]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
convert : apply Q/K RoPE permutation in NVFP4 repack path (#22611)
authorJM Robles <redacted>
Sun, 3 May 2026 15:22:00 +0000 (17:22 +0200)
committerGitHub <redacted>
Sun, 3 May 2026 15:22:00 +0000 (18:22 +0300)
commitdb44417b027cff147f7de85e7da22bc6a3a804fb
treeb7ce3a69128c2d4915ecf49ac7b7930801c304dc
parentd05fe1d7dadbf8943c8f1903fcf65b935ddab839
convert : apply Q/K RoPE permutation in NVFP4 repack path (#22611)

Llama-architecture q_proj/k_proj weights need an axis-0 row permutation
to match GGML's RoPE convention. The BF16 path applies this in
LlamaModel.modify_tensors via LlamaModel.permute, but the NVFP4 path
bypasses modify_tensors and writes weights directly through
ModelBase._repack_nvfp4. Without the permutation, attention heads end
up scrambled at inference and the model produces gibberish.

This change overrides _repack_nvfp4 on LlamaModel and applies the same
permutation to both the nibble-packed weight and the per-block scale
before delegating to ModelBase._repack_nvfp4 via super(). Reuses the
existing LlamaModel.permute static helper and respects the existing
undo_permute flag, so subclasses (Mistral, Granite, Llama4, etc.)
inherit the fix automatically.

Verified on TinyLlama-1.1B reproducer: perplexity drops from 4419
(gibberish) to 43.9, matching the BF16-dequantized baseline (44.0).
Also verified end-to-end on ALIA-40b-instruct-2601 (BSC, Llama
architecture) with multilingual generation in Spanish/Catalan/Basque/
Galician all coherent with the fix applied.

Co-authored-by: Chema <redacted>
convert_hf_to_gguf.py