-
Notifications
You must be signed in to change notification settings - Fork 35
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
Int8 default ranges break when a bconv is followed by a normal conv. #421
Comments
Just to note, until we fix this in LCE this issue can be worked around by explitly adding TensorFlow fake quantise ops before and after the problematic layer that doesn't get converted properly. E.g.: model = tf.keras.models.Sequential([
tf.keras.Input((32, 32, 3)),
lq.layers.QuantConv2D(
32,
(3, 3),
input_quantizer="ste_sign",
kernel_quantizer="ste_sign",
padding="same",
pad_values=1.0,
use_bias=False
),
tf.keras.layers.Lambda(lambda x: tf.quantization.fake_quant_with_min_max_args(x, -3.0, 3.0)),
tf.keras.layers.Conv2D(32, (3, 3)),
tf.keras.layers.Lambda(lambda x: tf.quantization.fake_quant_with_min_max_args(x, -3.0, 3.0)),
])
converted_model = lce.convert_keras_model(model, experimental_default_int8_range=(-3, 3)) (It may not be clear from the screenshot, but the converted model is entirely Int8.) |
Looks like we are running into tensorflow/tensorflow#40055 here since the model = tf.keras.models.Sequential([
tf.keras.Input((32, 32, 3)),
lq.layers.QuantConv2D(
32,
(3, 3),
input_quantizer="ste_sign",
kernel_quantizer="ste_sign",
padding="same",
pad_values=1.0,
use_bias=False
),
tf.keras.layers.Conv2D(32, (3, 3), bias_initializer="random_uniform"),
])
converted_model = lce.convert_keras_model(model, experimental_default_int8_range=(-3, 3)) |
Just an extra note: if that's indeed the cause of the bug, then training the network (on any dataset, even random data) for just 1 epoch should also fix this, and will work on any type of network. |
@lgeiger do you have any idea why a |
There it is not a problem since both biases will be converted to int32 and still can be shared. The reason it fails is because |
Observed behaviour
When converting this model...
...we obtain the following converted model, with extra dequantise and quantise nodes around the
Conv2D
:Expected behaviour
We expect there to be no dequantise or quantise nodes in a converted model when the
experimental_default_int8_range
argument is used.If the
QuantConv2D
is replaced by a normalConv2D
we get:Similarly, if the
Conv2D
is replaced with aQuantConv2D
we get:So there is something specifically going wrong with the
QuantConv2D > Conv2D
combination.The text was updated successfully, but these errors were encountered: