Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress bars not displaying in vscode Jupyter notepad #104

Open
codermrrob opened this issue Mar 4, 2023 · 11 comments
Open

progress bars not displaying in vscode Jupyter notepad #104

codermrrob opened this issue Mar 4, 2023 · 11 comments

Comments

@codermrrob
Copy link

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)
@elisgrahn
Copy link

elisgrahn commented Mar 8, 2023

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.

@codermrrob
Copy link
Author

@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.

@peterbull
Copy link

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()

@elisgrahn
Copy link

elisgrahn commented Mar 10, 2023

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)]

@bosmart
Copy link

bosmart commented Mar 23, 2023

Same issue here - no progress bars in vscode :(

@bosmart
Copy link

bosmart commented Mar 24, 2023

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

@codermrrob
Copy link
Author

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

@bosmart
Copy link

bosmart commented Mar 24, 2023

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

@aisbergg
Copy link

aisbergg commented Apr 7, 2023

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...

@adam-matic
Copy link

adam-matic commented Apr 10, 2023

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()

@pounde
Copy link

pounde commented May 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants