-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Requires for torch.tensor before casting #31755
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thanks for fixing!
@@ -762,7 +762,7 @@ def torch_int(x): | |||
|
|||
import torch | |||
|
|||
return x.to(torch.int64) if torch.jit.is_tracing() else int(x) | |||
return x.to(torch.int64) if torch.jit.is_tracing() and isinstance(x, torch.Tensor) else int(x) |
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.
Here you can use the torch_int utility instead
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.
do you mean ensuring shift_size
is a torch.Tensor
when jit tracing in the modeling directly ?
self.shift_size = torch_int(0) |
@@ -774,7 +774,7 @@ def torch_float(x): | |||
|
|||
import torch | |||
|
|||
return x.to(torch.float32) if torch.jit.is_tracing() else int(x) | |||
return x.to(torch.float32) if torch.jit.is_tracing() and isinstance(x, torch.Tensor) else int(x) |
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.
And here torch_float
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.
I think since we're explicitly calling torch_float
where float was used to be it should be fine, no?
@amyeroberts do you think this fix could be included in a patch release ? |
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.
thanks!
@echarlaix I'm happy to include it in a patch release towards the end of the week |
thanks a lot! |
Fixes ONNX export for swin, swin-donut and clap models
transformers/src/transformers/models/swin/modeling_swin.py
Line 643 in 82486e5
coming from :
introduced in #31311
as
torch_int
is expecting atorch.Tensor
:transformers/src/transformers/utils/generic.py
Line 765 in 82486e5
also I think we should be able to have here
cc @merveenoyan @xenova