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

pytorch-quantization example classfication_flow.py has incorrect import path #1938

Closed
Jeremalloch opened this issue Apr 20, 2022 · 1 comment
Labels
triaged Issue has been triaged by maintainers

Comments

@Jeremalloch
Copy link
Contributor

In the tools/pytorch-quantization/examples/torchvision/classification_flow.py file, in line 42, custom (Nvidia modified) pytorch models are imported. However, the code defining these models was later nested further under a classification directory, so the correct path should be models.classification. In the same file, a check is performed to see if a custom implementation exists for a model (specified by name), or if the script should fall back to torchvision implementation. This incorrect path results in the model always falling back to the torchvision implementation, without warning to the user. The modified models were authored because they made minor changes to allow quantization of residual connections (during TRT export), but by falling back to the torchvision implementation, the residual connections are left unquantized, resulting in a slower model.
The first figure below is a Netron visualization of a block in a ResNet-50 onnx model generated by the current implementation of the classification_flow.py script.
Unquantized Residual Onnx
The second figure, below, highlights the addition of the QuantizeLinear and DequantizeLinear layers along the residual path that are added by the custom implementation:
Quantized Residual Onnx

Environment

N/A, this is a universal issue.

Relevant Files

In this Google drive folder, I have included the above screenshots, as well as the onnx files that were used to generate them.

Steps To Reproduce

Run the Nvidia authored classification_flow.py already included in the repository. Then either insert a PDB breakpoint at line 150 to verify this path is never being reached, or visualize the exported onnx file and verify the lack of QuantizeLinear and DequantizeLinear layers along residual paths.

@ttyio ttyio added bug triaged Issue has been triaged by maintainers labels Apr 22, 2022
@ttyio
Copy link
Collaborator

ttyio commented Apr 22, 2022

Thanks @Jeremalloch for the catch, yes we reorg the folder structure and the classification_flow.py can no longer find the correct resnet. I had just merged your code, thanks again!

@ttyio ttyio closed this as completed Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants