You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add hand-written AArch64 NEON implementations for eight quantize_row_*
functions that currently fall through to the scalar _ref versions, and
remove two serial dependency chains in the K-quant vec_dot kernels.
Scope: this speeds up the quantize path, i.e. llama-quantize and
non-quantized -> quantized type conversion. It does not change inference
throughput. mul_mat quantizes activations to vec_dot_type, so for a Q4_0
weight it calls quantize_row_q8_0, never quantize_row_q4_0. Measured with
llama-bench on Qwen2.5-1.5B Q4_K_M and Q4_0 (8 threads): pp512 -0.02%,
pp128 0.00%, tg32 within noise.
Mechanism: the generic quantize_row_* entry points in quants.c are renamed
to *_generic so that arch-fallback.h can route each architecture to a native
implementation; aarch64 then provides NEON versions in arch/arm/quants.c.
The renaming and the arch-fallback.h blocks are part of this change because
the mapping references the *_generic symbols.
Quantize kernels, all verified bit-exact against the _ref implementations
over the full block set, including +-0.0f, subnormals and +-1e30:
q4_0: pmax/pmin pairwise reduction for the signed extremum instead of a
per-lane sign mask, whole-block 32-nibble narrow+interleave with a single
16-byte store, 2-block unroll. A cold-path rescan (ggml_arm_first_amax)
preserves the reference's first-in-memory-order semantics when a block
contains both +A and -A with |A| beyond fp16 range.
q4_1, q5_0, q5_1: same structure; q5_0/q5_1 share ggml_arm_qh_16() for
the 5-bit high bits.
q8_0, q8_1: vqmovn_s32/vqmovn_s16 saturating narrow chain plus two
vst1q_s8 stores, replacing 32 vgetq_lane_s32 extractions.
q8_K: vmaxq_f32 reduction for amax with a scalar pass to recover the
sign, then vcvtnq_s32_f32 + vqmovn + vst1q_s8, bsums via vaddlvq_s8;
the amax sign scan uses 4-element vceqq_f32 groups.
q3_K: new NEON implementation replacing the scalar _ref forwarder.
vec_dot: q5_K splits the nested ggml_vdotq_s32 chain into two independent
sdot chains combined with vaddq_s32; q4_K unrolls the NEON branch by 2 blocks.
Many agents do not load AGENTS.md on their own. Please tell your agent explicitly, e.g.: Read AGENTS.md and follow it strictly. Then review all changes in this branch against it and fix any violation.
github-actionsBot
added
ggml
changes relating to the ggml tensor library for machine learning
and removed
draft
PR will be changed to draft by github-actions bot
labels
Dec 4, 2026
This branch has not been deployed
No deployments
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
ggmlchanges relating to the ggml tensor library for machine learning
1 participant
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.
Add hand-written AArch64 NEON implementations for eight quantize_row_*
functions that currently fall through to the scalar _ref versions, and
remove two serial dependency chains in the K-quant vec_dot kernels.
Scope: this speeds up the quantize path, i.e. llama-quantize and
non-quantized -> quantized type conversion. It does not change inference
throughput. mul_mat quantizes activations to vec_dot_type, so for a Q4_0
weight it calls quantize_row_q8_0, never quantize_row_q4_0. Measured with
llama-bench on Qwen2.5-1.5B Q4_K_M and Q4_0 (8 threads): pp512 -0.02%,
pp128 0.00%, tg32 within noise.
Mechanism: the generic quantize_row_* entry points in quants.c are renamed
to *_generic so that arch-fallback.h can route each architecture to a native
implementation; aarch64 then provides NEON versions in arch/arm/quants.c.
The renaming and the arch-fallback.h blocks are part of this change because
the mapping references the *_generic symbols.
Quantize kernels, all verified bit-exact against the _ref implementations
over the full block set, including +-0.0f, subnormals and +-1e30:
per-lane sign mask, whole-block 32-nibble narrow+interleave with a single
16-byte store, 2-block unroll. A cold-path rescan (ggml_arm_first_amax)
preserves the reference's first-in-memory-order semantics when a block
contains both +A and -A with |A| beyond fp16 range.
the 5-bit high bits.
vst1q_s8 stores, replacing 32 vgetq_lane_s32 extractions.
sign, then vcvtnq_s32_f32 + vqmovn + vst1q_s8, bsums via vaddlvq_s8;
the amax sign scan uses 4-element vceqq_f32 groups.
vec_dot: q5_K splits the nested ggml_vdotq_s32 chain into two independent
sdot chains combined with vaddq_s32; q4_K unrolls the NEON branch by 2 blocks.
Quantize throughput (test-quantize-perf, GB/s):
q4_0 2.03 -> 4.44 (+118.7%) q4_1 1.09 -> 2.42 (+122%)
q5_0 0.89 -> 1.98 (+122%) q5_1 0.87 -> 1.95 (+124%)
q8_0 2.31 -> 4.12 (+78%) q8_1 2.28 -> 4.05 (+78%)
q8_K 1.42 -> 1.58 (+11%) q3_K 0.06 -> 0.13 (+117%)
Tested on aarch64, tsv110, GCC 12.3.1 with test-quantize-fns, test-backend-ops and test-barrier.