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 ResNet to models exportable with ONNX #16948

Closed

Conversation

chamidullinr
Copy link

What does this PR do?

I added OnnxConfig to make ResNet model available for ONNX conversion.

Issue #16308

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.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.


@property
def atol_for_validation(self) -> float:
return 1e-4
Copy link
Contributor

@chainyo chainyo Apr 27, 2022

Choose a reason for hiding this comment

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

Hey @chamidullinr nice PR, did you try the conversion config with the default --atol=1e-5 before putting it to 1e-4 ?

If you are okay you could push a ResNet ONNX converted model to the ONNXConfig for all organisation, it would be awesome! 🤗

Copy link
Author

Choose a reason for hiding this comment

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

I pushed a ResNet-50 ONNX converted model. And I set --atol=1e-3 because some tests were failing.

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 the first non-Transformer model to our ONNX exporter @chamidullinr !

Apart from @chainyo's comment, this all looks good to me, so can you please check that the slow tests pass by running:

RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py -s -k "resnet"

Gently pinging @sgugger for final approval 🤗

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.

Thanks for the PR. LGTM module existing comments :-)

@chamidullinr
Copy link
Author

Thanks for the suggestions. One test fails when running slow tests. The error is:

ValueError: Outputs values doesn't match between reference model and ONNX exported model: Got max absolute difference of: 0.000244140625

Should I set --atol=1e-3 or is there some way to fix this?

@lewtun
Copy link
Member

lewtun commented Apr 27, 2022

Should I set --atol=1e-3 or is there some way to fix this?

Ah yes, some models require a lower tolerance due to their architectures. Setting --atol=1e-3 as the default is fine!

Krishna Sirumalla and others added 19 commits April 28, 2022 08:18
* Avoid repeated per-lang filtering

* Language groups and logits preprocessing

* Style
* Add first draft

* Improve script and README

* Improve README

* Apply suggestions from code review

* Improve script, add link to resulting model

* Add corresponding test

* Adjust learning rate
Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
1. Fixes evaluation errors popping up when you train/eval on squad v2 (one was newly encountered and one that was previously reported Running SQuAD 1.0 sample command raises IndexError huggingface#15401 but not completely fixed).
2. Removes boolean arguments that don't use store_true. Please, don't use these: *ANY non-empty string is being converted to True in this case and this clearly is not the desired behavior (and it creates a LOT of confusion).
3. All no-trainer test scripts are now saving metric values in the same way (with the right prefix eval_), which is consistent with the trainer-based versions.
4. Adds forgotten model.eval() in the no-trainer versions. This improved some results, but not everything (see the discussion in the end). Please, see the F1 scores and the discussion below.
…#16946)

* Add fix

* Apply suggestion from code review

Co-authored-by: Niels Rogge <nielsrogge@Nielss-MacBook-Pro.local>
* Fix `distributed_concat` with scalar tensor

* Update trainer_pt_utils.py
BertModelForSequenceClassification -> BertForSequenceClassification
…ace#16947)

* Fix multiple deletions of the same files in save_pretrained

* Add is_main_process argument
* Fix doc notebooks links

* Remove missing section
Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
* Add -e flag

* add check

* create new keys

* run python setup.py build install

* add comments

* change to develop

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
The emoji version must be either 0.5.4 or 0.6.0. Newer emoji versions have been updated to newer versions of the Emoji Charts, thus not consistent with the one used for pre-processing the pre-training Tweet corpus (i.e. not consistent with the vocab).
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@chamidullinr chamidullinr deleted the add-resnet-onnxconfig branch June 3, 2022 10:36
@chainyo
Copy link
Contributor

chainyo commented Jun 3, 2022

Can't we rebase this branch and add the code for ResNet ?

@regisss
Copy link
Contributor

regisss commented Jun 7, 2022

I'm taking care of this in #17585, I didn't see this PR before opening mine. @chainyo

It should be done by the end of the week!

@chainyo
Copy link
Contributor

chainyo commented Jun 7, 2022

It should be done by the end of the week!

Pretty cool!

@regisss regisss mentioned this pull request Jun 9, 2022
5 tasks
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.