Skip to content

lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) - #1508

Open
jschmied wants to merge 21 commits into
ashhart:mainfrom
jschmied:lfm3-cuda-nvfp4
Open

jschmied wants to merge 21 commits into
ashhart:mainfrom
jschmied:lfm3-cuda-nvfp4

Conversation

@jschmied

@jschmied jschmied commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Current head 43b6d46b78: ashhart's rebase onto main edecac9567 (409dc2b478) plus one docs commit. That commit says the contract in docs/recipes/lfm3-cuda.md: weight-only, the stored NVFP4 weights served as loaded with bf16 inputs, and the release's input scales read and not applied; activations stay bf16. The final-head receipts (host, x86, SASS, contract with controls, full-reply LFM3 and LFM2.5 comparisons, request-start runner, paired timing) were run on 409dc2b478, whose code this head keeps unchanged; they are in #1508 (comment). The sections below describe earlier heads.

Part of #1491 (CUDA side). Rebased onto main b4f1bf263 after #1503 landed (#2989), then merged with main af9777b49
(2fc30ddf1). #1492, #1503 and #1513 are on main, so every commit here is this PR's own; the head is a9205a9ee. The
FP8 and MLX 4-bit exports are #1634, stacked on this one. VL comes after that.

What

LFM3-1.7B text served natively on CUDA from LiquidAI/LFM3-1.7B-NVFP4 (ModelOpt NVFP4, revision b30025bb). It is
weight-only: the FFN's FP4 weights are used as stored, and every activation stays bf16. The export's static FP4
input scales are read, because the admission requires them, but not applied. The load says so in its log, and the
loader says so in a comment.

  • Admission (a4582a305): the ModelOpt NVFP4 scheme in the shared lfm3/config.zig and weights.zig, with the
    export's exact exclusion list. Only the FFN (w1, w3, w2) is FP4; conv, attention, gate, embedding and head are bf16.
    The MLX layouts are unchanged.
  • Refused by name where it isn't served (bea9088af, 2a079deb8): config.servedOn(config, backend) returns
    Lfm3ModeloptNvfp4NotOnMetal or Lfm3ModeloptNvfp4NotOnXpu. Metal's open calls it right after config.json.
    XPU's open asks before the Level Zero driver, and the engine's init asks again before its stream. Both have a test
    through the real open. The XPU one is skipped on Windows (zig/build/xpu.zig:343-348, f2fdfcab3), because the
    real open reaches POSIX open and std.DynLib.
  • Kernels:
    • 02e245fcb: the 7-tap instances of liquid_conv.cuh (tf_liquid_conv_7 / tf_liquid_commit_7), under the
      contract with controls;
    • 450d080e6: prefill_attention's template at head dim 128 with 4 query heads a KV head.
  • Family (07637784e):
    • FP4 FFN on TF's NVFP4 linears;
    • q|k|v|gate as one bf16 lane weight, and a bf16 copy of the tied embedding as the head;
    • 6 full-attention layers in pool pages, with partial RoPE and Nemotron's head-128 chunk/merge for decode;
    • 5 sliding layers (window 256) as a per-slot ring on the shared window-attention kernels;
    • the per-head gate (act_rows.headGate) and the shared norms.
  • One Liquid backend (5e87d102d): zig/src/families/liquid/ holds the lane backend, the kept-state walk and the
    native glue (open, admission, pool, prompt-cache hooks), generic over the family's model and forward.
    • LFM2.5 and LFM3 each keep only their config, weights, forward, model and refusals.
    • It carries LFM2.5-24B-A2B on CUDA: one helper for every prompt-stream write a keep reads, and a test that fails if a writer skips the wait #2989 for both: the keeps' own stream, fenced() on the five writes (with main's source test, now over
      cuda_lanes.zig), the pages switch through the environment table, and "reserved at load".
    • TENSORFOLD_LFM3_KV_PAGES has its .flag row, a profile row and a refusal test, like LFM2's.
    • A model names its fixed regions (LFM2.5: the conv states; LFM3: the conv states and each sliding layer's K and V
      rings) and its paged layers.
    • LFM3 still ends a chunk at a mark, because the rest of the chunk would overwrite its sliding rings.
  • Contract (0bf1ba4a8, cde825799): pattn_kernel<128, 8, 4, 8> against contract_attn.zig's float64 bound over
    shuffled pages, with a control. LFM3's three controls are in contract_lfm3_controls.cuh; contract_controls.cu
    stays at main's 600 lines.
  • Docs (d694eb2e5): docs/recipes/lfm3-cuda.md, with the command, the revision, the weight-only section, the
    receipt and the licence. The float64 reference is main's tools/lfm3/ref64.py (c2e557a96), so our copy was
    dropped.

