-
Notifications
You must be signed in to change notification settings - Fork 199
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
BrevitasQuantProxyHandler args passing may be sometimes wrong #986
Comments
Quick response while I investigate further. Firstly, if you want a kwarg to apply to the weight quantizer, you need to prefix it with So before we discuss export, could you please check that the quantizer is being instantiated as you intend? You can quickly check with some code like this: import brevitas.nn as qnn
from brevitas.quant import Int8WeightPerTensorFloat
layer = qnn.QuantLinear(
2,
3,
True,
weight_bit_width=7, # weight_ prefix
bias_quant=None,
weight_narrow_range=False, # weight_ prefix
weight_signed=True, # weight_ prefix
weight_quant=Int8WeightPerTensorFloat
)
print(layer.weight_quant.tensor_quant.int_quant.signed)
print(layer.weight_quant.tensor_quant.int_quant.narrow_range)
print(layer.weight_quant.tensor_quant.msb_clamp_bit_width_impl()) With your chosen values inserted. However, I would've expected |
Also, thanks for the detailed issue description! |
I tried changing
but the I checked with the debugger so I'm pretty sure the problem is the one I detailed above. If you can not reproduce I can try to provide minimal code, but the order of the A solution could be to use introspection to list the arguments of the quantization function and do something to make sure the caller sorts the symbolic args in the right order. Another approach would be to use kwargs in |
Thanks for confirming. I haven't been able to reproduce it yet... What python version are you using? It seems that dictionary order for Sources:
|
I am using 3.8 so you're right, the order of the definition should be preserved, but maybe something weird is going on because a copy is made and some .pop calls are executed on the
while the original
|
Good spotting - I'll continue to investigate and get back to you |
Actually, a quick inspection tells me that |
That fixes the bug! I'm not sure there's a way to add test for it as you could not repro in the first place. Maybe and idea would be to make a test that looks at the |
The QONNX tests need a revamp. I'm going to open that as a separate issue and address it when we revamp those tests. |
I have a QuantLinear that I instantiate like so:
I export the model with
BrevitasOnnxManager
:when the weights are exported, the
BrevitasQuantProxyHandler
is called:this in turn calls
In
BrevitasQuantFn
the arguments to forward are positional, but these arguments are given as*self.symbolic_kwargs.values()
wheresymbolic_kwargs
is a dictionary.I think there is an issue with the order of arguments as sometimes, while I set
signed=True/narrow=False
everywhere, the exported onnx shows the opposite:It would seem to be related to the dicitonary
.values
not being ordered, assymbolic_kwargs
is adict
.Do you know of any workaround?
The text was updated successfully, but these errors were encountered: