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 estimator for Hugging Face models #2245

Merged

Conversation

GiulioZizzo
Copy link
Collaborator

@GiulioZizzo GiulioZizzo commented Aug 15, 2023

Description

In this PR we introduce an estimator to support HF models for classification. This can enable initial support for HF in ART which we can expand on and develop in future.

Fixes #2225

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.

  • Inclusion of a HF workflow to run the test suite with a HF classifier. Updates to core tests to explicitly check expected HF performance.

Test Configuration:

  • OS: Mac/RHEL
  • Python version: 3.8/3.11
  • ART version or commit number: 1.15.1
  • TensorFlow / Keras / PyTorch / MXNet version: TF 2.12, Pytorch 2.0.1, keras 2.12

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>
@GiulioZizzo GiulioZizzo marked this pull request as draft August 15, 2023 10:36
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2023

Codecov Report

Merging #2245 (6a6f094) into dev_1.16.0 (cbbd91c) will increase coverage by 0.95%.
The diff coverage is 89.23%.

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

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.16.0    #2245      +/-   ##
==============================================
+ Coverage       84.68%   85.64%   +0.95%     
==============================================
  Files             323      324       +1     
  Lines           29176    29304     +128     
  Branches         5374     5400      +26     
==============================================
+ Hits            24709    25098     +389     
+ Misses           3115     2828     -287     
- Partials         1352     1378      +26     
Files Changed Coverage Δ
...cks/poisoning/perturbations/image_perturbations.py 87.64% <53.84%> (-5.95%) ⬇️
art/estimators/classification/hugging_face.py 92.98% <92.98%> (ø)
...rigger_backdoor/hidden_trigger_backdoor_pytorch.py 75.42% <100.00%> (+2.14%) ⬆️
art/estimators/classification/__init__.py 100.00% <100.00%> (ø)

... and 8 files with indirect coverage changes

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@beat-buesser beat-buesser changed the title Huggingface Integration Implement estimator for Hugging Face models Aug 15, 2023
@beat-buesser beat-buesser self-requested a review August 15, 2023 11:14
@beat-buesser beat-buesser self-assigned this Aug 15, 2023
@beat-buesser beat-buesser added the enhancement New feature or request label Aug 15, 2023
@beat-buesser beat-buesser added this to the ART 1.16.0 milestone Aug 15, 2023
@beat-buesser beat-buesser linked an issue Aug 15, 2023 that may be closed by this pull request
GiulioZizzo and others added 12 commits August 16, 2023 08:20
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>
…ve to different PR.

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>
… with HF.

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 marked this pull request as ready for review September 1, 2023 13:18
@beat-buesser beat-buesser added this to Pull request review in ART 1.16.0 Sep 12, 2023
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 I have added a few suggestions. Please let me know what you think!

tests/defences/trainer/test_adversarial_trainer_FBF.py Outdated Show resolved Hide resolved
tests/attacks/poison/test_hidden_trigger_backdoor.py Outdated Show resolved Hide resolved
tests/attacks/poison/test_hidden_trigger_backdoor.py Outdated Show resolved Hide resolved
tests/attacks/poison/test_hidden_trigger_backdoor.py Outdated Show resolved Hide resolved
tests/attacks/poison/test_clean_label_backdoor_attack.py Outdated Show resolved Hide resolved
tests/utils.py Show resolved Hide resolved
tests/utils.py Show resolved Hide resolved
if len(shape) == 3 or len(shape) == 4:
# Transpose the image putting channels last
if channels_first:
x = np.transpose(x, (0, 2, 3, 1))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the transpose with 4 indices work if len(shape)==3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point: that should only apply to 4D inputs and an additional one is needed for 2D to go from HC to CH.

GiulioZizzo and others added 2 commits September 13, 2023 11:09
Co-authored-by: Beat Buesser <49047826+beat-buesser@users.noreply.github.com>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
GiulioZizzo and others added 6 commits September 13, 2023 15:13
…fier

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 44fc37a into Trusted-AI:dev_1.16.0 Sep 19, 2023
38 checks passed
ART 1.16.0 automation moved this from Pull request review to Pull request done Sep 19, 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
No open projects
ART 1.16.0
Pull request done
Development

Successfully merging this pull request may close these issues.

Inclusion of Huggingface Support
3 participants