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

Add small optimizations for QuantizeLinear #532

Merged
merged 2 commits into from
Jan 11, 2025

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented Jan 11, 2025

Add a couple of small and easy optimizations to QuantizeLinear. This also benefits DynamicQuantizeLinear.

  • Replace division with multiplication by reciprocal
  • Remove unnecessary clamp-ing as Rust's as operator does this for us

This is ~15% faster in a test with ModernBERT. It should be possible to do much better with SIMD, but that will come later.

Optimize QuantizeLinear and DynamicQuantizeLinear by replacing divisions
with multiplication by a pre-computed reciprocal.
Rust's `as` operator already does the desired saturating cast when converting
from f32 -> i8 / u8.
@robertknight robertknight merged commit e3eb30f into main Jan 11, 2025
2 checks passed
@robertknight robertknight deleted the quantize-linear-reciprocal branch January 11, 2025 08:45
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