Repository navigation
llama: load Hadamard-folded weights (prism.hadamard, Ternary Bonsai) - #34
Merged
Merged
Conversation
PrismML's Ternary-Bonsai models store most matmul weights in a blockwise
Walsh-Hadamard-rotated basis and describe it with prism.hadamard.* GGUF keys.
Without them this build loads such a file and computes garbage. Now the
loader reads the keys, builds the rotation (and sign) tensors next to the
weights, and build_lora_mm / build_lora_mm_id rotate each activation before a
folded weight (memoized per graph); token_embd lookups get the inverse. The
rotation is a plain F32 MUL_MAT, so it runs on HRX0 like any other matmul.
The first graph is checked: a folded weight consumed without its transform
or a rotated table read without the inverse is an error, not wrong output.
Follows PrismML-Eng/llama.cpp's implementation (MIT): same keys, checks and
transform. The code is in src/llama-hadamard.{h,cpp}; upstream files get
hook lines only.
Checked on HRX0: Ternary-Bonsai-2-27B (PTQ1_0 converted to Q4_0 bit-exactly
with the engine's tools/ternary_to_q4_0.py) gives wikitext-2 running PPL
7.962 / 10.408 / 10.171 at chunks 5 / 10 / 15 against 7.958 / 10.382 /
10.142 for the F16 model on CPU (PrismML's fork). Files without the keys
build the same graph as before (Qwen3.8-27B Q4_0 PPL 5.8893 both ways).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
llama_model_loader instantiates its string-keyed get_key / get_arr for a few types only; the bool and array ones did not link with GCC (CI ubuntu jobs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ollowed The prism.hadamard loader follows PrismML-Eng/llama.cpp (MIT). Keep its copyright line and permission notice with the files, as the license asks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
bong-water-water-bong
force-pushed
the
1bit/hrx-bonsai
branch
from
September 30, 2026 02:30
f375a52 to
616348a
Compare
bong-water-water-bong
merged commit Sep 30, 2026
b8d587e
into
1bit/hrx-vulkan-patched
10 of 24 checks passed
bong-water-water-bong
added a commit
that referenced
this pull request
Oct 25, 2026
… in test-backend-ops (#140) FillParams hook so two FILLs differing only in the constant cannot share a cached program; TOP_K test cases at 248320 columns, k 7/16, 1/2/8 rows, with and without ties. Pairs with the private add-on's DFlash2 selector kernels (gpu-kernels #34). Co-Authored-By: Claude Fable 5.1 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PrismML's Ternary-Bonsai models (Qwen3.8-27B trained ternary) store most matmul weights rotated by a blockwise Walsh-Hadamard transform, described by
prism.hadamard.*GGUF keys. This build used to load such a file and compute garbage. Now:build_lora_mm/build_lora_mm_idrotate each activation before a folded weight (once per activation per graph); thetoken_embdlookup gets the inverse;The rotation is a plain F32
MUL_MAT, so it runs on HRX0 with the existing kernels. The code is insrc/llama-hadamard.{h,cpp}(ours); upstream files get hook lines only (29 lines over 8 files).The weights themselves go through the engine's
tools/ternary_to_q4_0.py: PrismML's PTQ1_0 written as Q4_0, bit-exact.Checked on HRX0 (strixhalo, gfx1151):
🤖 Generated with Claude Code