-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Swin] Replace hard-coded batch size to enable dynamic ONNX export #19475
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
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lewtun
Thank you for the fix ❤️ !
Is the issue caused by the changes in #19255? More precisely, from (newly added code)
https://github.com/dwyatte/transformers/blob/949683675d83cc38620106626822279cd45b076b/src/transformers/onnx/convert.py#L368
The error shows Outputs values doesn't match between reference model and ONNX exported model - it must be non-trivi
al to figure out this is coming from the shape things! How are you able to find out 💯 ? Is there some tool we can use to check things (tensor values/shape) when running onnx inference?
|
(a bit off-topic, but still related question) Viewing the issue and the fix provided this PR, I was thinking we would have a lot of the same errors due to this
and
but the onnx tests still pass for |
Yes, this issue was surfaced by #19255, which implemented a stronger validation test on exported ONNX models. Basically, it generates the ONNX graph using dummy data with one batch size The reason it can be non-trivial to figure out when an export fails to have agreement between the PyTorch / ONNX models is that ONNX traces a graph based on dummy data, and this tracing can be incorrect if there are data-dependent flow statements (Swin in particular has a lot of these if/else statements). Currently , the best tool I know of is to visualise the graph with Netron and manually inspect for discrepancies.
I think in those cases we don't hit a problem because |
sgugger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for working on this!
What does this PR do?
This PR tweaks the modeling code of
swinto enable dynamic batch sizes with the ONNX export. With this fix, the ONNX slow tests for this model now pass, including the slow tests for the original PyTorch model:Since this change also impacts other models, I've also checked the modeling slow tests pass for:
maskformerdonut_swinswin_v2Related to #17476