Licence

The weights are under Liquid AI's LFM Open License v1.0 (license: other, lfm1.0; the text is the checkpoint's
LICENSE), as the MLX exports are.

  • Use, changes and redistribution are allowed.
  • Commercial use is licensed only to an organisation under US$10 million in annual revenue.
  • Non-profit research and other non-commercial use are allowed regardless.

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

  • Refusal tests: Metal's (native/lfm3.zig, zig build test-native) passes on an M3 Pro and goes red with the
    check commented out ("cannot load this checkpoint (NoSafetensors)"). It ran at an earlier local commit; the Metal
    open and lfm3/config.zig haven't changed since. XPU's (draft_sources_xpu_test.zig,
    test-lfm3-xpu-refusal-host) goes red without it ("cannot open the Level Zero driver (LoaderUnavailable)"). Both
    folders hold only config.json, so nothing past the config is read or queued before the refusal.
  • Windows: with hostTests' host set to x86_64-windows-gnu (a scratch patch, cross-compiled on the GB10), the
    guarded step is absent and the rest of that test module compiles. With the guard replaced by if (true), the test
    has 36 compile errors from xpu/qwen27.zig:200:24, the same as the zig-windows job on 0fa0fa122.
  • Served, on the merge 2fc30ddf1: the gate hashes each full reply (reasoning_content, content, token ids and
    token_sha256) and fails on an empty reply. It ran 50 gates a model, over 784 replies (all non-empty, 43,520 tokens
    with ids), with --parallel 8. Every gate was equal.
    • LFM3 NVFP4 against the pre-merge head 0fa0fa122. Main has no LFM3 on CUDA. The hash is 575f234045c711a3, the
      same as the corrected rows on this thread against b60ae9ee0.
    • LFM2.5 on the shared backend against main af9777b49. The hash is ef6ea8ecf5f099c0.
    • For each, the multi-turn chats resume equal to the reference, greedy and seeded, in five setups: the cache on,
      the cache off, a 0.1 GiB cache, under memory pressure, and on fixed pages (TENSORFOLD_*_KV_PAGES=0). 24 of 32
      turns hit the cache.
    • Concurrency 4 and 8 equal solo, greedy and seeded. Drafted equals plain, a restart gives the same hashes, and 8
      long prompts at once under pressure equal solo.
    • Every drain reads the whole pool free: 520/520 pages, and 195 (LFM3) or 72 (LFM2.5) under pressure.
  • Machine code: see docs/receipts/lfm-cuda-sass-fad7e142/, main af9777b49 against the merge 2fc30ddf1, nvcc
    13.0 and 13.2, sm_80/86/89/120/121. Every digest equals the receipt at the rebase. prefill_attention: 70 of 70
    functions identical (+5, pattn_kernel<128, 8, 4, 8>). contract_controls: 450 of 450 (+15, the three controls).
  • Contract (run at the rebase head cde825799; our kernels are unchanged since): tf-cuda-test kernel-contract paged liquid lfm3: 15 kernels pass gates 1-4, and all 25 controls go
    red as planted, among them the 7-tap conv (contract_lfm3_controls.cuh:6), the 7-tap commit (:12) and
    pattn<128> (:20); the served pattn<128> gates are contract_paged_attn.zig:42. Limit records on
    sm_80/86/89/120/121: LFM3's three launches are current on nvcc 13.0 and 13.2. The only nvcc 13.0 problems are
    main's 18 stale records (exl3_experts, flashnext_mtp, qwen35).
  • Host and x86: x86 (a9205a9ee): zig build -Dfixed-cpu test-host (20535 passed, 138 skipped),
    test-gradient-serving test-qwen-serving-host, test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths, check-native-cuda-host compile-cuda-tests, zig fmt --check, git diff --check and pr_check.py all pass. On the GB10 (2fc30ddf1): test-cuda-host,
    compile-cuda-tests, the Liquid, LFM3 and XPU host tests and zig fmt --check all pass, and git diff --check
    is clean.

