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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
torch._export can't export resnet50 model #124595
Comments
Hi @ecilay, please try the following code to make export work. Changes include a) providing a tuple input to def export_quantize(m):
# Issue: bn expected 4d, got 3
from torch._export import capture_pre_autograd_graph
example_inputs = (torch.randn(1, 3, 224, 224),) # Note: input should be a tuple
# breakpoint()
m = capture_pre_autograd_graph(m, example_inputs)
# we get a model with aten ops
# Step 2. quantization
from torch.ao.quantization.quantize_pt2e import (
prepare_pt2e,
convert_pt2e,
)
from torch.ao.quantization.quantizer.xnnpack_quantizer import ( # Note: Updated import path
XNNPACKQuantizer,
get_symmetric_quantization_config,
)
# backend developer will write their own Quantizer and expose methods to allow
# users to express how they
# want the model to be quantized
quantizer = XNNPACKQuantizer().set_global(get_symmetric_quantization_config())
m = prepare_pt2e(m, quantizer)
# calibration omitted
m = convert_pt2e(m)
# we have a model with aten ops doing integer computations when possible
return m |
Thanks your fix works, however, the resnet classification results are totally wrong. You can reproduce using below inference code. Also the runtime expoerted in this way is almost doubled/tripled: pt_time: 0.0398 vs quantize_time: 0.0918
|
Besides, if I use fx export, the outputs are numerically very different from original model; though the softmax classification results are the same, is this expected? |
Do you mind share "crane.jpg" and the log? Thanks! |
馃悰 Describe the bug
I followed this documentation https://pytorch.org/docs/stable/quantization.html to try the three available quantization methods, both fx graph and eager mode works, but the export approach doesn't work.
My questions are:
Code to reproduce:
Error logs
Minified repro
No response
Versions
cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4
The text was updated successfully, but these errors were encountered: