-
Notifications
You must be signed in to change notification settings - Fork 115
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
unnecessary float() variables cause quantization to fail. #281
Comments
您好,我已经收到您的邮件,我会尽快查看并在第一时间回复您。
|
Would you please try
|
Thank you for the tips! That's got me a bit further, although now I'm getting: And I look forward to trying the |
This may happen if
Sure, I can add this.
Nope, the input for the conversion step won't affect the PTQ calibration, because the quantized ranges are frozen when you call |
I'm definitely loading the weights, so I guess I'll be looking for if there's something like 2. And then if it's important or if it's something that should be 0, but is hitting float rounding errors or similar. |
I think it must be case 2, as I eventually found in the output: PyTorch don't make it easy to report bugs (not sure I can make a minimal reproducer), and from what you say it might not be a bug anyway? I've tried to ask a question on PyTorch forums, but that's awaiting moderation... Thanks for your help (and if you've got any other ideas!), but it looks like this one might just be a quantization fail? |
@BmanClark I guess you may print out the input/output scales of the add operations to find out something weird. You can do that on a model after |
I'm quantizing the MI-GAN network that I have previously converted to tflite successfully with your help (thank-you!)
I'm basing my conversion off your https://github.com/alibaba/TinyNeuralNetwork/blob/main/examples/quantization/post.py script, and I've managed to work my way through some difficulties (especially convincing pytorch not to quietly convert floats to doubles, which then stop the conversion - a force double to float before quantizing switch might be a nice feature).
My current issue though seems an unnecessary one. I'm hitting:
"Creation of quantized tensor requires quantized dtype like torch.quint8" which appears to come from https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/quantized/TensorFactories.cpp line 115 or 128 or similar.
This is because in (Traceback):
converter.convert()
File "[longpath]/tinynn/converter/base.py", line 476, in convert
self.init_jit_graph()
File "[longpath]/tinynn/converter/base.py", line 228, in init_jit_graph
script = torch.jit.trace(self.model, self.dummy_input)
it reads a python script version of the model created earlier by
quantizer.quantize()
(generator_q.py.txt[earlier: self.fake_quant_1 = torch.quantization.QuantStub() ]
float_0_f
is then never used, so could just not exist, rather than cause a failure. There are dozens of these, and none of the float values are used.Is there a way to stop these values being created? I can't immediately see where they come from to know if I can adjust the model or similar, but as they're unused, is there a way to have them automatically pruned?
A side question - is there a way to convert expected inputs from float to int as well? I have image input to the network that I have to convert from 0-256 to -1.0-1.0, so if there was a way to convert to sticking with integer, that would also be useful.
The text was updated successfully, but these errors were encountered: