Skip to content

Admit E8M0 block scales to the order-1 scale coder (includes the length-prefix fix) - #4

Merged
khwstolle merged 5 commits into
masterfrom
feat/order1-e8m0-scales
Oct 24, 2026
Merged

khwstolle merged 5 commits into
masterfrom
feat/order1-e8m0-scales

Conversation

@khwstolle

Copy link
Copy Markdown
Owner

Two commits.

1. Length-prefix limit shared by encoders and decoders (fix(core), 090b9f9)

rANS, tANS, and the arithmetic coders refused to decode any plane declaring more than 1 GiB, while their encoders wrote such planes without checking. A 2.1 GB BF16 embedding (128256 × 8192) encoded and then failed to decode with implausible orig_len. Both public releases (1.0.0, 1.0.1) carry this.

  • One rule in codecs::length_prefix decides which declared lengths are accepted; encoders and decoders both apply it.
  • Up to 1 GiB, any ratio is accepted, as before. Above that, the encoded body must be at least 1/64 of the declared length, which still bounds what a short or corrupted payload can make the decoder allocate.
  • rANS and tANS store a plane raw when the rule rejects it. The arithmetic coders, which have no raw form, return an encode error instead of an undecodable payload.
  • The unchecked as u32 casts in the rANS and Huffman encoders no longer wrap planes over 4 GiB.
  • Encoder output is unchanged for every plane up to 1 GiB.

2. E8M0 scales reach Order1ScaleAC (feat(core), d6dec5b)

The coder accepted only FP8 scale planes, on the assumption that MXFP4's E8M0 block scales have no row structure. Measured on gpt-oss-20b's 597M E8M0 scales: 1.20 bits conditioned on the previous scale in the row, against 1.89 bits unconditioned. E8M0 Scale and GlobalScale planes now reach the coder, and the per-plane trial encode still keeps the smallest codec. The README dtype table is updated.

Synthetic check: on an 8.3 MB row-correlated E8M0 plane, the container is 1.54 MB with the default menu against 2.41 MB with the generic coders only, and decodes byte-exact.

Known issue, not addressed here: on a small plane (46 KB) the default menu picked Order1ScaleAC although its container came out larger (31,350 B against 16,955 B with the generic coders). The trial encode appears not to charge shared-state table bytes to the plane.

Tests

  • cargo test --workspace: 916 passed, 2 ignored (the two above-1 GiB round trips, run separately in release mode and passing).
  • cargo clippy -p ptwm-core --all-targets -D warnings: clean.

rANS, tANS, and the arithmetic coders refused to decode any plane
declaring more than 1 GiB, while their encoders wrote such planes
without checking. A 2.1 GB BF16 embedding (128256 x 8192) therefore
encoded and then failed to decode with "implausible orig_len".

One rule in codecs::length_prefix now decides which declared lengths
are accepted, and both sides apply it. Up to 1 GiB any ratio is
accepted, as before. Above that, the encoded body must be at least
1/64 of the declared length, which still bounds what a short or
corrupted payload can make the decoder allocate. rANS and tANS store a
plane raw when the rule rejects it; the arithmetic coders, which have
no raw form, return an encode error instead of an undecodable payload.

The rANS and Huffman encoders also cast the plane length to u32
unchecked, so a plane over 4 GiB got a wrapped prefix. They now store
such planes raw.

Encoder output is unchanged for every plane up to 1 GiB.
Order1ScaleAC accepted only FP8 scale planes, on the assumption that
MXFP4's E8M0 block scales have no row structure. They do: across
gpt-oss-20b's 597M E8M0 scales the entropy conditioned on the previous
scale in the row is 1.20 bits, against 1.89 bits unconditioned. E8M0
Scale and GlobalScale planes now reach the coder, and the per-plane
trial encode still keeps whichever codec is smallest.
Copilot AI balanced review requested due to automatic review settings October 23, 2026 13:17

Copilot 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The two E8M0 scale-block tests asserted the old FP8-only gate. With
E8M0 admitted, the effective menu includes Order1ScaleAC, which wins
the synthetic NVFP4 fixture plane.
The pinned ruff flags both (SIM102, I001).
The Rust test, coverage, and lint jobs build pyo3-ffi against the
runner default Python, now 3.14, which PyO3 0.24 does not support.
@khwstolle
khwstolle merged commit 4ffec99 into master Oct 24, 2026
9 checks passed
@khwstolle
khwstolle deleted the feat/order1-e8m0-scales branch October 24, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants