Skip to content

cuda/fp8: pack a rank's share of block-FP8 scales from inside a 128 block - #1024

Closed
Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/fp4local-packscales
Closed

Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/fp4local-packscales

Conversation

@Bizuayeu

Copy link
Copy Markdown
Contributor

What this changes

Adds fp8.packScalesAt, which packs a rank's share of block-FP8 scales for fp8g from any row and input origin, so a share may start inside a 128 block, as TP=3's shares of GLM-5.3-Flash's 2048-row shared expert do at rows 704 and 1408 (#1015). packScales now calls it with origins 0, and core/quant/fp8.zig's blockScales reads ModelOpt's [Rb, 1, Cb, 1] scales as [Rb, Cb].

  • @jschmied: fp8g's scale layout is yours (Zig CUDA ports: shared layers below lanes.Backend, and one place to coordinate them #548); this adds a variant beside packScales and keeps its signature.
  • packScalesAt takes the share's row and input origins and the whole matrix's size, and reads each block's scale from the whole matrix's scales.
  • packScales's output is the same for k a multiple of 128, and every caller has such a k: the old size check allowed no other.
  • blockScales gives FP8_PB_WO's scales the [Rb, Cb] shape that reference takes, and refuses any other rank-4 shape.

Receipt

  • Environment: TensorFold 9ccf4727 plus this commit, Zig 0.17.0. Host tests on x86_64 Linux, on an LF tree from git archive.
  • Exactness: n/a. Only host-side packing changes, and no family calls packScalesAt yet.
  • Decode speed before and after: n/a, for the same reason.
  • Prompt speed before and after: n/a, for the same reason.
  • Tests run:
    • zig build test: 84/84 steps, 1378/1385 tests passed, 7 skipped.
    • zig build test-kernel-contract, test-golden, fuzz-cortheon and a plain zig build: succeeded.
    • lean: 0 new problems (517 on main). git diff --check: clean.
    • The new tests:
      • TP=3's three shares (rows 0, 704 and 1408; 704, 704 and 640 rows) of a 2048 × 4096 matrix by output rows, and of a 4096 × 2048 matrix by inputs, each equal to the same tiles of the whole matrix's pack;
      • blockScales on a 2 × 130 matrix with two column blocks, against the reference's values, and its refusal of a [1, 2, 1, 1] scale.
  • Not run: tf-cuda-test's fp8 repack check against the Python layout, which needs a GPU. For k a multiple of 128, packScales reads the same scale for each tile as before.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (Host packing only; no serving code changes.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (No served path changes.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (The packed scales are the stored values, moved; no arithmetic.)
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No GPU kernel changes.)
  • Prompt processing is no slower than the last release. (No served path changes.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (Host tests on x86_64 Linux; the GPU repack check not run.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (Before it, a share starting at row 704 reads the scales of a block starting at row 0 of its own rows.)
  • Comments and docstrings are one line. No measurements or history in the source. (lean: 0 new problems.)
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…lock scales, from origins inside a 128 block (TP=3's 704); ModelOpt's [Rb,1,Cb,1] scales read as [Rb,Cb]
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu for covering the TP=3 shares starting at rows 0, 704 and 1408, and @jschmied for the fp8g scale layout. We're taking this host foundation for 1.1.1. Review confirms that global row/input origins select the whole matrix's correct 128-block scales, while zero-origin packing retains the old layout. Independent controls fail when either origin is dropped, and the rank-4 scale view preserves its bytes. The GPU repack comparison against the independent layout is still owed when the new path is used, alongside #1015's per-rank row/column-slice and model checks. This does not by itself enable FP4-Local serving.

Posted by Ash's AI Assistant Synthena

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

Noted. We'll take the GPU repack comparison when GLM's loader packs FP4-Local's block-FP8 projections (MLA and the shared experts, whose TP=3 shares start inside a 128 block) through this path: every rank's uploaded scales against the independent layout at TP=2 and TP=3, posted on #1015 with the row and column slice checks.

@ashhart ashhart mentioned this pull request Oct 18, 2026
ashhart pushed a commit that referenced this pull request Oct 19, 2026
Credit: @Bizuayeu for the implementation and TP=3 origin controls.
Credit: @jschmied for the original fp8g scale layout (#548).
Keep existing zero-origin packing and add the ModelOpt rank-4 scale view.

Co-authored-by: Jürgen Schmied <[email protected]>
@ashhart

ashhart commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu for #1024 and @jschmied for the fp8g layout. 1.1.1 includes global row/input-origin scale packing for rank shares that begin inside a block, plus the ModelOpt rank-4 scale view. Both split orientations and the zero-origin legacy layout are retained. GPU repacking and #1015's per-rank/model checks remain owed when consumers use the new path. This host foundation does not announce complete FP4-Local support.

Posted by Ash's AI Assistant Synthena

@ashhart ashhart closed this Oct 19, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
Credit: @Bizuayeu for the implementation and TP=3 origin controls.
Credit: @jschmied for the original fp8g scale layout (ashhart#548).
Keep existing zero-origin packing and add the ModelOpt rank-4 scale view.

Co-authored-by: Jürgen Schmied <[email protected]>
@Bizuayeu
Bizuayeu deleted the pr/fp4local-packscales branch October 25, 2026 07:27
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