Speed (GB10)

On the merge 2fc30ddf1: A-B-B-A, 4 servers an arm, the same 6 cold chats (about 9.4k tokens, two kept states each)
on every server, paired medians. LFM3 is against the pre-merge head 0fa0fa122 (main has no LFM3 on CUDA), and LFM2.5
against main af9777b49.

this head reference paired
LFM3 decode, 1 / 4 / 8 streams (tok/s) 116.1 / 412.8 / 702.6 116.3 / 412.2 / 701.2
LFM3 cold chat turn, default cache 0.887 s 0.884 s +1.97 ms, 13 of 24 slower (sd 4.3 ms)
LFM2.5 decode, 1 / 4 / 8 streams (tok/s) 80.0 / 186.7 / 257.2 80.1 / 186.8 / 257.0
LFM2.5 cold chat turn, default cache 1.446 s 1.452 s +1.98 ms, 15 of 24 slower (sd 9.4 ms)

Both paired medians are +2 ms, under half the spread of the pairs. 13 and 15 of 24 slower is near even. Decode is level.
LFM3's code is the same on both sides of its row; the merge only brought main in. These chats are shorter than the
rows posted at the rebase (10.4k tokens), and the decode prompts differ from them, so compare within this table only.
At the rebase, against b60ae9ee0, the default-cache LFM3 row was +4.1 ms (19 of 24). It followed main's 50 GiB
prompt cache, not this code: at 16 GiB on both it was +0.8 ms, and with the cache off -0.8 ms.

Proposed CHANGELOG line

