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 Config for ImageGPT #19868

Merged
merged 7 commits into from
Oct 28, 2022
Merged

Conversation

RaghavPrabhakar66
Copy link
Contributor

@RaghavPrabhakar66 RaghavPrabhakar66 commented Oct 25, 2022

What does this PR do?

Fixes #16308

Add changes to make ImageGPT models available for Onnx conversion.

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.

@chainyo

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 25, 2022

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

@sgugger sgugger requested a review from lewtun October 25, 2022 13:33
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 ONNX support for this model @RaghavPrabhakar66 🤗 !

Could you please confirm that the slow tests pass by running:

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

@RaghavPrabhakar66
Copy link
Contributor Author

@lewtun With latest changes, all the 4 tests are now passing.

image

@chainyo
Copy link
Contributor

chainyo commented Oct 27, 2022

@lewtun With the latest changes, all the 4 tests are now passing.

Thanks for iterating so fast, @RaghavPrabhakar66. Good work!

If you have time, you can try to upload an ONNX ImageGPT model to the ONNX organization on the hub if you want.

@RaghavPrabhakar66
Copy link
Contributor Author

@chainyo Sure.

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 a lot for sharing the test runs @RaghavPrabhakar66 ! I spotted one last thing we need to fix, but then this should be good to go 🚀

from collections import OrderedDict
from typing import Any, Mapping, Optional

from transformers.feature_extraction_utils import FeatureExtractionMixin
Copy link
Member

Choose a reason for hiding this comment

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

We use relative imports in the transformers codebase, so would you mind changing these two lines please?

Also, since we're only using these imports for type checking we should put them under a TYPE_CHECKING clause like this:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from ... import FeatureExtractionMixin, TensorType

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. One small doubt, Should I put Any, Mapping etc under TYPE_CHECKING clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, after putting TensorType under TYPE_CHECKING clause, I am getting following error

RuntimeError: Failed to import transformers.models.imagegpt.configuration_imagegpt because of the following error (look up to see its traceback):
name 'TensorType' is not defined

Copy link
Member

Choose a reason for hiding this comment

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

It's OK to leave Any etc as proper imports - the TYPE_CHECKING clause is usually reserved for imports coming from the transformers library :)

To fix your issue, you need to put TensorType in quotes, i.e. "TensorType". You can find more information about "forward referencing" here: https://peps.python.org/pep-0484/#forward-references

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for replying and clearing the doubt.

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 iterating @RaghavPrabhakar66 !

This now LGTM, so 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.

Just one small nit in the doc and we should be good to go!
Thanks for working on this!

src/transformers/models/imagegpt/configuration_imagegpt.py Outdated Show resolved Hide resolved
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
@RaghavPrabhakar66
Copy link
Contributor Author

@sgugger fixed it.

@sgugger sgugger merged commit 0d4c45c into huggingface:main Oct 28, 2022
@sgugger
Copy link
Collaborator

sgugger commented Oct 28, 2022

Thanks!

amyeroberts pushed a commit to amyeroberts/transformers that referenced this pull request Nov 1, 2022
* add Onnx Config for ImageGPT

* add generate_dummy_inputs for onnx config

* add TYPE_CHECKING clause

* Update doc for generate_dummy_inputs

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
amyeroberts pushed a commit to amyeroberts/transformers that referenced this pull request Nov 3, 2022
* add Onnx Config for ImageGPT

* add generate_dummy_inputs for onnx config

* add TYPE_CHECKING clause

* Update doc for generate_dummy_inputs

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
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.

ONNXConfig: Add a configuration for all available models
5 participants