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

Implement Interval Bound Propagation Training #2044

Merged
merged 26 commits into from
Mar 11, 2023

Conversation

GiulioZizzo
Copy link
Collaborator

@GiulioZizzo GiulioZizzo commented Feb 27, 2023

Description

In this PR we include adversarial training with interval bound propagation. With careful training this can achieve excellent certified robustness.

Fixes #2037

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

Tests can be found in test_interval.py. We check that the certification gives the correct results, runs without errors, propagates gradients correctly and when running without bounds gives the same results as regular neural networks.

Test Configuration:

  • OS: MacOS
  • Python version: 3.8
  • 1.13.1
  • 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

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>
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>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
@GiulioZizzo GiulioZizzo changed the title Ibp training IBP Training Feb 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2023

Codecov Report

Merging #2044 (9013b8c) into dev_1.14.0 (0727e2b) will increase coverage by 8.63%.
The diff coverage is 80.38%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.14.0    #2044      +/-   ##
==============================================
+ Coverage       76.94%   85.58%   +8.63%     
==============================================
  Files             291      292       +1     
  Lines           25612    25798     +186     
  Branches         4631     4665      +34     
==============================================
+ Hits            19708    22079    +2371     
+ Misses           4871     2529    -2342     
- Partials         1033     1190     +157     
Impacted Files Coverage Δ
art/utils.py 73.41% <ø> (+0.75%) ⬆️
.../defences/trainer/ibp_certified_trainer_pytorch.py 78.16% <78.16%> (ø)
art/estimators/certification/interval/interval.py 84.66% <78.94%> (+2.77%) ⬆️
art/estimators/certification/interval/pytorch.py 79.86% <92.00%> (+13.19%) ⬆️
art/defences/trainer/__init__.py 100.00% <100.00%> (ø)
art/defences/trainer/trainer.py 100.00% <100.00%> (ø)

... and 28 files with indirect coverage changes

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 changed the title IBP Training Implement Interval Bound Propagation Training Feb 27, 2023
@beat-buesser beat-buesser self-requested a review February 27, 2023 20:02
@beat-buesser beat-buesser self-assigned this Feb 27, 2023
@beat-buesser beat-buesser added the enhancement New feature or request label Feb 27, 2023
@beat-buesser beat-buesser added this to the ART 1.14.0 milestone Feb 27, 2023
@beat-buesser beat-buesser linked an issue Feb 27, 2023 that may be closed by this pull request
GiulioZizzo and others added 2 commits March 1, 2023 09:22
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
ABLATOR_TYPE = Union[BlockAblator, ColumnAblator] # pylint: disable=C0103

CERTIFIER_TYPE = Union[PytorchDeepZ] # pylint: disable=C0103
IBP_CERTIFIER_TYPE = Union[PyTorchIBPClassifier] # pylint: disable=C0103

Check notice

Code scanning / CodeQL

Unused global variable

The global variable 'IBP_CERTIFIER_TYPE' is not used.
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 in Interval Bound Propagation training! I have left a few comments, what do you think?

@@ -4,6 +4,7 @@
from art.defences.trainer.trainer import Trainer
from art.defences.trainer.adversarial_trainer import AdversarialTrainer
from art.defences.trainer.certified_adversarial_trainer_pytorch import AdversarialTrainerCertifiedPytorch
from art.defences.trainer.ibp_certified_trainer_pytorch import AdversarialTrainerCertifiedIBPPytorch
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
from art.defences.trainer.ibp_certified_trainer_pytorch import AdversarialTrainerCertifiedIBPPytorch
from art.defences.trainer.ibp_certified_trainer_pytorch import AdversarialTrainerCertifiedIBPPyTorch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, name changed!

Comment on lines +210 to +215
This classifier has 3 modes which can be set via: classifier.model.set_forward_mode('mode')

'mode' can be one of:
+ 'abstract': When we wish to certifiy datapoints and have abstract predictions
+ 'concrete': When normal predictions need to be made
+ 'attack': When we are interfacing with an ART attack (for example PGD).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this docstring build correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

checked, all ok!

art/estimators/certification/interval/pytorch.py Outdated Show resolved Hide resolved
art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
@@ -0,0 +1,462 @@
# MIT License
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update docs and check if new docstrings build correctly.

art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
art/defences/trainer/ibp_certified_trainer_pytorch.py Outdated Show resolved Hide resolved
GiulioZizzo and others added 4 commits March 7, 2023 14:32
…with much less protected member access

Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Co-authored-by: Beat Buesser <49047826+beat-buesser@users.noreply.github.com>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Co-authored-by: Beat Buesser <49047826+beat-buesser@users.noreply.github.com>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Co-authored-by: Beat Buesser <49047826+beat-buesser@users.noreply.github.com>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
GiulioZizzo and others added 6 commits March 8, 2023 10:17
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>
@beat-buesser beat-buesser merged commit 9b2891b into Trusted-AI:dev_1.14.0 Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of certified training via IBP
3 participants