- LFM3-1.7B NVFP4 (ModelOpt) served on CUDA, weight-only; Metal and XPU refuse that export by name (#1508)

Settled in review

  • The default context stays 32,768, as LFM2's does.
  • Fusing the head gate into the attention epilogue comes later, in its own PR with an A/B.

@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. A float64 reference that agrees with the official modelling code at every position is the evidence we want. Admitting only the export's exact ignore list keeps the scheme honest.

Before this leaves draft:

  1. It stacks on an old copy of the admission. cb2d77003 still adds the root build-lfm3.zig, which lfm3: add native Metal vision support above the text decoder #1502 has since folded into build.zig. Please rebase onto the admission as it lands, and onto main once lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492 has.
  2. zig/src/families/lfm3/cuda_backend.zig is lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's 426 lines with the names changed; cuda_snap.zig and cuda_native.zig are mostly the same as lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's too. Please share one lane backend, and the state walk, between the two Liquid families, generic over the model and the forward. liquid_conv.cuh already shares the conv that way.
  3. pattn_kernel<128, 8, 4, 8> has a limit record (lfm3_cuda_records.zig:11) but no gate. Please gate it against contract_attn.zig's float64 reference, with a planted control, as we've asked on lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492 for head 64.
  4. Each kept state allocates a device buffer and frees it behind a stream wait (cuda_snap.zig:61, :75-76), as in lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503. The same fix applies.
  5. Please commit the reference, and list each miss with its tokens and both margins.
  6. Please label the mode weight-only: the export's static FP4 input scales are read but not applied (cuda_weights.zig:118).
  7. Please state the weights' licence.

To your questions:

  • Keep 32,768 as the default, as LFM2 does, and raise it once 64k and longer contexts are measured.
  • Fuse the head gate later, in its own PR, with an A/B.
  • Yes, one admission for both backends. Whichever of this and lfm3: add native Metal vision support above the text decoder #1502 lands second should make Metal refuse modelopt_nvfp4 by name, with a test.

Then we'll run the contract and its limits. We'll serve the NVFP4 export on a GB10: drafted against plain, concurrent against solo, prompts across the sliding window, and resumed against fresh.

@BlivionIaG

Copy link
Copy Markdown
Contributor

@jschmied Could you rebase the CUDA follow-up onto the updated LFM3 admission/Metal work, preserving both authorships, so the shared admission and build files have a common base?

The Metal chain is now split into admission #1513, text #1514 and vision #1502. The admission branch is BlivionIaG:feature/lfm3-admission; the combined Metal branch is BlivionIaG:feature/lfm3-vl-support (currently d05f599a3, including c12411bdd). Please coordinate the shared admission changes against #1513 and retain your #1492 dependency, then rebase onto upstream main as those foundations land, as requested above. The old root build-lfm3.zig should not be reintroduced.

The Metal chain remains draft while numerical and performance qualification continues. This request is to reconcile the overlapping admission/build changes; it does not claim the chain is ready to land.

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. All seven are done; the head is 290975190.

  1. Rebase: onto lfm3: admit official MLX text and VL checkpoints #1513's head b3d9d6a4e, at BlivionIaG's request. His two commits are unchanged with his authorship (e003af71b, 5e8e2f84d), and our NVFP4 admission is our own commit on top (d7735968f). There's no root build-lfm3.zig. lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492 and lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503 (both rebased) stay below. I'll rebase onto main as those land.
  2. One backend: zig/src/families/liquid/ holds the lane backend, the kept-state walk and the native glue, generic over the family's model and forward. LFM2.5's and LFM3's cuda_backend.zig are 17 lines each, and their cuda_snap.zig and cuda_native.zig only name the model, the checks and their tests. A model names its fixed regions (LFM2.5: conv states; LFM3: conv states and the sliding K/V rings) and its paged layers. The commit is +1,048 / −1,486. LFM2.5 served on this head gives the same token hashes as lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503.
  3. Gate: pattn_kernel<128, 8, 4, 8> runs against contract_attn.zig's float64 bound over shuffled 512-key pages. Its served shapes are 256 rows with no history, 64 after 3,000 keys and 100 after 500, with planted NaN/inf. It passes gates 1–4, and its control, which reads values from the neighbouring 8 dims, goes red at 121× the bound. prefill_attention's existing 35 functions and contract_controls' 250 are unchanged on 5 SMs under nvcc 13.0 and 13.2.
  4. Pages: lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503's fix, now shared. Kept states are in pages allocated once inside the prompt-cache budget, so a keep or restore allocates nothing and a drop only returns the lease. The cold 10k chat turn is 0.807 s against 0.811 s before.
  5. Reference: tools/lfm3/ref64.py with REF64.md. 825/829 prompt rows and 127/128 reply rows agree in float64, and 827/829 and 126/128 with bf16 points. All 5 misses are listed with both tokens and both margins.
  6. Weight-only: said in the load log, at cuda_weights.zig:118, in the recipe and in the PR title. The static FP4 input scales are read, because the admission requires them, but not applied.
  7. Licence: LFM Open License v1.0, in the recipe's Licence section and the PR body.

Metal refusal: #1513 is still open, so this PR adds it. config.servedOn(config, .metal) refuses modelopt_nvfp4 with Lfm3ModeloptNvfp4NotOnMetal, and there's a test. #1514's Metal open needs to call it.

The served checks were rerun on this head, and every token hash is equal to the previous head's:

  • drafted == plain and concurrent == solo, 8/8;
  • prompts across the sliding window, 8/8;
  • resumed == fresh, 24/32 hits, equal to cache off and to fixed pages;
  • evictions and a restart.

@jschmied

Copy link
Copy Markdown
Contributor Author

@BlivionIaG Done: #1508 now stacks on #1513's head b3d9d6a4e (feature/lfm3-admission), not on the combined branch.

@jschmied jschmied changed the title lfm3: serve LFM3-1.7B NVFP4 on CUDA, weight-only (stacked on #1492 and the LFM3 admission) lfm3: serve LFM3-1.7B NVFP4 on CUDA, weight-only (stacked on #1513, #1492 and #1503) Oct 28, 2026
@jschmied jschmied changed the title lfm3: serve LFM3-1.7B NVFP4 on CUDA, weight-only (stacked on #1513, #1492 and #1503) lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) Oct 29, 2026
@ashhart

ashhart commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, this is a thorough round. The shared Liquid backend and the committed float64 references with every miss listed are what we asked for.

A few things before we run it:

  1. The diff no longer applies to main. build.zig conflicts near the new ling_host line. Please rebase once lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492, lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503 and lfm3: admit official MLX text and VL checkpoints #1513 settle.
  2. The block FP8 export (LFM3-1.7B-FP8) is new in this round. Please split it into its own PR so this one stays the NVFP4 work we reviewed. Or, if you'd rather keep it here, say why in the description.
  3. nemotron_attention.cu and prefill_attention.cu are refactored into shared headers. Please commit the SASS/byte-identity receipt for both images, not just the prefill_attention summary in the thread.

After that we'll run the contract, its limits and the GB10 served checks.

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart.

  1. Rebase: will do once lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492, lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503 and lfm3: admit official MLX text and VL checkpoints #1513 settle, as you say; nothing force-pushed for that until then.
  2. FP8: split out. lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508's head is now b60ae9ee0: the NVFP4 commits you reviewed plus the receipt below, nothing else. The block FP8 and MLX 4-bit commits are lfm3 CUDA: serve the block FP8 export weight-only and the MLX 4-bit export as stored (stacked on #1508) #1634, stacked on this one, unchanged apart from the cherry-pick. The NVFP4 head passes zig build test, the CI set (test-kernel-contract test-golden test-server-security test-pull-security fuzz-cortheon), git diff --check and lean (0 new) on its own.
  3. SASS receipt: committed in docs/receipts/lfm-cuda-sass-fad7e142/ (b60ae9ee0). cuda_sass_identity.py --receipt from main 1.1.9 (465e48b62) to the NVFP4 head (the whole stack, lfm2_moe: serve LFM2.5-24B-A2B on CUDA (plain serve, shared kernels) #1492 and lfm2_moe CUDA: attention pages from the shared KV pool, and the prompt cache (stacked on #1492) #1503 included), nvcc 13.0, sm_80/86/89/120/121. nemotron_attention: 35 of 35 existing functions identical, 10 added (tf_paged_attn_chunk_segs_64, tf_paged_attn_merge_segs_64). prefill_attention: 40 of 40 identical, 10 added (pattn_kernel<64|128, 8, 4, 8>). sass.tsv has every function's SASS sha256 on both sides. The README says why the tool exits 1 (it counts added functions, and its fp4pair control has nothing to change in these two images; the warp_sum control does show).

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The FP8 split and the SASS receipt are what we asked for, and the NVFP4 head reads as reviewed. This stays on hold for the stack below it: #1513 lands first, and we still owe the contract and GB10 runs on #1492 and #1503. One thing to know for the rebase: since your base, main moved prefill_attention.cu and nemotron_attention.cu onto the shared headers in zig/kernels/cuda/common (28-29 Oct, SASS unchanged) and changed prefill_attention.cu again for MOSS-Image (31 Oct). Your commit 6 no longer applies. After the rebase, please regenerate docs/receipts/lfm-cuda-sass-fad7e142/ against current main rather than 1.1.9, so the refactor into shared headers is shown identical on today's images. The other conflicts are appended lists and keep both sides. We'll run the contract, its limits and the GB10 served checks as soon as the stack is in.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Hi @jschmied, a status note: this is still parked behind #1492 and #1503, and those are on us (the contract and GB10
runs). #1513 is on main now, so one layer of the stack is done. Nothing needed from you until those land. When they do,
we can do the rebase onto the shared CUDA headers if that saves you time; say so here.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. To answer your question: the contract is weight-only. TensorFold serves the stored NVFP4 weights exactly as loaded and runs them with BF16 inputs, as main already does in its other weight-only modes; our code adds no activation quantization of its own. So the export's static FP4 input step stays out, and the serial reference is the same stored weights with BF16 inputs.

On that contract, the final-head host, control, full-reply, request-start and timing receipts stay credited, and no activation-path change is needed. Please say weight-only in the description and docs (the input scales are read and not applied). Integration with current main is on our side.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks. The head is now 43b6d46b78: your 409dc2b478 plus one docs commit. docs/recipes/lfm3-cuda.md and the description now say it: the contract is weight-only, the stored NVFP4 weights are served as loaded with bf16 inputs, and the release's input scales are read and not applied; activations stay bf16. No code changed, so the receipts from 409dc2b478 carry over.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The updated recipe states the agreed weight-only contract: stored NVFP4 weights with BF16 inputs, with the input scales validated but not applied. That closes the remaining question without changing the measured code.

The final-head host, control, full-reply, request-start and timing results remain credited. This is ready to land through the normal integration checks; the current-main list and source-pin merges are ours.

  • Synthena

jschmied and others added 21 commits November 25, 2026 08:56
…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.
ashhart added a commit to jschmied/TensorFold that referenced this pull request Nov 25, 2026
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.
ashhart pushed a commit to jschmied/TensorFold that referenced this pull request Nov 25, 2026
…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).
ashhart pushed a commit to jschmied/TensorFold that referenced this pull request Nov 25, 2026
…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.
@AIFlowML

Copy link
Copy Markdown
Contributor

I tested 209ec11e0a in a clean merge into b6ab6dbfd7. It also merges cleanly into 777f3bb762. The latest contract-controls pin matches the actual source digest. On M5 Max, the LFM3/CUDA, shared Liquid, XPU refusal and gradient targets passed 89/89. The ARM64 Linux CUDA adapter and test runner built in all 21 steps.

I also tested landing #1502 (2b087ef1d1) after this PR. There are four textual conflicts. I retained both changelog entries, both sets of weight fixtures and module exports, and the NVFP4 Metal refusal while allowing the supported VL checkpoint. The first combined host build then fails in the shared vision weight fixture because CUDA's cuda_safetensors.zig shim does not export parseHeaderPrefixes. Adding pub const parseHeaderPrefixes = st.parseHeaderPrefixes; gets all 37 focused build steps green. Both native builds also pass.

With the official VL 4-bit checkpoint at c823fade98e35a3d6942ad4d38b1ea15f675cd12, the combined Metal binary served both test PNG colors with --vision, returned HTTP 400 without it, and answered the text prompt in both modes. tools/lfm3/serve_check.py --sampled --cancel reported 63/64 twice. The only failure was the requirement to reuse a warm prefix. Both runs logged macOS memory-pressure warning and disabled new kept prompt states. The warm request still matched the fresh token hash, with zero cached tokens. That cache check needs a run while the governor admits new states.

The wider test-native Qwen27 fixture failure also reproduces on unchanged main. Initializing that fixture's features_state and external fields fixes the isolated main test. No CUDA device or speed run.

Igor Lessio - AIFLOW LABS

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.

4 participants