mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5387] [Engine] Metal: fix garbage output with Unsloth low-bit files (BF16 ple_conv1d read as F16) #5412
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#5412
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/5387
Author: @qChauncey
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:metal-ple-conv1d-bf16📝 Commits (1)
dc1cf66[Engine] Metal: narrow a BF16 blk.1.ple_conv1d to F16 at load📊 Changes
1 file changed (+13 additions, -4 deletions)
View changed files
📝
metal/src/engine/window.cpp(+13 -4)📄 Description
Problem and result
On the Metal engine, Unsloth's UD-IQ2_XS (Dynamic v3.1, uploaded 2026-11-04) answers with garbage from the first token. Logits are finite (STRATA_METAL_NFCHECK: largest |logit| 19.6); DFlash2 accepts ~0 drafts. With this change the same file gives coherent answers.
Cause: ple_conv_add reads blk.1.ple_conv1d.weight as F16. Window::init (metal/src/engine/window.cpp) converts it only when the GGUF stores it as F32 and otherwise passes the file's bytes through. In these files it is BF16 - the same size as F16 - so the BF16 words are read as F16, the layer-1 PLE conv is wrong, and every later layer follows.
Which files store it how (headers read with tools/quantscope.py; not all of them were run):
Of the sets the 0.2.11 Mac app offers, UD-IQ1_M, UD-Q2_0, UD-IQ2_XS and UD-Q2_K_XL are affected.
Related discussion
none (focused fix). #4711 (UD-Q4_K_XL) stores ple_conv1d as F32, so it is not this bug.
Approach
Convert BF16 like F32 (bf16 -> f32 -> ref::f32_to_f16, round to nearest even - the same rule tools/iq_pack.py uses when it stores this tensor as F16 in the pack), and refuse the start with a message for any other non-F16 type instead of computing with it.
Compatibility: F16 files take the same path as before; F32 files get the same arithmetic as before. Every Metal reader of this tensor (decode, verify windows, prompt chain) goes through kw_arg() / kw_host(), so all of them see the converted copy. Metal only: the CUDA / HIP / SYCL engines read this tensor from the pack, where iq_pack --compat-bf16 already converts it (conversions.json: bf16->f16).
Cost: load time only - 40,960 values once and an 80 KB buffer; the decode and prompt kernels are unchanged.
Validation
Environment: Mac Studio M4 Max 36 GB, macOS 27.2; main at
9f7d977d+ this patch; engine built withcmake --build build-metal --target strata; served by the Strata app 0.2.11 with the run config's exe pointed at the built engine; experts streamed from the SSD (STRATA_METAL_STREAM=1). UD-IQ2_XS freshly prepared from the original Unsloth shards (metal/tools/metal_repack.py --verify, metal/tools/stream_experts.py --verify, tools/iq_pack.py --compat-bf16).Passed:
Failed:
none observed
Not run:
Limits
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.