Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Training] quantize_static Histogram based calibration methods expect fixed shape outputs #18792

Open
kmn1024 opened this issue Dec 12, 2023 · 2 comments
Labels
quantization issues related to quantization stale issues that have not been addressed in a while; categorized by a bot

Comments

@kmn1024
Copy link

kmn1024 commented Dec 12, 2023

Describe the issue

When using quantize_static on models that produce variable shaped outputs, using calibrate methods that need to collect a histogram first will run this line and fail:

data_arr = np.asarray(data_arr) # noqa: PLW2901

For example, I had a model which outputs (Batch Size, Sequence Length, Embedding dims)

data_arr = np.asarray(data_arr) # noqa: PLW2901
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (200, 1) + inhomogeneous part.

To reproduce

Run this on a model that produces variable sized outputs:

quantize_static('./onnx/xxx.prep.onnx',
                                   './onnx/quantized/xxx.prep.static-dist.onnx',
                                   calibration_data_reader=cal_data,
                                   calibrate_method=CalibrationMethod.Distribution)

Urgency

quantize_static still works with CalibrationMethod.MinMax, and quantize_dynamic also works. I just want to see how well the other calibration method works for my model.

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

22.04

PyTorch Version

2.1.1

Execution Provider

Default CPU

Execution Provider Library Version

No response

@kmn1024 kmn1024 added the training issues related to ONNX Runtime training; typically submitted using template label Dec 12, 2023
@github-actions github-actions bot added the quantization issues related to quantization label Dec 12, 2023
@baijumeswani baijumeswani removed the training issues related to ONNX Runtime training; typically submitted using template label Jan 3, 2024
Copy link
Contributor

github-actions bot commented Feb 3, 2024

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Feb 3, 2024
@volker48
Copy link

Just hit this issue as well trying to use CalibrationMethod.Entropy with dynamic_axes for the batch size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quantization issues related to quantization stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants