Skip to content

Fix pytorch_half_pixel resize mode in Resize op #654

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

Merged
merged 5 commits into from
Apr 8, 2025

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented Apr 8, 2025

The formula was copied from the specification, but neglected to account for the fact that scale in the Rust code is the scale going from output to input, whereas in the spec it is the inverse scale from input to output. In the Rust code the inverse scale is used in order to replace division with multiplication.

The bug was encountered while testing a version of the DeepLab v3 model exported using TorchDynamo via export-deeplab.py --dynamo. In that model the final Resize op produced the wrong result with the previous pytorch_half_pixel implementation. This PR also contains a reference implementation of DeepLab and update to the tensor comparison script used in debugging.

Support reading input tensors as JSON rather than binary in
`compare-tensors.py`. The expected JSON format matches that used by
rten-tensor's serde serialization. This JSON format is much less space efficient
than the binary format, but more convenient to generate.
The formula was copied from the specification, but neglected to account for the
fact that `scale` in the Rust code is the scale going from output to input,
whereas in the spec it is the inverse scale from input to output. In the Rust
code the inverse scale is used in order to replace division with multiplication.
Use the built-in support for creating tensors from nested arrays instead of
manually demarcating rows with comments.
@robertknight robertknight merged commit 3269bd6 into main Apr 8, 2025
2 checks passed
@robertknight robertknight deleted the fix-pytorch-half-pixel branch April 8, 2025 06:47
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.

1 participant