Help with Custom ONNX Model Optimization – matmul2 Layer Error

Hi everyone,

I’m working on optimizing and compiling a custom ONNX model for deployment on the Hailo platform. So far, I’ve successfully parsed the ONNX into a HAR file and used a subset of images from my dataset to run the optimization.

However, I’m running into an error during the optimization phase, specifically related to a matmul2 layer. Here’s the error message:

AccelerasUnsupportedError: layer model/matmul2 does not support shift delta.
To overcome this issue you should force larger range at the inputs of the layer using command:

quantization_param([model/matmul2], force_range_in=[range_min, range_max], force_range_index=index)

Current input ranges:
input 0: [0.003, 0.006]
input 1: [-1.143, 1.311]

Suggested fix:
quantization_param([model/matmul2], force_range_in=[0.069, 0.138], force_range_index=0)
quantization_param([model/matmul2], force_range_in=[-26.209, 30.061], force_range_index=1)

I tried adding these quantization_param lines to the .alls file, but ran into a validation error:

ValidationError: 1 validation error for ModelOptimizationConfig
translation_config → layers → model/matmul2 → force_range_in
0 must be in range (type=value_error)

To address that, I tried setting the first input range to [0, 0.138], which got past the validation, but the original shift delta error still occurs — just with updated suggested ranges.

My questions:

  1. Is there a best practice for choosing force_range_in values that avoids this shifting issue?
  2. Should I be scaling the input data differently during dataset preparation?
  3. Any tips for debugging or tuning range settings for custom layers like this?

Any guidance would be super appreciated — thanks in advance!

Hey @gje_gje ,

Welcome to the Hailo Community!

This error:

AccelerasUnsupportedError: layer model/matmul2 does not support shift delta.
ValidationError: 1 validation error for ModelOptimizationConfig
translation_config → layers → model/matmul2 → force_range_in
0 must be in range (type=value_error)

Why It’s Happening

The Hailo DFC requires that zero is included in the force_range_in values. The range [0.069, 0.138] fails because it excludes 0 — and that breaks a core validation rule.

The range [0, 0.138] would pass validation, but it still might not work for your layer depending on how much dynamic range it needs. That’s likely why you’re still seeing the shift delta error even when using valid input.


How to Fix It

Try using a range that:

  • Includes zero
  • Better matches the value scale of matmul2

For example:

quantization_param(["model/matmul2"], force_range_in=[-0.01, 0.14], force_range_index=0)

or something broader like:

quantization_param(["model/matmul2"], force_range_in=[-30.0, 30.0], force_range_index=1)

This way, you’re both passing validation and giving the quantizer enough space to work with.


  • Only scale your input data if your preprocessing doesn’t match how the model was trained. If everything’s aligned (e.g., normalized inputs, same preprocessing steps), you don’t need to change anything there.

I just wanted to say thank you for the guidance on handling the shift delta issue with the matmul2 layer. Your suggestions helped me move past that error by properly adjusting the force_range_in values.

Now, I’ve hit a new issue during the next steps of the optimization process. The model runs smoothly through most phases, but it gets stuck during the “Bias Correction” step. It doesn’t crash, but it just stops making progress and stays blocked for hours.

I’ve tested this on two different machines using WSL, and the behavior is exactly the same — always freezing at the start of Bias Correction.

Loaded 3066 calibration images of size (160, 48).
[info] Loading model script commands to slim from string
[info] Found model with 3 input channels, using real RGB images for calibration instead of sampling random data.
[info] Starting Model Optimization
[info] Model received quantization params from the hn
[info] MatmulDecompose skipped
[info] Starting Mixed Precision
[info] Assigning 4bit weights to layer slim/conv44 with 884.74k parameters
[info] Assigning 4bit weights to layer slim/conv47 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv48 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv51 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv52 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv55 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv56 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv59 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv60 with 589.82k parameters
[info] Ratio of weights in 4bit is 0.21
[info] Model Optimization Algorithm Mixed Precision is done (completion time is 00:00:02.15)
[info] Starting LayerNorm Decomposition
[info] Assigning 4bit weights to layer slim/conv44 with 884.74k parameters
[info] Assigning 4bit weights to layer slim/conv47 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv48 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv51 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv52 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv55 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv56 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv59 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv60 with 589.82k parameters
[info] Ratio of weights in 4bit is 0.21
[info] Using dataset with 64 entries for calibration
Calibration: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 64/64 [01:32<00:00, 1.44s/entries]
[info] Assigning 4bit weights to layer slim/conv44 with 884.74k parameters
[info] Assigning 4bit weights to layer slim/conv47 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv48 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv51 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv52 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv55 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv56 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv59 with 589.82k parameters
[info] Assigning 4bit weights to layer slim/conv60 with 589.82k parameters
[info] Ratio of weights in 4bit is 0.21
[info] Model Optimization Algorithm LayerNorm Decomposition is done (completion time is 00:02:00.58)
[info] Starting Statistics Collector
[info] Using dataset with 64 entries for calibration
Calibration: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 64/64 [03:25<00:00, 3.21s/entries]
[info] Model Optimization Algorithm Statistics Collector is done (completion time is 00:03:41.45)
[info] Starting Fix zp_comp Encoding
[info] Model Optimization Algorithm Fix zp_comp Encoding is done (completion time is 00:00:00.00)
[info] Starting Matmul Equalization
[info] Model Optimization Algorithm Matmul Equalization is done (completion time is 00:00:03.35)
[info] Starting MatmulDecomposeFix
[info] Model Optimization Algorithm MatmulDecomposeFix is done (completion time is 00:00:00.00)
[info] No shifts available for layer slim/conv14/conv_op, using max shift instead. delta=0.2469
[info] No shifts available for layer slim/conv14/conv_op, using max shift instead. delta=0.1234
[info] No shifts available for layer slim/conv21/conv_op, using max shift instead. delta=0.5946
[info] No shifts available for layer slim/conv21/conv_op, using max shift instead. delta=0.2973
[info] activation fitting started for slim/reduce_sum_softmax1/act_op
[info] activation fitting started for slim/reduce_sum_softmax2/act_op
[info] activation fitting started for slim/reduce_sum_softmax3/act_op
[info] activation fitting started for slim/reduce_sum_softmax4/act_op
[info] No shifts available for layer slim/conv43/conv_op, using max shift instead. delta=0.0017
[info] No shifts available for layer slim/conv43/conv_op, using max shift instead. delta=0.0009
[info] activation fitting started for slim/reduce_sum_softmax5/act_op
[info] activation fitting started for slim/reduce_sum_softmax6/act_op
[info] activation fitting started for slim/reduce_sum_softmax7/act_op
[info] activation fitting started for slim/reduce_sum_softmax8/act_op
[info] activation fitting started for slim/reduce_sum_softmax12/act_op
[info] activation fitting started for slim/reduce_sum_softmax9/act_op
[info] activation fitting started for slim/reduce_sum_softmax10/act_op
[info] activation fitting started for slim/reduce_sum_softmax11/act_op
[info] activation fitting started for slim/reduce_sum_softmax13/act_op
[info] activation fitting started for slim/reduce_sum_softmax14/act_op
[info] activation fitting started for slim/reduce_sum_softmax15/act_op
[info] activation fitting started for slim/ew_sub_softmax16/act_op
[info] activation fitting started for slim/reduce_sum_softmax16/act_op
[info] Finetune encoding skipped
[info] Starting Bias Correction

If anyone has experience with:

  • Bias Correction hanging or taking unusually long,
  • Running Hailo tools under WSL,
  • Or tips to debug or skip this phase safely,

I’d really appreciate your insights!

Thanks again for all the support so far!