Skip to content

When I quantize the yolo_tube.onnx model, the scale_ array tensor for bias was a scalar, so an exception was thrown #581

Closed

Description

@happyAnger66-an

https://github.com/NVIDIA/TensorRT-Model-Optimizer/blob/e35db173b170eac663abf2903e7592ee30add2f5/modelopt/onnx/quantization/qdq_utils.py#L666

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 781, in qdq_to_dq
scaled = _convert_weight(weight_array, scale, zp, quantized_node)
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 676, in _convert_weight
reshape_dims[axis] = scale_array.shape[0]
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/srcs/codes/wujie/model-optimizer/./src/model_optimizer/quantization/models/yolo.py", line 114, in
quantize_model_onnx(model, quant_cfg, quant_mode, args)
File "/srcs/codes/wujie/model-optimizer/./src/model_optimizer/quantization/models/yolo.py", line 39, in quantize_model_onnx
quantize(
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/quantize.py", line 523, in quantize
onnx_model = qdq_to_dq(onnx_model)
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 806, in qdq_to_dq
raise RuntimeError(f"Failed to convert node {node.name}: {e!s}")
RuntimeError: Failed to convert node /model.23/cv3.0/cv3.0.2/weight_quantizer/QuantizeLinear: tuple index out of range

After adding the following code, the problem can be fixed
scale_array = onnx.numpy_helper.to_array(scale)
if not scale_array.shape: ### ---------this is my added
scale_array = np.expand_dims(scale_array, axis=0)
print(f'none scale found extend to {scale_array}')

Activity

  1. changed the title [-]When I quantified the yolo_tube.onnx model, the scale_ array tensor for bias was a scalar, so an exception was thrown[/-] [+]When I quantize the yolo_tube.onnx model, the scale_ array tensor for bias was a scalar, so an exception was thrown[/+] on Nov 20, 2025
  2. happyAnger66-an commented on Nov 20, 2025

    @happyAnger66-an
    Author

    After adding the following code, the problem can be fixed

    scale_array = onnx.numpy_helper.to_array(scale)
    if not scale_array.shape: ### ---------this is my added
    scale_array = np.expand_dims(scale_array, axis=0)
    print(f'none scale found extend to {scale_array}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions