perf: Improve CPU performance on x64 and arm64#1968
Open
matthewdouglas wants to merge 27 commits into
Open
Conversation
…ts' into cpu-perf-improvements
Member
Author
|
cc @jiqing-feng for x86-64 visibility and @pdeep854 for arm64 visibility |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improves CPU performance on x64 and arm64. Specifically focused on the blockwise quantization/dequantization ops. The improvements come mostly from improved use of SIMD features, with a minor bump from some adjustments to compile flags.
Depending on op, dtype, and hardware, improvements range from 1.1x to over 20x, with the largest gains on fp16 and on x86-64 CPUs without AVX-512.
General changes:
-fno-semantic-interpositionon LinuxMore specific changes/benchmarks:
x86-64
dequantize_4bitWithout AVX-512
Impacts CPUs without AVX-512 support, or Windows where we do not build for AVX-512 yet. Improvements for fp32/fp16 range 2.4x-23x depending on shape. Improvement for bf16 ranges 3.5x-11x depending on shape.
Linux, Ryzen 7950X, PyTorch 2.12.0, blocksize=64, NF4, AVX-512 disabled
With AVX-512
Improvements here range from negligible to up to 1.8x-2.3x depending on the shape and dtype. One note: the AVX-512 gains measured here are modest on Zen4 with 2x256 lanes, but may be more pronounced on Zen5+ or Intel chips.
Users with further AVX-512BF16 extension support are more likely to be taking the fused GEMM path for inference than relying on dequantization. E.g. the Zen4 CPU used to benchmark would take the AVX-512BF16 path. However the dequantization would be used on older Intel AVX-512 CPUs.
Linux, Ryzen 7950X, PyTorch 2.12.0, blocksize=64, NF4
dequantize_blockwiseThis brings fp16 performances in line with bf16.
quantize_blockwisefp16 input sees up to 1.3x improvement while fp32/bf16 are relatively flat.
ARM64
dequantize_4bitImproved the existing NEON path by handling LUT with a vectorized table lookup (
vqtbl4q_u8). This applies to all dtypes. Overall 1.1x-1.4x improvement.Apple M4, macOS 15, PyTorch 2.12.0, blocksize=64, NF4
dequantize_blockwiseAdded NEON vectorized implementation for all dtypes. 1.3-1.6x improvement for fp32 (the most common use case), 2.0-2.6x for bf16, and significantly stronger improvements fp16.
Apple M4, macOS 15, PyTorch 2.12.0, blocksize=256
quantize_blockwiseExtended existing fp32 NEON absmax reduction to bf16/fp16.
The fp32 performance is unchanged, while bf16/fp16 improve ~3x and 5-6x respectively.
Apple M4, macOS 15, PyTorch 2.12.0, blocksize=256