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

Simple Progress Bar Inclusion #2334

Merged
merged 21 commits into from
Dec 22, 2023

Conversation

GiulioZizzo
Copy link
Collaborator

Description

Currently, the core training routines for many ART estimators do not had progress bars to inform the user of how long models require for training. Although this was not a problem when ART was first developed as models were small and trained quickly, with ever larger models being evaluated for robustness, it Is very useful to have an indication of how long training will take.
For this PR we introduce a simple tqdm progress bar in the pytorch/tensorflow/huggingface estimators for the fit and fit_generate functions.

This feature branches off the current open PR #2300

Fixes (partially) #2288

Type of change

Please check all relevant options.

  • Improvement (non-breaking)
  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing

Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.

Updated the current CI test test_fit_kwargs to include a check for using the progress bar kwarg

Test Configuration:

  • OS: Mac OS
  • Python version: 3.8
  • ART version or commit number: ART 1.16
  • TensorFlow / Keras / PyTorch / MXNet version: TensorFlow 2.10, pytorch: 1.13

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My changes have been tested using both CPU and GPU devices

Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (a281f62) 76.18% compared to head (b817b9c) 85.47%.
Report is 6 commits behind head on dev_1.17.0.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.17.0    #2334      +/-   ##
==============================================
+ Coverage       76.18%   85.47%   +9.29%     
==============================================
  Files             327      327              
  Lines           30850    30206     -644     
  Branches         5716     5591     -125     
==============================================
+ Hits            23503    25819    +2316     
+ Misses           5914     2948    -2966     
- Partials         1433     1439       +6     
Files Coverage Δ
art/attacks/extraction/knockoff_nets.py 89.93% <ø> (ø)
art/defences/trainer/adversarial_trainer.py 92.24% <100.00%> (ø)
art/defences/trainer/dp_instahide_trainer.py 96.07% <100.00%> (ø)
...rs/certification/derandomized_smoothing/pytorch.py 58.36% <ø> (-0.38%) ⬇️
...certification/derandomized_smoothing/tensorflow.py 62.38% <ø> (-0.92%) ⬇️
...ertification/randomized_smoothing/macer/pytorch.py 98.38% <100.00%> (ø)
...ification/randomized_smoothing/macer/tensorflow.py 91.89% <100.00%> (+56.75%) ⬆️
...tors/certification/randomized_smoothing/pytorch.py 85.54% <100.00%> (ø)
...ation/randomized_smoothing/randomized_smoothing.py 97.33% <100.00%> (-0.04%) ⬇️
...ication/randomized_smoothing/smooth_adv/pytorch.py 98.36% <100.00%> (ø)
... and 8 more

... and 59 files with indirect coverage changes

@beat-buesser beat-buesser self-requested a review November 30, 2023 15:36
@beat-buesser beat-buesser self-assigned this Nov 30, 2023
@beat-buesser beat-buesser added the improvement Improve implementation label Nov 30, 2023
@beat-buesser beat-buesser added this to the ART 1.17.0 milestone Nov 30, 2023
@beat-buesser beat-buesser linked an issue Nov 30, 2023 that may be closed by this pull request
Copy link
Collaborator

@beat-buesser beat-buesser left a comment

Choose a reason for hiding this comment

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

Hi @GiulioZizzo Thank you very much for your pull request! I think it would be great to extend the PR to also cover Keras and TensorFlow for the new progress bar.

@@ -389,12 +390,14 @@ def fit( # pylint: disable=W0221
the batch size. If ``False`` and the size of dataset is not divisible by the batch size, then
the last batch will be smaller. (default: ``False``)
:param scheduler: Learning rate scheduler to run at the start of every epoch.
:param kwargs: Dictionary of framework-specific arguments. This parameter is not currently supported for PyTorch
and providing it takes no effect.
:param kwargs: Dictionary of framework-specific arguments. Currently supports "display_progress_bar" to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change this new argument display_progress_bar to verbose to follow the ART pattern and add it as full argument outside kwargs.

Comment on lines 206 to 209
if framework in ["kerastf", "keras"]:
kwargs = {"callbacks": [LearningRateScheduler(get_lr)]}
else:
kwargs = {"callbacks": [LearningRateScheduler(get_lr)], "display_progress_bar": True}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add progress bars also for Keras and TensorFlow v1.

Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
…andomized tools

Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
…for kwargs checks

Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Comment on lines 1121 to 1122
display_pb = self.process_verbose(verbose)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
display_pb = self.process_verbose(verbose)

Comment on lines 1162 to 1163
for epoch in tqdm(range(nb_epochs), disable=not display_pb, desc="Epochs"):
for i_batch, o_batch in tqdm(generator.iterator, disable=not display_pb, desc="Batches"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for epoch in tqdm(range(nb_epochs), disable=not display_pb, desc="Epochs"):
for i_batch, o_batch in tqdm(generator.iterator, disable=not display_pb, desc="Batches"):
for epoch in tqdm(range(nb_epochs), disable=not verbose, desc="Epochs"):
for i_batch, o_batch in generator.iterator:

kwargs = {"epochs": 1}
with pytest.raises(TypeError) as exception:
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)
kwargs = {"callbacks": [LearningRateScheduler(get_lr)], "verbose": True}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
kwargs = {"callbacks": [LearningRateScheduler(get_lr)], "verbose": True}
kwargs = {"callbacks": [LearningRateScheduler(get_lr)]}

with pytest.raises(TypeError) as exception:
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)
kwargs = {"callbacks": [LearningRateScheduler(get_lr)], "verbose": True}
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, verbose=True, **kwargs)

Comment on lines 213 to 226

# Test failure for invalid parameters: does not apply to many frameworks which allow arbitrary kwargs
if framework not in [
"tensorflow1",
"tensorflow2",
"tensorflow2v1",
"huggingface",
"pytorch",
]:
kwargs = {"epochs": 1}
with pytest.raises(TypeError) as exception:
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)

assert "multiple values for keyword argument" in str(exception)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Test failure for invalid parameters: does not apply to many frameworks which allow arbitrary kwargs
if framework not in [
"tensorflow1",
"tensorflow2",
"tensorflow2v1",
"huggingface",
"pytorch",
]:
kwargs = {"epochs": 1}
with pytest.raises(TypeError) as exception:
classifier.fit(x_train_mnist, y_train_mnist, batch_size=default_batch_size, nb_epochs=1, **kwargs)
assert "multiple values for keyword argument" in str(exception)

beat-buesser and others added 2 commits December 20, 2023 10:45
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
@beat-buesser beat-buesser merged commit b817b9c into Trusted-AI:dev_1.17.0 Dec 22, 2023
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improve implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of Progress Bars for ART Estimators
3 participants