Get progress bar in VS Code instead of text/stream based progress bar
Hi, one of the maintainers of the Python extension that provides Jupyter functionality in VS Code.
Here's the original issue:
https://github.com/microsoft/vscode-python/issues/14476#issuecomment-714895448
What is your question?
When running the code in class Jupyter notebook, we get the widget (I think tqdm) progress bar.
However, when running the exact same code in VS Code, we get the class text stream based progress bar.
I would like to get the progress bar (tqdm) being rendererd in the output when running cells in VS Code.
Does this package have some auto detection of the host (whether its Jupyter labs/notebook) & then renders the progress bar as widgets & when executed from another front end like VSCode it will render it using text streams.
Please note: we are not using Jupyter to run the code, we're starting the Python kernel & communicating with the kernel over ZQM directly. Hence Jupyter is not avaiable.
Finally, VS Code does support IPyWidgets functionality.
Thanks for your help.
Code
import torch
from torch import nn
from torch.nn import functional as F

from pl_bolts.datamodules.mnist_datamodule import MNISTDataModule
import pytorch_lightning as pl
class LitLeNet(pl.LightningModule):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.conv1 = nn.Conv2d(1, 6, 5, padding=2)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.classifier = nn.Linear(84, 10)

        self.accuracy = pl.metrics.Accuracy()
    
    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = F.max_pool2d(x, (2, 2))
        x = F.relu(self.conv2(x))
        x = F.max_pool2d(x, (2, 2))
        x = x.view(-1, 16 * 5 * 5)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.classifier(x)
        x = F.softmax(x, dim=0)

        return x
    
    def configure_optimizers(self):
        return torch.optim.Adam(self.parameters())
    
    def _shared_step(self, batch, batch_idx):
        x, y = batch
        y_hat = self(x)
        loss = F.cross_entropy(y_hat, y)
        self.log('acc', self.accuracy(y_hat, y), prog_bar=True)
        return loss

    def training_step(self, batch, batch_idx):
        return self._shared_step(batch, batch_idx)
    
    def validation_step(self, batch, batch_idx):
        return self._shared_step(batch, batch_idx)
    
    def test_step(self, batch, batch_idx):
        return self._shared_step(batch, batch_idx)
    
    def validation_epoch_end(self, outputs):
        self.log('acc', self.accuracy.compute(), prog_bar=True)
mnist = MNISTDataModule('./data', num_workers=2)
model = LitLeNet()

trainer = pl.Trainer(max_epochs=1)
trainer.fit(model, datamodule=mnist)
Here's the output in VS Code
Epoch 0:  92%|█████████▏| 1718/1874 [00:17<00:01, 98.09it/s, loss=2.047, v_num=19, acc=0.875]
Validating: 0it [00:00, ?it/s]

Here's the output in Jupyter Notebooks

   
What have you tried?
What's your environment?

OS: [e.g. iOS, Linux, Win] - OSX
Packaging [e.g. pip, conda] - Pip
Version [e.g. 0.5.2.1]

Python 3.8.2
pytorch_lightning 1.0.3
pytorch-lightning-bolts           0.2.5
torch                             1.6.0
torchvision                       0.7.0