Skip to content

lfm3 CUDA: serve the block FP8 export weight-only and the MLX 4-bit export as stored (stacked on #1508) - #1634

Open
jschmied wants to merge 29 commits into
ashhart:mainfrom
jschmied:lfm3-cuda-fp8
Open

jschmied wants to merge 29 commits into
ashhart:mainfrom
jschmied:lfm3-cuda-fp8

Conversation

@jschmied

@jschmied jschmied commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Current head f3d0fd7051: ashhart's rebase onto main 22d77f7839 (6d91aa5cb) plus one docs commit. That commit says the contract in docs/recipes/lfm3-cuda.md: weight-only, with the stored FP8 and NVFP4 weights served as loaded with bf16 inputs. The release's input scales are read and not applied, the dynamic FP8 input step is not applied, and activations stay bf16. The served receipts (FP8, MLX 4-bit, LFM2.5 against main) and the 8-stream cache timing ran on 6d91aa5cb, whose code this head keeps unchanged; they are in #1634 (comment).

  • The 8-stream FP8 decode loss is withdrawn: on 6d91aa5cb against 2b748e000 it is +0.10 % (noise floor 0.56 %), WITHIN NOISE. The "Don't land yet" rows below are history.
  • The cold-turn cost of the prompt cache is a separate result.
    • With the cache on, FP8's cold first token is 2.8 % slower than with --prompt-cache-gib 0 (5 of 5 rounds), and decode is about 5 % faster.
    • LFM2.5 on main shows the same pattern: cold first token -0.5 %, within its noise but 5 of 5; decode +4 to 5 %.
    • So it comes from the prompt cache's keep path, which main already has, not from this PR's code. It is not attributed to any one base commit.

The sections below describe earlier heads.

Stacked on #1508 (head 0fa0fa122); every commit after it is this PR's own. The head is 82cb493d8. Rebased onto
#1508 after its rebase onto main e7e24243d: our ref64.py commit 4ab6a44e6 dropped out (main has the same file
byte for byte, from #1696), and so did the tools part of the docs commit.

What

LFM3-1.7B's other two text exports on CUDA, beside #1508's NVFP4:

  • Admission (503883283): LiquidAI/LFM3-1.7B-FP8 (revision 243955da, compressed-tensors FP8_BLOCK). The
    recipe, the ignore list and all 402 tensors are checked as published.
  • Refused by name where it isn't served (503883283, 042028b62): servedOn refuses fp8_block with
    Lfm3Fp8BlockNotOnMetal or Lfm3Fp8BlockNotOnXpu, beside lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508's two NVFP4 refusals, and servedProblem words
    all four. Metal's and XPU's opens already ask servedOn (lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508), before any weight is read and, on XPU, before
    the Level Zero driver. No new path: the FP8 case is one more arm of the same switch.
  • Served (7c0fa775e, 8faf23426):
    • FP8 weight-only: the FFN and q/k/v/o on the block-FP8 lane, activations bf16; the export's dynamic FP8
      input quantization is not applied. The bf16 attention gate is a projection of its own.
    • LiquidAI/LFM3-1.7B-MLX-4bit (revision d0ca73dc) as stored: every projection and the tied head as
      affine-4 tiles, prompt chunks on the affine prompt GEMM, decode rows on the verify tiles.
    • The 6- and 8-bit MLX exports and VL are refused by name. Each load line says what is served.
  • Docs (d986410d1): the recipe's table of the three exports. The float64 receipts are main's
    tools/lfm3/REF64.md.
  • Receipt (82cb493d8): docs/receipts/lfm-cuda-sass-fad7e142/ regenerated against main e7e24243d.

No kernel changes, and no file outside families/lfm3, the XPU refusal test and the docs. Liquid's shared backend
and LFM2.5 are #1508's, unchanged.

Verification (GB10, sm_121, real weights, on this head)

Speed (GB10)

A-B-B-A, 4 servers an arm, the same 6 cold chats (10.4k tokens) on every server, paired medians.

this head reference paired
FP8 decode, 1 / 4 / 8 streams (tok/s) 254.9 / 359.1 / 584.8 255.3 / 358.9 / 590.8 (3551fd822)
FP8 cold chat turn 1.183 s 1.188 s -0.7 ms, 10 of 24 slower
MLX 4-bit decode, 1 / 4 / 8 196.8 / 676.0 / 1067.4 197.2 / 678.1 / 1067.9 (3551fd822)
MLX 4-bit cold chat turn 0.642 s 0.644 s +0.1 ms, 12 of 24 slower
NVFP4 decode, 1 / 4 / 8 120.2 / 420.4 / 750.8 120.3 / 421.0 / 750.6 (#1508 0fa0fa122)
NVFP4 cold chat turn 0.825 s 0.824 s +0.3 ms, 13 of 24 slower
LFM2.5 decode, 1 / 4 / 8 173.7 / 192.6 / 281.2 174.5 / 192.4 / 281.6 (main e7e24243d)
LFM2.5 cold chat turn, 3 runs main, main, #1508 +7.0 ms 18/24, +7.2 ms 13/24, +5.1 ms 16/24

Two rows are paired losses, said plainly. Don't land yet until both are explained:

Proposed CHANGELOG line

- LFM3-1.7B FP8 (block, weight-only) and MLX 4-bit (as stored) served on CUDA; Metal and XPU refuse the FP8 export by name (#1634, after #1508)

Licence

The weights are under Liquid AI's LFM Open License v1.0 (license: other, lfm1.0), as the NVFP4 and MLX exports
are.

@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, and thanks for splitting this out so cleanly. Reusing the affine-4 tiles for the MLX export as stored, and the float64 receipts listing every miss for both exports, are what we were hoping for.

This one waits on #1508, which waits on #1492, #1503 and #1513, so we can't run it yet. When you rebase the stack onto main, note that main has since moved the shared attention helpers (texp, ldmatrix, the cp.async commit and wait) into common/qmm_frag.cuh and common/cp_async.cuh. prefill_attention.cu now conflicts with the move into prefill_attention.cuh, and the SASS receipt will need regenerating after that.

One small thing in the new commits: in lfm3/cuda_weights.zig the load log if (!fp8) ... "LFM3 NVFP4 on CUDA serves weight-only" also prints for the MLX 4-bit export, which is served as stored. Could it say so for MLX, or print nothing?

Once it's on main, we'll serve both exports on a GB10: drafted against plain, concurrent against solo, prompts across the sliding window, and resumed against fresh. If you have time before then, those same checks for FP8 and MLX 4-bit (you listed them as not run) would speed things up.

@jschmied

Copy link
Copy Markdown
Contributor Author

One commit added on top, 4ab6a44e6: tools/lfm3/ref64.py now also runs on numpy without torch.

  • Why: the Intel GPU work (LFM3-1.7B on the XPU backend (Intel GPUs, Iris Xe first) #1666) checks its LFM3 forward against these dumps on a machine without torch.
  • The numpy path: MLX affine is dequantized exactly. NVFP4 and FP8 still need torch and say so.
  • New in both paths: --bf16-points (the storage points of a bf16 engine) and dump / check subcommands.
  • The torch path is unchanged: on the GB10, the old and new script give byte-identical output for all four receipt runs (MLX, FP8, NVFP4, NVFP4 --bf16). The numpy path matches torch exactly on MLX.
  • REF64.md gains a short "Without torch" section.

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart, fixed in 3551fd822. The MLX 4-bit export now logs "LFM3 MLX 4-bit on CUDA serves the export as stored: affine-4 weights, bf16 activations". The NVFP4 weight-only line prints for NVFP4 only. Lean, test and CI are green.

On the rebase: noted that main moved the shared attention helpers into common/qmm_frag.cuh and common/cp_async.cuh. I will rebase the stack and regenerate the SASS receipt once #1508 is ready, or earlier if you want it.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, the load log is right now: FP8, MLX 4-bit and NVFP4 each say what's served, and the MLX line says it's served as stored. The numpy path for ref64.py is the same file #1696 carries, so whichever lands first keeps it.

This still waits on #1508, and that's on us: #1508 needs #1492 and #1503 first, and we owe their runs. When you rebase, please regenerate the SASS receipt after the move into common/qmm_frag.cuh and common/cp_async.cuh. Once it's on main, we'll serve both exports on a GB10: drafted against plain, concurrent against solo, prompts across the sliding window, and resumed against fresh. If you run any of those for FP8 or MLX 4-bit first, paste them here.

@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

/atc exchange 79fc1ac2936caca2ede559f5aa3603fb08bf85d2ae72e9b9534e31a700a86b66

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

(Optional: nothing new from the author since our last note.)

Thanks @jschmied, a quick status note. Nothing is needed on this PR yet. #1492 is on main now, so the stack below this
is down to #1503 and #1508. #1503 has one small ask on its own thread, and #1508 follows it. When #1508 rebases, its
pages switch (zig/src/families/liquid/cuda_native.zig:57-58, read with getenv and on for anything but 0) will need
to go through platform/environment.zig like the other settings.

When you rebase this after #1508: tools/lfm3/ref64.py and REF64.md are already on main byte for byte (they came in with
#1696), so 4ab6a44e6 should drop out. Please regenerate the SASS receipt against that day's main, and add a CHANGELOG
line under ## Unreleased with "(#1634, after #1508)". Then we serve both exports on a GB10: drafted against plain,
concurrent against solo, prompts across the sliding window, and resumed against fresh. Main is frozen for a release
right now, so the stack moves once that's out.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, a status note. Nothing is needed on this PR yet: #1503 is queued to land, and #1508 follows it with the rebase you've taken on. We read this head against today's main so the rebase holds no surprises:

  1. tools/lfm3/ref64.py and tools/lfm3/REF64.md on main are byte-identical to this branch's, so 4ab6a44e6 drops out.
  2. servedOn refuses fp8_block only on Metal (zig/src/families/lfm3/config.zig:377). Once lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508 gives Backend its .xpu case for the XPU LFM3 path, please refuse the FP8 export there by name too, with a test through the XPU open, as we asked for NVFP4 on lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508.
  3. As before: regenerate the SASS receipt in docs/receipts/lfm-cuda-sass-fad7e142/ against that day's main, and add a CHANGELOG line under ## Unreleased with "(lfm3 CUDA: serve the block FP8 export weight-only and the MLX 4-bit export as stored (stacked on #1508) #1634, after lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508)".

Then we serve both exports on a GB10: drafted against plain, concurrent against solo, prompts across the sliding window, and resumed against fresh.

  • Synthena (Ash's Agent)

jschmied and others added 29 commits November 25, 2026 08:59
…KV head

prefill_attention.cu instantiates pattn_kernel<128, 8, 4, 8>: Nemotron's <128, 8, 8, 8> needs eight query heads
a KV head, and LFM3's full-attention layers have four (16 over 4). Its launch record is measured on nvcc 13.0 and
13.2 from every SM's image (206 registers on sm_80/86/89, 231 on sm_120/121, no static shared memory).
sassid on sm_80/86/89/120/121, both toolkits: 0 functions changed, 5 added.
LiquidAI/LFM3-1.7B-NVFP4 stores only the FFN as NVFP4: w1, w3 and w2 as e2m1 codes in groups of 16 with e4m3
block scales, an fp32 tensor scale and a static input scale. Every mixer projection, the embedding and the tied
head are bf16, and the depthwise conv kernel is [channels, 1, taps].

- config.zig reads `quantization_config` with quant_method "modelopt" as Scheme.modelopt_nvfp4: quant_algo NVFP4,
  one Linear group of static FP4 g16 weights and inputs, and an ignore list that is exactly the head, the
  embedding and every layer's mixer. Anything else is UnsupportedLfm3Quantization. MLX configs parse as before
  (Scheme.mlx_affine), so a decoder that reads one scheme can refuse the other by name.
- weights.zig's schema takes that layout for the bare namespace.

tf-lfm3-check passes the published header (b30025bb): 502 text tensors, 1,829,689,408 bytes. The MLX-4bit header
still passes (594 tensors, 973,008,384 bytes). Host tests 26/26.
…tract

lfm3.cu instantiates liquid_conv<7,0> and liquid_commit<7,0>; contract_controls.cu adds their <7,1> controls.
contract_lfm2_moe.zig's Conv and Commit take the tap count; contract_lfm3.zig checks the served 7-tap shapes.
Records are identical on nvcc 13.0 and 13.2. contract_limits.zig now lists the lfm2_moe and lfm3 images.
Conv layers keep a 6-row state per slot; full attention runs on kv_pool pages with partial RoPE (32 of 64 pairs);
sliding attention runs on a 1280-row per-slot ring through the shared window kernels at window 256.
FFN w1|w3 is one FP4 lane weight (shared weight_scale_2), w2 FP4; q|k|v|gate, o, conv and the tied head are bf16.
Adds --parallel lanes, drafted rows, and a copy-based prompt cache (conv states, rings, pages [0, at)).
…and LFM3 on CUDA

zig/src/families/liquid/ holds what the two Liquid families shared as copies: the lane backend (cuda_lanes.zig),
the kept states in the prompt cache's preallocated pages and the walk over a slot's state (cuda_snap.zig), and the
native glue: open, admission, the pool and the prompt-cache hooks (cuda_native.zig). Each is generic over the
family's model and forward, as liquid_conv.cuh is over the conv's taps. A model names its fixed regions (LFM2.5:
the conv states; LFM3: the conv states and every sliding layer's rings) and its paged layers; each family keeps
its config, weights, forward, refusals and model. lfm2_moe's backend, snap and native are now thin instances, and
lfm3's no longer copy them.
…4, with a control

LFM3's full-attention prompt rows (16 query heads over 4 of 128) join the head-64 paged attention's gates, held head by head to contract_attn's float64 bound over shuffled 512-key pages; tf_ctl_pattn_128 reads its values from the neighbouring 8 dims.
config.servedOn(config, backend) refuses modelopt_nvfp4 on Metal with Lfm3ModeloptNvfp4NotOnMetal; CUDA serves it, and both serve the MLX layouts. Metal's LFM3 open (ashhart#1514) calls it.
The export's static FP4 input scales are read, as the admission requires, and not applied: activations stay bf16. The load logs it and the loader's comment says so.
config.Backend gains .xpu; servedOn refuses modelopt_nvfp4 with Lfm3ModeloptNvfp4NotOnMetal or
Lfm3ModeloptNvfp4NotOnXpu, and servedProblem words both for the problem line. Metal's open (native/lfm3.zig)
calls it right after config.json, before any weight is read. XPU's openFamily asks the family's refuse() before
the Level Zero driver opens, and the engine's init checks again before its stream. Tests through each real open:
native/lfm3.zig (test-native, macOS) and draft_sources_xpu_test.zig (test-lfm3-xpu-refusal-host, any host).
contract_controls.cu is back at main's 600 lines: the 7-tap conv and commit controls (tf_ctl_liquid_conv_7,
tf_ctl_liquid_commit_7) and the head-128 prompt rows' tf_ctl_pattn_128 move to contract_lfm3_controls.cuh, which
contract_controls_set.cu includes beside the dense decoders' controls, as one image as before. tf_ctl_pattn_128
names main's P256, IDS and PN constants like tf_ctl_pattn_64.
…base

docs/receipts/lfm-cuda-sass-fad7e142/ now compares today's main (shared CUDA headers, ashhart#1492 and ashhart#1503 on it) with
the rebased head cde8257 on sm_80/86/89/120/121: prefill_attention 70 of 70 functions identical (+5,
pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls), nvcc 13.0 and 13.2.
nemotron_attention is no longer reached. sass.tsv has every function's SASS sha256 on both sides.
docs/receipts/lfm-cuda-sass-fad7e142/ now compares main af9777b with the merge head 2fc30dd on
sm_80/86/89/120/121, nvcc 13.0 and 13.2 (-j 1): prefill_attention 70 of 70 functions identical (+5,
pattn_kernel<128, 8, 4, 8>), contract_controls 450 of 450 (+15, LFM3's three controls). Every digest equals the
receipt before it; only the header names the new trees.
…ckend

Carry main’s cutPoints planning, cut-point tap gating, and LFM2.5 request-start tests through the generic Liquid backend. LFM3 keeps its reviewed mark-only chunking because its sliding rings cannot tap within a chunk.
Keep one-line public comments, retain the detailed LFM3 note in gradient-serving.tsv, and keep the Metal registry at its existing 600-line cap. No execution behavior changes.
Replace the fixed eight-entry cache with the build allocator's list. The host build defines more than eight target/runtime combinations; reuse remains keyed by CUDA module and optimization mode.
The CUDA request-start device runner still named the pre-refactor Lfm declaration. Use the retained B.Liquid type exported by the new backend; its model, snapshots and test operations are unchanged.
ashhart#1508's 7-tap conv commit adds controls to zig/kernels/cuda/contract_controls.cu and re-pins it; a later
commit moves them into contract_lfm3_controls.cuh, which leaves the file byte for byte main's, but its
gradient-serving row kept the interim hash. The row now has main's hash again; its note is main's.
LiquidAI/LFM3-1.7B-FP8 (compressed-tensors, FP8_BLOCK): e4m3 weights with a bf16
scale per 128 x 128 block on the FFN and q/k/v/o, dynamic FP8 inputs in groups of
128; the convs, the attention gate, the embedding and the head stay bf16. The
recipe, the ignore list and the 402 tensors are checked as published. Metal
refuses it by name (Lfm3Fp8BlockNotOnMetal).
…as stored

- FP8: the FFN and q/k/v/o on the block-FP8 lane, activations bf16 (the
  export's dynamic input quantization is not applied). The bf16 attention gate
  is a projection of its own, written into the merge's sums buffer after the
  attention.
- MLX 4-bit g64: every projection and the tied head as affine-4 tiles, prompt
  chunks on the affine prompt GEMM, decode rows on the verify tiles over their
  64-value sums; the embedding rows read the same codes. Wrapped names
  (language_model.model.*) come from the admission. 6- and 8-bit MLX and VL
  are refused by name.
The receipts are main's tools/lfm3/REF64.md (ref64.py dequantizes block FP8
exactly, from ashhart#1696). FP8 agrees on 824 of 829 prompt rows and 128 of 128 reply
rows, MLX 4-bit on 825 and 128; every miss is listed with its float64 margin
(0.004 to 0.085). Concurrent == solo at 4 and 8 streams.
…gh the open

servedOn's .xpu case (from ashhart#1508) now names fp8_block too:
Lfm3Fp8BlockNotOnXpu, beside Lfm3ModeloptNvfp4NotOnXpu. The XPU open asks
before the Level Zero driver, as it does for NVFP4, and the engine's init asks
again before its stream. The test writes only the export's config.json and opens
it through xpu.zig; with the check removed it fails at the driver instead
(LoaderUnavailable).
…1634

ashhart#1634 changes nothing under zig/kernels, so main against its code head 042028b
reaches ashhart#1508's functions only: prefill_attention 70 of 70 identical (+5),
contract_controls 450 of 450 (+15), nvcc 13.0 and 13.2, sm_80/86/89/120/121.

This branch has not been deployed

No deployments
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