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

[Wav2Vec2] Fix torch srcipt #24062

Merged
merged 2 commits into from
Jun 7, 2023
Merged

[Wav2Vec2] Fix torch srcipt #24062

merged 2 commits into from
Jun 7, 2023

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Jun 6, 2023

What does this PR do?

Fixes Wav2Vec2 torch script slow tests

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten
Copy link
Contributor Author

It seems like torch.trace(...) doesn't like property function as it'll always call them. Since we've added the property as a private property in #23813, let's just go the simplest way and change it to a function.

This PR should fix:

tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2ModelTest::test_torchscript_output_attentions
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.
tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2ModelTest::test_torchscript_output_hidden_state
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.
tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2ModelTest::test_torchscript_simple
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.
tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2RobustModelTest::test_torchscript_output_attentions
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.
tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2RobustModelTest::test_torchscript_output_hidden_state
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.
tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2RobustModelTest::test_torchscript_simple
(line 1180)  ValueError: <class 'transformers.models.wav2vec2.modeling_wav2vec2.Wav2Vec2ForCTC'> has no adapter layers. Make sure to define config.adapter_attn_dim.

of the slow tests, such as

RUN_SLOW=1 pytest tests/models/wav2vec2/test_modeling_wav2vec2.py::Wav2Vec2ModelTest::test_torchscript_simple

@sgugger @ydshieh

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 6, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

the code in torch.jit.trace will call hasattr(mod, name). This function hasattr will actually call the method if it is a property. Let's why we have this failure. In general, not really a jit issue but the python thing. See this.

So good fore me, but would like to know how the core maintainers think.

@ydshieh
Copy link
Collaborator

ydshieh commented Jun 7, 2023

One possible different way is to raise AttributeError instead of ValueError if we want to keep the propery.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Change looks good to me - thanks for fixing!

@sgugger sgugger merged commit 52972e7 into main Jun 7, 2023
@sgugger sgugger deleted the fix_torchscript_wav2vec2 branch June 7, 2023 11:27
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
* [Wav2Vec2] Fix torch srcipt

* fix more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants