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

Compute input min/max with a single vectorized pass in DynamicQuantizeLinear #531

Merged
merged 5 commits into from
Jan 10, 2025

Conversation

robertknight
Copy link
Owner

Combine the separate passes over the input to compute the min/max in DynamicQuantizeLinear with a single vectorized pass.

There is a caveat that the new implementation doesn't guarantee the same handling of NANs in the input as before, and this will vary by architecture. The ReduceMin / ReduceMax ops always propagate NANs, whereas this implementation just uses the obvious min/max intrinsic (eg. _m256_min_ps) which may do something else.

There was already a `max` method, so this fills in a gap.
This is useful for reductions which need to compute multiple values in one pass
over the data.
This allows for computing the minimum and maximum values in a slice of floats
with one pass over the slice.
Previously two separate passes over the data were used to compute the min/max
values. Use the `MinMax` op from rten-vecmath to compute this in one vectorized
pass.

In a benchmark with a quantized ModernBERT model this made DynamicQuantizeLinear
2.5-3x faster.
@robertknight
Copy link
Owner Author

For reference, ORT is using the same intrinsics I am here, or the SSE version with the same behavior in the case of x64 - https://github.com/microsoft/onnxruntime/blob/ecdeecae617d1b37b42bca51e1ade979dd260961/onnxruntime/core/mlas/lib/mlasi.h#L2230.

@robertknight robertknight merged commit c6d4245 into main Jan 10, 2025
2 checks passed
@robertknight robertknight deleted the dynamic-quantize-linear-min-max-simd branch January 10, 2025 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant