mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2931] [CLOSED] Metal: hc matrices of any format quantized to Q8_0 at load; gemv for IQ3_XXS and IQ2_S #4345
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4345
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2931
Author: @tolstenko
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:metal-hc-q8-any-format📝 Commits (1)
468582fmetal: quantize hc matrices of any format to Q8_0 at load, and gemv for IQ3_XXS/IQ2_S📊 Changes
2 files changed (+7 additions, -3 deletions)
View changed files
📝
metal/kernels/gemv.metal(+1 -1)📝
metal/src/engine/window.cpp(+6 -2)📄 Description
What it changes
Two related fixes in
metal/, both hit while running uncensored fine-tune GGUFs of Qwen3.8-Flash-Next on Apple Silicon (files whose hc/attention tensors are quantized differently from the original and the Unsloth releases).metal/only; the CUDA/HIP builds are untouched.1. The hyper-connection read assumed BF16/Q8_0/F32 hc tensors
Window::init's HC-Q8 step (metal/src/engine/window.cpp) only quantizedhc_matrices that were already BF16; Q8_0 and F32 were read natively bygr_down_8_8/gr_down_q8_8_8/gr_up*. A fine-tune that re-quantized those tensors to IQ3_S (down/inject) and IQ4_NL (up) made the host pick the plain kernels, which read the bytes of a different format. The logits came out NaN on the first decode; the sampler's all-NaN path returned token 2147483647 (thebi = 0x7fffffffsentinel in sample.metal'sargmax_part), the server surfaced it asIndexError: token id 2147483647 is outside the vocabulary, and the engine then segfaulted iniq3s_gridinsidemtp_encodewhen the drafter gathered the embedding of that bogus token.The fix is in the loader, not new kernels: the HC-Q8 step now takes
hc_matrices of every quantized format (skips only Q8_0/F32, which the file's own kernels already read, and*_norm), dequantizes from the tensor's own type, and quantizes to Q8_0 once at load — the same treatment BF16 tensors already got.gr_down_q8/gr_up_q8then handle them unchanged.2.
gemv.metalwas missing IQ3_XXS and IQ2_Smoe.metalinstantiates both (expert gate/up), but plaingemvdid not — so a model with an IQ3_XXS shared-expert gate (ffn_gate_shexp) or an IQ2_S attention projection failed withno function gemv_18_16_1_4_1/gemv_22_16_1_4_1(exit 3) before its first token. AddedGV_SET(T_IQ3_XXS)andGV_SET(T_IQ2_S)to the defaultGEMV_TYPES.Measured (M2 Max, 96 GB unified memory, macOS 26.6.2)
With RVN Uncensored IQ3_S (88.9 GB merged GGUF, experts streamed from the SSD,
--spec 2+ MTP):token id 2147483647 is outside the vocabulary (248320); direct CLI run → SIGSEGV iniq3s_grid(stack:mtp_encode←mtp_draft)./health→"loaded": true; completions return real text; decode 9.0-10.4 tok/s (51-token story in 4.9 s), MTP drafting 19/32 accepted. The HC-Q8 step logs290 matrices, 680 MB, made in 222 ms.The HC-Q8 conversion is a one-time per-load cost (222 ms); resident and streaming modes both quantize only the hc matrices, everything else keeps the file's own kernels, so the validated packs' paths are unchanged.
STRATA_HC_Q8=0still selects the exact-BF16 read for files whose hc tensors are BF16.What I did not test
metal/(and the two files it touches are Mac-only paths).Happy to add anything else the review wants measured.
Fixes the failure mode behind: running a non-validated quantization of the model on the Mac engine — the engine refused with a missing-function error (clear) or silently produced NaN tokens (not clear) depending on which tensor hit first.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.