mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #464] [CLOSED] ple: read the n-gram table at full BF16 precision #2653
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2653
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/464
Author: @constantindjonkam
Created: 10/2/2026
Status: ❌ Closed
Base:
main← Head:pr/3-ple-bf16📝 Commits (1)
df4c218ple: read the n-gram table at full BF16 precision📊 Changes
8 files changed (+221 additions, -48 deletions)
View changed files
📝
CMakeLists.txt(+1 -1)📝
include/strata/artifact/gguf_reader.hpp(+1 -1)📝
include/strata/kernels/ngram.hpp(+17 -5)📝
src/kernels/ngram.cpp(+31 -7)📝
src/kernels/ple_fp8_parity.cpp(+1 -1)📝
src/ngram/ple_reader_test.cpp(+110 -0)📝
src/program/generate.cpp(+1 -1)📝
tools/ple_table_pack.py(+59 -32)📄 Description
What
Stop reading the PLE n-gram table from a lossy quantization of it.
The table reaches the engine as IQ4_NL - ISTA-DASLab's shard 2 - which is about 8% off per row
against the checkpoint's own values. The checkpoint ships the table in F8_E4M3 with a single
weight_scale, at 2.66%, and in BF16, which is the source of record.This PR adds a packer (
tools/ple_table_pack.py, renamed fromple_fp8_pack.py) that copies whicheverform the checkpoint has, byte for byte - nothing is decoded, rounded or re-quantized - and a reader for
the BF16 form.
Thank you for the measurement on 0.1.37 / RTX 5090, and for building the BF16 table with this PR's tool
against OrcaRouter's checkpoint. Two things from it that this PR now leans on:
table at another cache size giving 0.00080 - i.e. below run-to-run noise - for 51 GB against 102 GB.
That is the right call for your fork and the reason this PR leads with the packer rather than with
BF16.
that only 6% of the checkpoint's BF16 values have the low 4 mantissa bits zero shows the FP8 table is
a real re-quantization, not an upcast - which is exactly why the packer copies bytes instead of casting.
What the review did not measure, and what we measured instead
Your comparison is FP8 against BF16. The table a stock install actually runs is IQ4_NL, three times
further out again, so that is the gap worth closing. First-window logits, same engine, same prompt,
fixed
--expert-cache 8000, so the table is the only variable:Against your FP8 figures (0.019 at 2K, 0.0011 at 32K) that is 8-200x larger, and above your
reference point for the whole experts pack against an all-Q8_0 model (KL 0.0069 at 32K) by 20-30x.
Two honest limits: the greedy top token is unchanged in every case - the deviation shows over
sequences, not at one position - and these are single-position logits, not the answer-level KL you
measured with a reference model's teacher-forced answers.
The reader
BF16 rows are 320 B rather than 90, and widening is exact: a bfloat16 is the top half of a float32, so
bf16_dequant_rowis a shift and a copy, little-endian bytes assembled explicitly so it does not dependon host endianness. No scale is read and no metadata is trusted - the values carry themselves.
The direct reader already takes the table's own row size, so BF16 reads unbuffered like IQ4_NL and FP8
rather than falling back to the mapped path Q5_0 needs. (The comment claiming fixed 90-byte rows was
stale from before FP8.)
Tested in
ple_reader_test: widening is exact over the patterns a lossy path breaks on - subnormals,+/-inf, both NaN encodings - and a synthetic BF16 GGUF reads back identically through Direct and Mmap.
Both were mutation-checked: widening by
>>instead of<<, and a 160 B row width, each fail the test.Cost
None measurable. Same sweep, same card, same config, 256 output tokens per cell, cold:
Within +/-2.3% across a 25x range, sign flipping - noise. 16 rows/token is dwarfed by streaming 47 GB
of experts over PCIe. That matches your +1.8% at 32K on the 5090.
Note on 0.1.38
Rebased onto 0.1.38, which moved this code twice:
max_inflight64 -> 256, and the Q5_0--ple-io directrefusal removed withrow_bytesgeneralised (#296). Both are kept as upstream has them;the BF16 checks now run inside upstream's parameterised
selftest(dir, rb). Mutation-checked after therebase:
<< 16->>> 8fails the selftest on the first subnormal, so the BF16 coverage is live ratherthan merely present.
Which to use
cost/benefit for most installs. Build it from the FP8 checkpoint with this PR's packer.
Disk is the real cost: the table is streamed (
--ple-io direct, never resident; the row cache is ~90 MBat the default), so this is disk and not RAM, but 51 GB or 102 GB has to exist.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.