Skip to content

hy4_flash: host W8A16 FP8 weight map, TP=1/2/4 partition, and Engram FP8 row format (slice 1 of #4795) - #4827

Merged
ashhart merged 3 commits into
ashhart:mainfrom
GrgaPalcic:pr/hy4-w8a16-host
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
GrgaPalcic:pr/hy4-w8a16-host

Conversation

@GrgaPalcic

Copy link
Copy Markdown
Contributor

What this changes

Adds Slice 1 (host-only) of official tencent/Hy4-flash-FP8 (W8A16) support inside zig/src/families/hy4_flash/ (Refs #4795):

  1. zig/src/families/hy4_flash/fp8_weights.zig (292 lines): W8A16 checkpoint tensor map built directly on config.Text, core.Checkpoint, and core.quant.fp8 — admits per-projection BF16 vs F8_E4M3 + BF16 weight_scale_inv [ceil(N/128), ceil(K/128)], stacked FP8 routed MoE experts, and Engram/indexer/iHC tensors while refusing leftover tensors (UnusedTensors), stray scale tensors beside BF16 weights (UnexpectedTensor), and unsupported weight dtypes (UnsupportedQuantization).
  2. zig/src/families/hy4_flash/fp8_partition.zig (225 lines): TP=1, TP=2, and TP=4 block-aligned (128-row FP8 block) partitioning and per-rank memory floor accounting (layerBytes, weightBytes, engramTableBytes, tokenBytes, ringBytes), verified byte-for-byte against the official config_fixture.json (158,445,453,396 B stored text weights, 126,721,231,872 B stored Engram BF16, 660,006,416 × 100 B packed FP8 Engram rows, 16,896 B/tok BF16 KV, 17,694,720 B sliding rings).
  3. zig/src/families/hy4_flash/engram_fp8.zig (135 lines): 100-byte FP8 Engram row format (96 e4m3fn codes via exact round-to-nearest-even from fp64 amax / 448.0 + f32 row scale, 4096-byte HY4ENGR1 header encode/parse/config validation).
  4. zig/src/families/hy4_flash/fp8_weights_test.zig (325 lines) wired into zig/src/families/hy4_flash/host_tests.zig: synthetic W8A16 mapping + refusal controls, release TP=1/2/4 partition & memory floor tests, exhaustive e4m3Rne verification across all 65,536 BF16 values + packRow/unpackRowF32 round-trip + HY4ENGR1 header/tiling checks across all 4 Engram layers (2, 12, 22, 32).

Remaining slices (held until this slice and its parent receipts settle): Slice 2 (PR 4B: CUDA kernels + core/contract/ + planted controls + sm_121 SUMMARY), Slice 3 (PR 4C: served W8A16 TP=2/TP=4 + DFly2 CUDA Graphs + BF16 KV receipts with serial token equality), Slice 4 (PR 4D: SigLIP2 --vision + 3D M-RoPE).

  • Issue: Refs #4795 (Slice 1 of 4; #4795 remains open for Slices 2–4).
  • Stacked on: main (141d6995a59e3e08685d0bbf4b741aebdd8bfe8c), 1 commit (e1b01462e).
  • atc overlap --json: run on 2026-11-24T02:29Z against origin/main (141d6995a) — changedFiles: 5, overlaps: [], conflict: "clean" (complete: false due to pullRequestsLimit / pullFilesUnavailable; gh pr list --search hy4_flash --state open also notes #4110 and #4566 touch zig/src/families/hy4_flash/host_tests.zig with independent test imports).

Checks on this head

  • Head commit: e1b01462e
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 on base (141d6995a), 165 on head (e1b01462e), 0 new findings (python3 tools/pr_check.py --base origin/main: 0 error(s), 1 warning(s) — advisory Unreleased changelog bullet).
  • Tests run, with the command and pass, fail and skip counts (Linux x86_64 host, Zig 0.17.0):
    • zig build -Dfixed-cpu test-hy4-flash-host --summary all — 31 passed, 0 failed, 0 skipped (28 baseline + 3 new test suites with negative controls)
    • zig build -Dfixed-cpu test --summary all — 12,489 passed, 0 failed, 89 skipped (822/822 steps)
    • zig build -Dfixed-cpu test-golden --summary all — 324/337 + 69/69 equal, 0 unexpected differences (5/5 steps)
    • zig fmt --check build.zig zig — pass (exit 0)
    • git diff --check — pass (exit 0)
  • CI: pending maintainer workflow approval.
  • Not run, and why: CUDA / Metal / HIP GPU kernel contracts and live serving benchmarks — host-only slice; no GPU kernels, runtime dispatch, or serving paths changed (covered in Slices 2 and 3). Windows and macOS host suites not run locally (covered by CI).

Receipt

n/a — host-only W8A16 checkpoint map, TP partition/memory floor, and Engram FP8 row codec + unit tests inside zig/src/families/hy4_flash/; no existing loader, kernel, or serving inference path is reached yet. Full GPU kernel contracts and served TP=2/TP=4 receipts with serial token equality follow in Slices 2 and 3.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @GrgaPalcic, for sending the first slice of the FP8 support.

The host tensor map, the TP partition and memory-floor arithmetic, and the Engram row codec are careful work. The refusal controls in the tests make it clear which bad checkpoints are turned away and why. We found nothing that needs a change from you. The new modules stay inside the test build, so this slice does not touch any served token, default or model load.

When the served slices follow, they will need the serial token-equality receipts next to the kernel and memory checks. We will check the CI result on our side.

  • Synthena

@eXsoR65

eXsoR65 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent host verification of head e1b01462e4 on a Linux x86_64 machine (no GPU), Zig 0.17.0:

  • zig build test-hy4-flash-host: 31/31 passed, including the three new tests — the W8A16 map (bf16/e4m3 admission + leftover/invalid-tensor refusal), TP=1/2/4 splits and memory floors vs the official Hy4-flash-FP8 byte totals, and the Engram 100-byte FP8 rows (e4m3fn RNE, fp64 scaling, HY4ENGR1 headers, layer tiling).
  • zig fmt --check (5 changed files) and git diff --check: clean.
  • lean_new.py vs the merge base: 165 head / 165 base, 0 new (all inherited); the new modules are 296/225/135/330 lines, under the 600 limit.

Host-side looks clean. Not run here: the full no-GPU suite (fuzz-cortheon etc. — CI covers it) and any GPU/real-model gates; this is host-only slice 1, so device bring-up in the later #4795 slices still needs its own evidence.

— eXsoR65's AI agent (DeepSeek Harness): eXsoR65 authorized this comment before posting.

@ashhart
ashhart merged commit 683c66f into ashhart:main Nov 24, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @GrgaPalcic. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants