Skip to content

[Feature request] Support 1D vector for w_scale in QLinearConv reference implementation #6428

@mcollinswisc

Description

@mcollinswisc

System information

1.17.0 release

What is the problem that this feature solves?

Documentation for w_scale argument to QLinearConv operator (https://github.com/onnx/onnx/blob/41cba9d512620781257163cb2ba072871456f8d3/docs/Operators.md#QLinearConv) states:

It could be a scalar or a 1-D tensor, which means a per-tensor/layer or per output channel quantization. If it's a 1-D tensor, its number of elements should be equal to the number of output channels (M).

If using QLinearConv with a 1D vector for w_scale in onnx.reference.ReferenceEvaluator, though, will get a numpy broadcast error. It can be seen by running this file:
https://gist.github.com/mcollinswisc/bccaa6730089c4221f53415a39b6835b

I see error:

Traceback (most recent call last):
  File "onnx_qlinearconv.py", line 71, in <module>
    ref_result = ref_eval.run(None, {"x": x})
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/qlinearconv/lib/python3.12/site-packages/onnx/reference/reference_evaluator.py", line 599, in run
    outputs = node.run(*inputs, **linked_attributes)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/qlinearconv/lib/python3.12/site-packages/onnx/reference/op_run.py", line 466, in run
    res = self._run(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/qlinearconv/lib/python3.12/site-packages/onnx/reference/ops/op_qlinear_conv.py", line 53, in _run
    R = res * (x_scale * w_scale / y_scale)
        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ValueError: operands could not be broadcast together with shapes (1,8,24,24) (8,) 

Thrown from here:

R = res * (x_scale * w_scale / y_scale)

Alternatives considered

N/A

Describe the feature

For getting full reference implementation results from QLinearConv.

Will this influence the current api (Y/N)?

No

Feature Area

ReferenceEvaluator

Are you willing to contribute it (Y/N)

Yes

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions