Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/tbkern/phase9-four-row-vnni64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Phase 9: four-row VNNI64 decode tile

Phase 9 adds a separately opt-in single-token Q2_0 decode route:

```text
GGML_TBKERN_Q2_0_VNNI64_4R=1
```

The VNNI64 route previously rebuilt the identical 64-byte Q8 activation vector for each output row. The four-row tile constructs that vector once for each 64-value subgroup, then applies it to four independent packed-weight rows. Each output row retains the original `b=0,1` and group accumulation order, per-32 Q8 scales, and precomputed Q8-sum correction. A thread's final one to three rows use the unchanged Phase 8 route.

This is intentionally opt-in and does not change native Prism, Phase 7 VNNI, or Phase 8 VNNI64 selection. It requires AVX-512F and AVX-512VNNI. It changes no GGUF storage, repack allocation, or generic-ggml fallback behavior.

Validation gate: exact native/Phase 8/Phase 9 logits and token parity on the real 27B Q2_0 model, then matched CPU decode and PPL measurements. Retain it only if matched decode improvement exceeds run-to-run noise.
63 changes: 63 additions & 0 deletions docs/tbkern/phase9-prism-evidence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Phase 9: Prism 27B minimal-PR evidence

This document records the evidence for the opt-in four-row CPU decode path.
It is a decode measurement, not a claim about prompt processing or GPU
throughput.

## Scope

The minimal branch is based on Prism's prism branch at 7529fdaaf. It keeps only
the CPU backend integration, the Q2_0 cache packer, the parity comparator, and
this evidence. The native Prism Q2_0 path remains the default unless the
selector is set:

GGML_TBKERN_Q2_0_VNNI64_4R=1

## Configuration

- Model: Ternary-Bonsai-27B-Q2_0.gguf, 7,165,121,600 bytes,
SHA-256 868c11714cf8fe47f5ec9eeb2be0ab1a337112886f92ee0ede6b855c4fa31757.
- Host: Google Cloud C3 highmem-8, Intel Xeon Platinum 8481C, 4 physical
cores plus SMT siblings, one NUMA node, AVX-512F/VNNI/VBMI.
- Decode command: llama-bench -m MODEL -p 0 -n 16 -t 8 -ngl 0 -b 32 -ub 32.
- Baseline: unmodified Prism prism branch, same model, host, command, and
eight ggml threads, with no TBKERN selector.

## Correctness

llama-debug with prompt Hello, deterministic generation, and the same runtime
settings produced bit-identical files relative to the native path:

- logits SHA-256:
65d581397ae42288fe1115e7fa434589700cacd98edc67a750c0fba1765062f2
- generated-token SHA-256:
7a7748eacf971049271242b9d921628019d6c44698574e9301da9b8c88026381
- NMSE: 0
- top-1 mismatches: 0
- one-chunk PPL: 1.0645 +/- 0.03006 for both routes

## Matched decode triplicate

The recorded three-run matched set used the exact command above:

| Route | Run 1 | Run 2 | Run 3 |
| --- | ---: | ---: | ---: |
| Native Prism | 1.09 tok/s | 1.09 tok/s | 1.09 tok/s |
| Phase 9 four-row VNNI64 | 1.52 tok/s | 1.53 tok/s | 1.53 tok/s |

The Phase 9 route is approximately 40% faster for target decode on this host.
These are historical C3 measurements from the equivalent Phase 9 implementation
before this cleanup. This cleanup removes unused files and narrows the packing
header; it does not intentionally change the arithmetic or dispatch.

## Reproduction status

The current Windows workspace has no CMake, GCC, Clang, or llama-bench, so the
cleaned branch could not be rebuilt and rerun here. Before marking the PR ready
for review, rebuild this exact commit on the Linux C3 host and repeat native and
Phase 9 llama-bench three times, then rerun the deterministic parity check.

The route remains opt-in because the recorded perplexity workload was slower
even though the PPL value matched. Attention, norms, RoPE, softmax, GDN
recurrence/convolution, KV cache, sampling, scheduling, and GPU execution
remain in Prism's native runtime.
13 changes: 12 additions & 1 deletion ggml/src/ggml-cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Keep this at directory scope: CMAKE_CURRENT_FUNCTION_LIST_DIR was added
# after the project's CMake 3.14 minimum and is not available there.
set(TBKERN_ROOT "${CMAKE_SOURCE_DIR}/third_party/tbkern")

function(ggml_add_cpu_backend_features cpu_name arch)
# The feature detection code is compiled as a separate target so that
# it can be built without the architecture flags
Expand Down Expand Up @@ -56,7 +60,14 @@ function(ggml_add_cpu_backend_variant_impl tag_name)

target_compile_features(${GGML_CPU_NAME} PRIVATE c_std_11 cxx_std_17)
target_include_directories(${GGML_CPU_NAME} PRIVATE . ggml-cpu)

# Resolve from the project root inside this function to avoid caller-scope shadowing.
set(TBKERN_ROOT "${CMAKE_SOURCE_DIR}/third_party/tbkern")
# Q2_0 cache packing is opt-in. Scalar and AVX2 routes are selected by env;
# Prism's native Q2_0 vec-dot remains the fallback.
target_sources(${GGML_CPU_NAME} PRIVATE
"${TBKERN_ROOT}/src/q2_pack.c"
)
target_include_directories(${GGML_CPU_NAME} PRIVATE "${TBKERN_ROOT}/include")
if (APPLE AND GGML_ACCELERATE)
find_library(ACCELERATE_FRAMEWORK Accelerate)
if (ACCELERATE_FRAMEWORK)
Expand Down
Loading