fastai / fastprogress

Simple and flexible progress bar for Jupyter Notebook and console

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

progress bars not displaying in vscode Jupyter notepad

codermrrob opened this issue · comments

A few days ago fastprogress stopped working in Jupyter notepads in vscode.

It seems to run without error but does not display anything.
I have the same issue in existing environments (venv) and in newly created environments.
I have reverted to Jan 2023 version of vscode where I know it was working before, but that showed no change.

Running the following code works for console output, but in Jupyter notebook nothing.

Where should I look to try and resolve this issue? Any guidance will be valuable because I have pretty much exhausted my knowledge of fastprogress and what I can do.

from time import sleep
from fastprogress.fastprogress import master_bar, progress_bar

mb = master_bar(range(10))
progress_bar(range(100), parent=mb)

for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)

I have the exact same problem. Discovered something was wrong since fastai wasn't displaying any bars. Tqdm for instance, still works in notebooks.

I have also tried to revert to Jan 2023 vscode and also reverted ipywidgets to 7.7.* instead of 8 without any further luck.

@elisgrahn I also reverted ipywidgets, but I can verify both the ipywidgets 7.7.* and 8 work fine; I can import and run and successfully display widgets in notebooks that I have tried. fastprogress is working in console mode, of course, but not in notebooks in vscode.

makes working through the fastai courses problematic with local setup, which is disappointing because I want to utilize my GPU (which I have successfully set up, which is the trickier part). But now I've hit this wall.

Also having this issue. In the meantime, if anyone like myself is still early in the learning process and just needs the epoch data, there is a quick workaround. Add cbs=CSVLogger() to your learner, and then create a quick function to display it. Example:

def train_res():
    train_data = pd.read_csv('history.csv')
    return train_data.head(n=50)

learn = tabular_learner(dls, layers=[500, 250], n_out=1, y_range=(-11,11), loss_func=F.mse_loss, cbs=CSVLogger())

learn.fit_one_cycle(1, 1e-2)
train_res()

Nice workaround! Just want to share that the solution I've currently settled on is to add a TensorBoardCallback() in order to view the models in Tensorboard. Might be a bit overkill, but I felt it was useful to learn how to use it.

cbs=[TensorBoardCallback(n_preds=8)]

Same issue here - no progress bars in vscode :(

Ok, I tried a few different versions of the Jupyter extension and:
v2022.11.1003412109 - working, ShowGraphCallback works too
v2023.1.2000312134 - working, ShowGraphCallback doesn’t (plot disappears)
v2023.1.2010391206 - working, ShowGraphCallback doesn’t (plot disappears)
v2023.2.1000592019 - not working, ShowGraphCallback works again
v2023.2.1200692131 - not working, ShowGraphCallback works again

@bosmart thanks for the effort there, I hadn't been aware it was so easy to revert extension versions in vscode now.

@codermrrob I've opened the following: microsoft/vscode-jupyter#13163

Same issue here. Just started with the course and was wondering why I don't get any output. I played around and found out that with a short sleep between the display.update() calls in the show method of the progress bar it actually outputs something. Might be a race condition somewhere.

Here is my code snippet (I only inserted some time.sleep(), the rest is basically unchanged):

# workaround for displaying progress bar in notebook
import time
from fastai.vision.all import *
from fastprogress.fastprogress import NBMasterBar, NBProgressBar

class NBMasterBarPatched(NBMasterBar):
    def on_iter_begin(self):
        super().on_iter_begin()
        time.sleep(0.01)

    def show(self):
        time.sleep(0.01)
        super().show()

class NBProgressBarPatched(NBProgressBar):
    def on_iter_begin(self):
        super().on_iter_begin()
        time.sleep(0.01)

    def show(self):
        time.sleep(0.01)
        super().show()

class ProgressCallbackPatched(ProgressCallback):
    def before_fit(self):
        if self.create_mbar: self.mbar = NBMasterBarPatched(list(range(self.n_epoch)))
        assert hasattr(self.learn, 'recorder')
        if self.learn.logger != noop:
            self.old_logger,self.learn.logger = self.logger,self._write_stats
            self._write_stats(self.recorder.metric_names)
        else: self.old_logger = noop

    def _launch_pbar(self):
        self.pbar = NBProgressBarPatched(self.dl, parent=getattr(self, 'mbar', None), leave=False)
        self.pbar.update(0)

defaults.callbacks = [TrainEvalCallback, Recorder, ProgressCallbackPatched]

# now do your learning
learn...

Another workaround from an older issue, forcing text output for the progress bar:

from fastprogress.fastprogress import master_bar, progress_bar
from fastprogress.fastprogress import force_console_behavior
master_bar, progress_bar = force_console_behavior()
commented

Same issue here. Reverted jupyter extension and it seems to be working. I'll add a comment to the vs-code jupyter issue as well.

EDIT:
Should have looked at the jupyter issue first. Looks like it was merged two days ago. Guessing we'll see it in the next release.