Skip to content

QVAC-25280: add Ternary Bonsai core and CPU support - #283

Merged
gianni-cor merged 15 commits into
temp-10549from
qvac-25280-bonsai-core-cpu
Sep 24, 2026
Merged

gianni-cor merged 15 commits into
temp-10549from
qvac-25280-bonsai-core-cpu

Conversation

@pratiknarola-t

@pratiknarola-t pratiknarola-t commented Sep 21, 2026 •

Copy link
Copy Markdown

Overview

Adds the core runtime and CPU support for the published prism-ml/Ternary-Bonsai-2-27B-gguf formats:

  • PQ2_0: tensor type 142, 34 bytes per 128 weights, file type 141
  • PTQ1_0: tensor type 143, 28 bytes per 128 weights, file type 143
  • GGUF, RPC, quantization, ARM, x86, and fallback CPU integration
  • Bonsai model metadata, conversion, and signed Hadamard activation graph support
  • x86 VNNI acceleration for PTQ1_0
  • Backend operation coverage, including 5120, 6144, and 17408-wide signed Hadamard cases

This is PR 1 of 4 in the Ternary Bonsai stack.

Verification

  • GGUF and quantization suites: 165/165
  • Apple M5 CPU ternary matrix multiplication: 344/344
  • Apple M5 CPU Hadamard: 33/33
  • Ryzen CPU backend operations: 386/386
  • Deterministic generation returns 126 on Apple M5 CPU and Ryzen CPU
  • Pinned Prism perplexity: PTQ1_0 6.3796, PQ2_0 6.3811
  • Ryzen 9 7950X3D reference pp64/tg8: PQ2_0 7.06/5.69 tok/s, PTQ1_0 2.91/2.35 tok/s

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI assisted with reference-port adaptation, implementation, verification, optimization, and PR drafting. The submitter remains responsible for reviewing and validating all changes.

@github-actions

Copy link
Copy Markdown

Review Status

Current Status: ❌ PENDING
Approvals so far: none

Pending reviews: Needs 1 Management or Team Lead, and 1 more from Management, Team Lead, or Member.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@pratiknarola-t
pratiknarola-t force-pushed the qvac-25280-bonsai-core-cpu branch 2 times, most recently from f90c72d to 2afd46e Compare September 22, 2026 10:02

@amangupta-tether amangupta-tether left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found three issues in the Hadamard metadata and embedding paths.

Comment thread src/llama-model.cpp
std::vector<std::string> inverse_names;
ml.get_arr("prism.hadamard.inverse_weight_names", inverse_names, false);
for (const auto & name : inverse_names) {
// the graph applies the inverse only to the token-embedding lookup; any

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Handle tied output weights when the token embedding is folded. When output.weight is absent, Qwen3 and Qwen3.5 reuse token_embd.weight as the output matrix (see src/models/qwen35.cpp:44-52). This branch restores only the looked-up input rows; the output matmul still uses the folded matrix without a matching activation transform, so logits are incorrect for a tied model. Please reject this metadata combination or transform the output path as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread src/llama-graph.cpp Outdated
@@ -2325,6 +2377,17 @@ ggml_tensor * llm_graph_context::build_inp_embd(ggml_tensor * tok_embd) const {

cur = ggml_get_rows(ctx0, tok_embd, inp->tokens);

// Restore folded embedding rows to the primal basis.
if (hadamard_inverses) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Apply the inverse transform to MTP embedding lookups. Qwen3.5 MTP calls ggml_get_rows directly on model.tok_embd when its own embedding table is absent (src/models/qwen35.cpp:520-524; the same pattern appears in qwen35moe and qwen3next). That path skips this inverse, so MTP receives folded coordinates and the graph verifier can reject the lookup. Please apply the inverse on those paths or reject this combination.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread conversion/base.py
f"Hadamard tensor {record['name']!r} maps to {mapped!r}, which is not on a "
"verified Hadamard-aware matmul path"
)
weight_names.append(mapped)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Resolve Hadamard names after gate/up expert fusion. With --fuse-gate-up-exps, modify_tensors emits only blk.*.ffn_gate_up_exps.weight, but the manifest still records separate blk.*.ffn_gate_exps.weight and blk.*.ffn_up_exps.weight here. The loader then fails to find those named tensors. Please record the fused tensor name or reject the flag when a manifest requests these weights.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@yingying0906 yingying0906 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few issues on the Hadamard load path and the CPU kernels, details inline.

Comment thread src/llama-model.cpp
Comment thread ggml/src/ggml-cpu/ops.cpp
Comment thread conversion/base.py
Comment thread ggml/src/ggml-cpu/arch-fallback.h
Comment thread ggml/src/ggml-cpu/arch/x86/quants.c
Comment thread ggml/src/ggml-cpu/quants.c
Comment thread ggml/src/ggml-cpu/ggml-cpu.c
Comment thread src/llama-graph.cpp Outdated
Comment thread ggml/src/ggml-cpu/arch-fallback.h Outdated
Comment thread tools/quantize/quantize.cpp Outdated
@pratiknarola-t
pratiknarola-t force-pushed the qvac-25280-bonsai-core-cpu branch from 9866576 to 55cc12a Compare September 23, 2026 09:41
Comment thread src/llama-model.cpp
@pratiknarola-t
pratiknarola-t force-pushed the qvac-25280-bonsai-core-cpu branch from d288a5f to 268acd2 Compare September 23, 2026 16:33
@gianni-cor
gianni-cor merged commit e45fc65 into temp-10549 Sep 24, 2026
49 of 54 checks passed
gagallo7 pushed a commit to gagallo7/qvac-fabric-llm.cpp that referenced this pull request Sep 25, 2026
* QVAC-25280 ggml: add PQ2_0 and PTQ1_0 types

* QVAC-25280 llama: apply Bonsai Hadamard metadata

* QVAC-25280 tests: cover Bonsai backend operations

* QVAC-25280 conversion: narrow Hadamard manifest types

* QVAC-25280 conversion: satisfy nested function style

* tests : relax WebGPU signed FWHT tolerance

* ggml-cpu : optimize PTQ1_0 with x86 VNNI

* tests : cover wide FWHT kernels

* ggml-cpu : use ARM32 table lookup wrapper

* bonsai : address review feedback

* conversion : fix flake8 spacing

* convert : reject duplicate fused Hadamard records

* metal : reject unsupported core matmuls

* model : defer Hadamard init for split loads

* ggml : add AVX2 ternary dot products

(cherry picked from commit e45fc65)
@gianni-cor
gianni-cor deleted the qvac-25280-bonsai-core-cpu branch October 27, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants