-
Notifications
You must be signed in to change notification settings - Fork 26.3k
ONNX Export Interpolate (Resize) for opset version 10 #21434
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
|
waiting on #20533 to be merged (tests will fail until merged with the referenced PR) |
| return symbolic_fn | ||
|
|
||
|
|
||
| upsample_nearest1d = _interpolate('upsample_nearest1d', 3, "nearest") |
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.
fuse upsamples together is great!
maybe we should have some convention on the prefix of the helper functions, such as _interpolate, slice_op, they are not real symbolics, just some helper functions.
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 renamed slice to follow the same convention as _interpolate and other ops (_max_pool, _avg_pool).
houseroad
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.
Rebase to the master?
| return [(torch.floor(input.size(i + 2) * torch.tensor(float(scale_factors[i])))) for i in range(dim)] | ||
| return [(torch.floor(float(input.size(i + 2)) * torch.tensor(float(scale_factors[i])))) for i in range(dim)] | ||
| else: | ||
| return [int(math.floor(int(input.size(i + 2)) * scale_factors[i])) for i in range(dim)] |
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.
This cast was making the input of the operator Floor set as "integer", which is not supported (Floor only accepts float and double as input types), and fails in onnxruntime.
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 am a bit confused here, seems the tracer won't go with the else branch, why will it affect onnx's export? do you test the script module? But it's equivalent change, so i am okay with it.
| upsample_nearest1d = _interpolate('upsample_nearest1d', 3, "nearest") | ||
| upsample_nearest2d = _interpolate('upsample_nearest2d', 4, "nearest") | ||
| upsample_nearest3d = _interpolate('upsample_nearest3d', 5, "nearest") | ||
|
|
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.
Removed support for linear mode in both opsets 9 and 10.
Linear mode behaves differently in onnx and pytorch (with both align_coner enabled and disabled).
The exported model was not matching numbers with onnxruntime.
(the difference is explained here : microsoft/onnxruntime#1179).
Will try to add support to linear mode in a different PR.
|
@pytorchbot rebase this please |
facebook-github-bot
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.
@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@houseroad feedback on this? |
|
I think the failing tests are related. Could you take a look? |
facebook-github-bot
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.
@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
houseroad
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.
Looks good. Please address the questions before merge.
| return [(torch.floor(input.size(i + 2) * torch.tensor(float(scale_factors[i])))) for i in range(dim)] | ||
| return [(torch.floor(float(input.size(i + 2)) * torch.tensor(float(scale_factors[i])))) for i in range(dim)] | ||
| else: | ||
| return [int(math.floor(int(input.size(i + 2)) * scale_factors[i])) for i in range(dim)] |
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 am a bit confused here, seems the tracer won't go with the else branch, why will it affect onnx's export? do you test the script module? But it's equivalent change, so i am okay with it.
| # make scale_factor a tensor in tracing so constant doesn't get baked in | ||
| if torch._C._get_tracing_state(): | ||
| return [(torch.floor(input.size(i + 2) * torch.tensor(float(scale_factors[i])))) for i in range(dim)] | ||
| return [(torch.floor((input.size(i + 2) * torch.tensor(float(scale_factors[i]))).float())) for i in range(dim)] |
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.
seems the old code should generate the float tensor as well, is .float() conversion necessary?
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.
Without this, the generated ONNX graph fails in ORT and complains that the input of the "Floor" node is an Int.
I could submit an example of the ONNX file and the error if required.
For the following line, I did the same for consistency and out of precaution.
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.
Yea, i am wondering how the onnx model looke like? could you attach the exported model?
|
@houseroad I attached the model generated without the changes in functional.py, for the code below. def Test_Upsample_op(): |
|
@houseroad merged this pull request in 34aee93. |
No description provided.