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

Added rich-based progress bar #2132

Merged
merged 11 commits into from
Sep 18, 2023

Conversation

nikita-savelyevv
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv commented Sep 12, 2023

Changes

Added nncf.common.logging.track_progress.track() method to replace tqdm for quantization algorithms bars.
This method is an almost exact copy of rich.progress.track() method, but with an addition of an iteration counter. This is kind of a hack, but rich does not provide a way to add custom Column objects to the track() method.

By default rich.progress.track() renders progress bar as
image

With an addition of customizations this becomes
ac437dfc-de24-46fc-9538-3bdfee2e3ac9

With this change the quantization pipeline looks like
image

For iterables without length the progress bar displays as
image

How it looks in a notebook:
image

Reason for changes

  • User experience improvement
  • Avoiding multi-line logs in CI produced by tqdm, for example:
    Statistics collection: 0%| | 0/300 [00:00<?, ?it/s]
    Statistics collection: 0%| | 1/300 [00:00<01:13, 4.09it/s]
    Statistics collection: 1%| | 2/300 [00:00<00:50, 5.87it/s]
    Statistics collection: 1%|▏ | 4/300 [00:00<00:33, 8.79it/s]
    Statistics collection: 2%|▏ | 6/300 [00:00<00:26, 11.30it/s]
    Statistics collection: 3%|▎ | 8/300 [00:00<00:24, 11.88it/s]

@github-actions github-actions bot added NNCF Common Pull request that updates NNCF Common NNCF PTQ Pull requests that updates NNCF PTQ dependencies Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM labels Sep 12, 2023
@nikita-savelyevv nikita-savelyevv marked this pull request as ready for review September 13, 2023 08:10
@nikita-savelyevv nikita-savelyevv requested a review from a team as a code owner September 13, 2023 08:10
@nikita-savelyevv
Copy link
Collaborator Author

run pylint pre-commit tests
run pytorch pre-commit tests
run tensorflow pre-commit tests
run openvino pre-commit tests
run onnx pre-commit tests

@nikita-savelyevv
Copy link
Collaborator Author

Previously @vshampor expressed some concerns on rich compatibility with our own loggers. I've conducted some checks by running pipelines where our loggers (common logger, torch example logger, tf example logger) operate in parallel with the new progress bar from this PR and haven't noticed any conflicts. The existing loggers perform the same.

nncf/common/logging/track_progress.py Outdated Show resolved Hide resolved
nncf/common/logging/track_progress.py Outdated Show resolved Hide resolved
setup.py Show resolved Hide resolved
return Text(text, style="progress.remaining")


def track(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And need add option to use progressbar in async mode to manually update iterations

with tqdm.tqdm(total=dataset_size, desc="Validation", disable=disable_tqdm) as pbar:
def process_result(request, userdata):
output_data = request.get_output_tensor().data
predicted_label = np.argmax(output_data, axis=1)
predictions[userdata] = [predicted_label]
pbar.update()
infer_queue.set_callback(process_result)
for i, (images, target) in enumerate(val_loader):
# W/A for memory leaks when using torch DataLoader and OpenVINO
image_copies = copy.deepcopy(images.numpy())
infer_queue.start_async(image_copies, userdata=i)
references[i] = target
infer_queue.wait_all()

Copy link
Collaborator Author

@nikita-savelyevv nikita-savelyevv Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this functionality by turning track into a class with __iter__, __enter__ and __exit__ implemented similarly to tqdm. It can be used in the following way:

from nncf.common.logging.track_progress import track
n = 10000
with track(total=n, description="Description") as pbar:
    for _ in range(n):
        np.random.random((100000,))
        pbar.progress.update(pbar.task, advance=1)

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Merging #2132 (cf24959) into develop (0a08966) will increase coverage by 0.30%.
Report is 4 commits behind head on develop.
The diff coverage is 88.52%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2132      +/-   ##
===========================================
+ Coverage    35.92%   36.23%   +0.30%     
===========================================
  Files          476      477       +1     
  Lines        42483    42544      +61     
===========================================
+ Hits         15264    15414     +150     
+ Misses       27219    27130      -89     
Files Changed Coverage Δ
setup.py 0.00% <ø> (ø)
.../quantization/algorithms/smooth_quant/algorithm.py 27.84% <50.00%> (ø)
...tization/algorithms/channel_alignment/algorithm.py 25.41% <66.66%> (ø)
nncf/common/logging/track_progress.py 90.00% <90.00%> (ø)
nncf/common/tensor_statistics/aggregator.py 98.14% <100.00%> (ø)
...antization/algorithms/bias_correction/algorithm.py 93.88% <100.00%> (ø)
...ation/algorithms/fast_bias_correction/algorithm.py 90.83% <100.00%> (ø)

... and 6 files with indirect coverage changes

@nikita-savelyevv
Copy link
Collaborator Author

run pylint pre-commit tests
run pytorch pre-commit tests
run tensorflow pre-commit tests
run openvino pre-commit tests
run onnx pre-commit tests

@KodiaqQ KodiaqQ merged commit df3b70f into openvinotoolkit:develop Sep 18, 2023
6 checks passed
@nikita-savelyevv nikita-savelyevv deleted the rich-progress-bar branch September 25, 2023 14:14
alexsu52 pushed a commit that referenced this pull request Oct 3, 2023
### Changes

- Progress bar now extends to screen width
- Iteration count, time spent and time remaining text components are now
Intel blue (RGB [0,104,181])

How it looks in terminal (Windows Terminal):

![image](https://github.com/openvinotoolkit/nncf/assets/23343961/cd10196a-ecdc-4b3a-a59e-b89341b6848c)


How it looks in Jupyter:

![image](https://github.com/openvinotoolkit/nncf/assets/23343961/131e2e10-887e-45ac-8640-dd0752f37593)


Please see how it looked before at #2132

Note: I've tried changing color for progress percent too, but couldn't,
most probably due to a bug in rich
Textualize/rich#3133

### Reason for changes

- Improving user experience

Special thanks to @AlexanderDokuchaev and @kshpv for suggesting these
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM NNCF Common Pull request that updates NNCF Common NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants