aimet icon indicating copy to clipboard operation
aimet copied to clipboard

How to Disable Concat Quantization Nodes, and how to Share the Same Quantization Parameters Across Multiple Layers

Open piantou opened this issue 6 months ago • 3 comments

(1) As shown in the figure below, I want to disable quantization for the specified Concat node. How should I write the corresponding code or configuration rules?

Image

(2) Taking the quantization tool TinyQ as an example, it can explicitly bind multiple operators through surgeon.connect to share the same set of quantization parameters (scale/zero_point). During operator fusion, only one set of QDQ nodes is retained, which reduces computation and accelerates inference. Taking the Add operation as an example (shown in the figure below), to enable operator fusion and acceleration in the subsequent inference stage, it is required that the quantization parameters (scale) of all its input branches must be exactly the same. How can this be implemented in AIMET?

Image

Looking forward to your reply to clarify my questions. Thank you.

piantou avatar May 26 '26 01:05 piantou

Hi @piantou, are you working in aimet-onnx or aimet-torch here?

michaelgtuttle avatar Jun 01 '26 23:06 michaelgtuttle

Hi @piantou, are you working in aimet-onnx or aimet-torch here?

aimet_torch dear

piantou avatar Jun 03 '26 11:06 piantou

Hi @piantou, the most straightforward way to tie the output quantizers of two layers in aimet-torch is to assign the same quantizer object to each layer, for example:

# Output encodings of layer_1 will always match output encodings of layer_2
sim.model.layer_1.output_quantizers[0] = sim.model.layer_2.output_quantizers[0]

To manually disable a layer's output quantizer you can set it to None, e.g.,

# Disables output quantizer of model.silu_1
sim.model.silu_1.output_quantizers[0] = None

For your specific use-case of tying the output quantizers of a layer to the inputs, we have a util which will do this graph traversal for you and tie the quantizers automatically:

from aimet_torch.experimental import quantsim_utils
from aimet_torch.nn.modules import custom

# To tie one specific layer's output quantizer to inputs:
quantsim_utils.propagate_output_encodings(sim, sim.model.add)

# To tie for all layers of type custom.Add or custom.Concat (change as necessary for your model)
quantsim_utils.propagate_output_encodings(
    sim, lambda layer: isinstance(layer, (custom.Add, custom.Concat))
)

Note that for Concat layers, tying the output quantizer to input quantizers is exactly the same as disabling the input quantizers from an accuracy standpoint, but is generally easier for downstream tools to ingest.

michaelgtuttle avatar Jun 04 '26 17:06 michaelgtuttle