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

Imperceptible asr bug detach #1677

Merged

Conversation

davidslater
Copy link
Collaborator

Description

When running imperceptible ASR attack on pytorch_deep_speech on GPU, I sometimes run into this error:

File "/opt/conda/lib/python3.8/site-packages/art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py", line 567, in _attack_2nd_stage[best_loss_2nd_stage[local_batch_size_idx] = loss_2nd_stage[local_batch_size_idx].numpy()
		RuntimeError^[[0m:^[[1m Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead

I believe it only occurs sometimes due to specific branching conditions being hit.
See also twosixlabs/armory#1472

This update just ensures that when moving from Tensor to numpy array, .detach().cpu().numpy() is always called. This should always be safe (detach and cpu are no-ops if they are already true).

Fixes # (issue)

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.

  • Test A
  • Test B

Test Configuration:

  • OS
  • Python version
  • ART version or commit number
  • TensorFlow / Keras / PyTorch / MXNet version

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: David Slater <david.slater@twosixlabs.com>
@codecov-commenter
Copy link

codecov-commenter commented May 10, 2022

Codecov Report

Merging #1677 (b3b8cf9) into dev_1.10.2 (1fd1f92) will decrease coverage by 0.74%.
The diff coverage is 0.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.10.2    #1677      +/-   ##
==============================================
- Coverage       88.10%   87.35%   -0.75%     
==============================================
  Files             259      259              
  Lines           21349    21349              
  Branches         3789     3789              
==============================================
- Hits            18809    18649     -160     
- Misses           1597     1755     +158     
- Partials          943      945       +2     
Impacted Files Coverage Δ
...ion/imperceptible_asr/imperceptible_asr_pytorch.py 86.79% <0.00%> (ø)
...estimators/speech_recognition/tensorflow_lingvo.py 18.27% <0.00%> (-73.10%) ⬇️
art/estimators/certification/abstain.py 90.90% <0.00%> (-9.10%) ⬇️
art/estimators/poison_mitigation/strip/strip.py 94.44% <0.00%> (-5.56%) ⬇️
art/estimators/tensorflow.py 77.77% <0.00%> (-2.03%) ⬇️
art/attacks/evasion/brendel_bethge.py 85.99% <0.00%> (-1.63%) ⬇️
art/attacks/evasion/boundary.py 92.77% <0.00%> (-1.21%) ⬇️
art/utils.py 74.95% <0.00%> (-0.51%) ⬇️
art/defences/detector/poison/activation_defence.py 84.28% <0.00%> (-0.34%) ⬇️

@beat-buesser beat-buesser self-requested a review May 10, 2022 17:04
@beat-buesser beat-buesser self-assigned this May 10, 2022
@beat-buesser beat-buesser added bug Something isn't working improvement Improve implementation labels May 10, 2022
@beat-buesser beat-buesser added this to the ART 1.10.2 milestone May 10, 2022
@beat-buesser beat-buesser changed the base branch from main to dev_1.10.2 May 10, 2022 17:05
@beat-buesser beat-buesser added this to Pull request open in ART 1.10.2 May 10, 2022
@beat-buesser beat-buesser changed the base branch from dev_1.10.2 to dev_1.11.0 May 10, 2022 22:20
@beat-buesser beat-buesser changed the base branch from dev_1.11.0 to dev_1.10.2 May 10, 2022 22:20
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 @davidslater Thank you very much! Your solution looks good to me.

@beat-buesser beat-buesser merged commit cb95baf into Trusted-AI:dev_1.10.2 May 11, 2022
ART 1.10.2 automation moved this from Pull request open to Pull request done May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working improvement Improve implementation
Projects
No open projects
ART 1.10.2
  
Pull request done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants