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

Add onnx export of models with a multiple choice classification head #16758

Merged
merged 9 commits into from
Apr 19, 2022

Conversation

echarlaix
Copy link
Collaborator

This PR adds the export support of models with a multiple-choice classification head, resolving #16695

This includes the following additions:

  • The "multiple-choice" feature was added to the corresponding model topologies
  • The dummy inputs are generated to match the expected inputs shape which includes an extra dimension corresponding to the number of candidates answers
  • The inputs method of the models corresponding OnnxConfig were modified to support the additional dynamic axis corresponding to the number of candidates

@echarlaix echarlaix changed the title Add export of models with a multiple-choice classification head Add onnx export of models with a multiple-choice classification head Apr 13, 2022
@echarlaix echarlaix changed the title Add onnx export of models with a multiple-choice classification head Add onnx export of models with a multiple choice classification head Apr 13, 2022
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 13, 2022

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

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Looks good on my side, thanks for working on this! Just make sure to run make fix-copies and make style on your branch to fix the quality issues.

@echarlaix
Copy link
Collaborator Author

Thanks for the review as well as the reminder @sgugger !

Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

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

Thanks for adding this @echarlaix - it looks great to me!

I think there's a few more models that support multiple choice classification and have an ONNX export:

  • BigBird
  • Data2VecText
  • Electra
  • FlauBERT

Would you like to include them in this PR too?

We should also do a final run of the slow tests before merging to make sure everything passes:

RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py

Copy link
Member

@michaelbenayoun michaelbenayoun left a comment

Choose a reason for hiding this comment

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

Perfect, thanks a lot for taking care of this @echarlaix !

num_choices, fixed_dimension=OnnxConfig.default_fixed_num_choices, num_token_to_add=0
)
dummy_input = dummy_input * num_choices
tokenized_input = preprocessor(dummy_input, text_pair=dummy_input)
Copy link
Member

Choose a reason for hiding this comment

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

I would just add a small comment to make clear what's happening here.
What do you think?

Suggested change
tokenized_input = preprocessor(dummy_input, text_pair=dummy_input)
# Shape is [batch_size x num_choices, seq_length]
tokenized_input = preprocessor(dummy_input, text_pair=dummy_input)

@echarlaix
Copy link
Collaborator Author

Thanks for the reviews @lewtun and @michaelbenayoun.
I have added some comments to make things clearer as well as the BigBird, Data2VecText, Electra and FlauBERT models support. Also when running the command line RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py, all the tests are passing.

@lewtun
Copy link
Member

lewtun commented Apr 19, 2022

Thanks for iterating on this @echarlaix - it looks great!

@lewtun lewtun merged commit 77de8d6 into huggingface:main Apr 19, 2022
elusenji pushed a commit to elusenji/transformers that referenced this pull request Jun 12, 2022
…uggingface#16758)

* Add export of models with a multiple-choice classification head
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