Skip to content

Int8 default ranges break when a bconv is followed by a normal conv. #421

@AdamHillier

Description

@AdamHillier

Observed behaviour

When converting this model...

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)),
])
converted_model = lce.convert_keras_model(model, experimental_default_int8_range=(-3, 3))

...we obtain the following converted model, with extra dequantise and quantise nodes around the Conv2D:

image

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 normal Conv2D we get:

model = tf.keras.models.Sequential([
    tf.keras.Input((32, 32, 3)),
    tf.keras.layers.Conv2D(
        32, (3, 3), padding="same", use_bias=False
    ),
    tf.keras.layers.Conv2D(32, (3, 3)),
])
converted_model = lce.convert_keras_model(model, experimental_default_int8_range=(-3, 3))

image

Similarly, if the Conv2D is replaced with a QuantConv2D we get:

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
    ),
    lq.layers.QuantConv2D(
        32,
        (3, 3),
        input_quantizer="ste_sign",
        kernel_quantizer="ste_sign",
        padding="same",
        pad_values=1.0,
        use_bias=False
    ),
])
converted_model = lce.convert_keras_model(model, experimental_default_int8_range=(-3, 3))

image

So there is something specifically going wrong with the QuantConv2D > Conv2D combination.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions