rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Restarting progressbar tasks does not restart their running clocks

Open julianmueller opened this issue 1 year ago • 2 comments

I'm using the progressbar to show the progress of my AI model training. Therefore I have three bars, "epochs", "training", "validation". First the "training" bar is filling up (like a few thousand steps). Then "training" stops and "validation" is filling up. After that is finished, I restart both and advance the "epoch" bar once and want to restart the "training" bar. But thats when the error occurs: The running clock of the previously finished and resetted "training" bar does not start again. The advancement etc works, but the clock timer keeps showing 0:00:00.

This is how it looks in the terminal. You can see, the yellow clock of "training" remains, while the loop clearly started and was also advanced many times. Same happens in the "validation" task.

grafik

Here is my code snippet:

from rich.progress import BarColumn, Progress, TextColumn, TimeElapsedColumn, TimeRemainingColumn

def init_progressbar() -> Progress:
    return Progress(
        TextColumn("[progress.description]{task.description}"),
        TextColumn(" "),
        TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
        TextColumn(" "),
        BarColumn(),
        TextColumn(" "),
        TextColumn("[progress.download]{task.completed:>5.0f}/{task.total:>5.0f}"),
        TextColumn(" "),
        TimeElapsedColumn(),
        TextColumn(" "),
        TimeRemainingColumn(),
    )

progress = init_progressbar()
progress.start()
epoch_task = progress.add_task("[red]Epoch", total=num_epochs)
train_task = progress.add_task("[blue]Training", total=num_train_data, start=False)
valid_task = progress.add_task("[green]Validation", total=num_valid_data, start=False)

# training in epochs
for epoch in range(0, num_epochs):
    # Training ================

    # start the training loop progress bar
    progress.start_task(train_task)
    # progress.reset(train_task, start=True, completed=0)

    for batch, ... in train_dataloader:
        ...
        
        # update the progressbar for the training loop
        progress.advance(train_task, advance=train_dataloader.batch_size)

    # stop the training loop progress bar
    # progress.update(train_task, completed=num_train_data)
    progress.stop_task(train_task)

    # Validation ================

    # start the validation loop progress bar
    progress.start_task(valid_task)
    # progress.reset(valid_task, start=True, completed=0)

    for batch, ... in valid_dataloader:
        ...
        
        # update the progressbar for the validation loop
        progress.advance(valid_task, advance=valid_dataloader.batch_size)

    # stop the validation loop progress bar
    # progress.update(valid_task, completed=num_valid_data)
    progress.stop_task(valid_task)

    ...
    
    # update the progressbar for the epoch loop
    progress.advance(epoch_task, advance=1)
    progress.reset(train_task, start=False)
    progress.reset(valid_task, start=False)

The commented code-lines were tests I did, but they did not help to resolve the issue.

Output of rich.diagnose:

╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=128 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 12                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=128, height=12),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=128,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=12,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=128, height=12)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 128                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': None,                  │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'vscode',      │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"

julianmueller avatar Feb 05 '24 13:02 julianmueller

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Feb 05 '24 13:02 github-actions[bot]

It might boil down to this line, as I do reset(task, start=False) and with start=False the start_time is None. Is that the intended behavior? If so, would it be possible to also set a flag as an argument as restart_clocl: bool = False, which in my case could be overridden to True?

julianmueller avatar Feb 05 '24 23:02 julianmueller