Skip to content

ARM i2_s (1.58-bit) CPU path produces constant output; fix in pinned llama.cpp submodule #610

Open

Description

@Scottcjn

The ARM CPU path for i2_s (1.58-bit ternary) produces constant, prompt-independent output (@@@@) on AArch64, while the x86 AVX2 path is correct and Metal aborts on tensor type 36. This affects builds using the pinned 3rdparty/llama.cpp submodule (isHuangXin/llama.cpp @ release-bitnet-embedding-0.6b-270m).

Root cause is in the ARM fallback of ggml_vec_dot_i2_i8_s in ggml/src/ggml-cpu/quants.c: it unpacked the 2-bit weights with a sequential layout instead of the interleaved layout the dequantizer and AVX2 path use, remapped the ternary codes instead of keeping the raw 0/1/2 the caller subtracts against, and only handled one of the two vec-dot calling conventions. Confirmed by reverting one file at a time on a clean tree (reverting quants.c brings the constant output back).

Fix (2 files, quants.c + ggml-cpu.c) submitted upstream to the pinned fork:
isHuangXin/llama.cpp#6

Tested on Apple M2, same i2_s GGUF before and after: coherent prompt-dependent output restored (5 of 5 distinct prompts distinct), about 30 tok/s generation vs about 2 tok/s on the scalar path, and 48 of 48 exact-integer parity against an independent scalar reference. This lines up with the open issues #468 (to_float UB) and #585 (i2_s layout).

Credit: the degeneracy was first isolated in a two-node verification pass by John Reed (github.com/jar9, Meridian North). Once the submodule pin picks up the fix by commit, the BitNet ARM CPU path is restored.

Activity

  1. shifulegend commented on Aug 11, 2026

    @shifulegend

    Great work tracking this down. We hit this exact same QK_I2_S block layout mismatch (64 vs 128 elements) when building the ARM NEON vdotq_s32 kernels for Project Zero.

    When the layout is hardcoded to 64 on AArch64, it halves the outer block stride, feeding misaligned offsets into the row traversal. We eventually solved this class of bugs by enforcing a strict interleaved C99 layout and using runtime SIMD dispatch (AVX2 / NEON / scalar) rather than #ifdef __ARM_NEON compile-time layout switches, keeping the core architecture-invariant.

    Glad to see the pinned submodule is picking up the fix — isolating that degeneracy across architectures is not easy!

  2. Scottcjn commented on Aug 12, 2026

    @Scottcjn
    Author

    Thanks, good to know we weren't the only ones who hit this. You're right that runtime dispatch with one interleaved layout is the cleaner fix. I kept this one as a compile-time #elif so it stays small and easy to review against the pinned submodule, but a single arch-invariant layout that only swaps the kernel is the better structure, and that per-arch drift is what caused the bug in the first place. I'll take a look at how Project Zero handles it if this grows past a point fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions