Repository navigation
Conversation
The host drew every verify row by scanning its 128,000 bf16 logits, after
the forward and with the GPU idle. lfm2_argmax picks each head row's first
largest logit on the GPU and flags a row with a nonfinite logit. verifyFn
takes the pick for greedy rows without a mask; sampled, masked and flagged
rows draw on the host as before.
The kernel is registered with the contract ("metal lfm2 argmax": the host
draw's pick, ties to the lower id, nonfinite rows flagged), and
tf-lfm2-exact checks every window's picks against the host draw.
…ctions lfm2_conv, lfm2_qk, lfm2_attn_mma and lfm2_attn_merge each call an inline body (lfm2_conv_row, lfm2_qk_row, lfm2_attn_rows, lfm2_merge_row) with the same arguments, so another kernel can run a row's arithmetic unchanged. The kernels' bits do not change.
The family's tests (config, draws, state) ran only inside `zig build test`. test-lfm2 runs the engine's test binary filtered to lfm2_moe, so a change to the family can run them without the whole suite.
…ll its streams A recorded call of several streams launched each stream's own short conv (30 layers) and its qk, attention and merge (10 layers): at 16 one-row streams 960 launches a forward for little work each. lfm2_segments.metal runs each of them once a layer over every row, from a table of the streams' cache addresses, row offsets and key counts (segments.zig); each row's arithmetic is the per-stream kernel's, called through the same inline bodies. A stream of more than 8 rows folds a chunk's sub-spans in its 8-row tiles, as its own 16-row tiles do. Prompt calls and one-stream windows keep their launches. Every cache buffer the table reaches is declared to the encoder: a new stream's caches join the server's residency set only at its next flush, so a kernel that reaches them through the table alone may read them before they are resident. The scratch's attention partials now hold each stream's apart (partialCount: a 32-row scratch's grow fourfold; the served scratch of 2,048 rows already holds them). The contract registers "metal lfm2 stream attention" and "metal lfm2 stream conv" as bit-equal replacements of the per-stream kernels, with float64 attention and a host replay of the conv steps. test-lfm2 checks the table, the row map, the tiles and the declared buffers, and the partials' count at 1, 32 and 2,048 rows.
… more From 8 rows the dense twin took its MMA window kernel, a threadgroup for 16 outputs over every row. A 2,048-wide matrix then has 128 threadgroups and runs slower than the scalar twin's 4-row passes; shared rounds of 8 to 32 rows call such matrices at every layer. The 6,144-wide short conv input and the head keep the window. Both kernels give the tiles' bits (the load check runs each matrix's twin at every width); the contract's twin now also serves 16 rows of 6,144 from 2,048.
… receipt README pointed at no native recipe for LFM2.5-24B-A2B. The page gives the checkpoint, the serve command, the shared-round kernels and their tests, and the measured M5 Ultra decode rates before and after them.
…mits and four planted controls The five launches are in lfm2_records.zig, with the limits that --offline compiled, not this GPU's. lfm2_attn_segs reserves its 128 threads in its source, as M1 and M2 cannot build it for another count. Four controls edit the source: a tie to the highest id, a nonfinite logit not flagged, and every stream reading or writing the first stream's conv state or kv cache. Each goes red at its gate.
M1 and M2 cap a pipeline's threads as its registers rise, and no run covers them. The server refuses them by name at open. An M3 is served, with one log line that it is not yet tested with shared rounds.
The shared-round kernels carry recorded M1 and M2 launch limits in the kernel contract, and no run covers those chips. The server no longer refuses them.
The shared-window chunk and merge bodies move to paged_attn_segs.cuh, included twice by nemotron_attention.cu: Nemotron's head-128 kernels keep their names and SASS, and head 64 adds tf_paged_attn_chunk_segs_64 and tf_paged_attn_merge_segs_64. prefill_attention.cu instantiates pattn_kernel<64, 8, 4, 8> over paged caches. sassid on sm_80/86/89/120/121: 0 functions changed, 15 added.
lfm2_moe.cu holds what the shared operators do not: the short conv over each stream's state with every window row's snapshot, the commit of an accepted row's conv state, and the router (fp32 weights, top-4 of sigmoid + bias, ties to the lower id, a NaN ranked as -inf). Each has a planted control. Launch records cover these kernels and the head-64 paged attention on nvcc 13.0, with one 13.2 override.
The MLX 4-bit checkpoint (embedding at 4, 6 or 8 bits) on the shared affine-4 projections and experts, with prompt chunks of 1024 rows, one-row decode and copy-drafted windows over --parallel streams. The ten attention layers keep their keys and values in 512-position pages, and each stream has its own conv state. There is no drafter and no prompt cache yet.
…ount The gated short conv over each stream's state and the conv-state commit move out of lfm2_moe.cuh into liquid_conv.cuh, templated on the tap count, so LFM3 (7 taps) can take the same bodies as LFM2.5 (3). lfm2_moe.cu keeps the router and instantiates the 3-tap pair as tf_liquid_conv_3 and tf_liquid_commit_3; the controls become tf_ctl_liquid_conv_3 and tf_ctl_liquid_commit_3. cuobjdump -sass on sm_80/86/89/120/121, nvcc 13.0 and 13.2: the moved bodies are identical under their new names, every other function unchanged.
|
Thanks @jschmied, this is a tidy port. It reuses the shared CUDA pieces wherever they fit, and the contract finding the all-NaN router row is a good catch. #1377 has landed as rewritten commits, so this branch no longer merges with main: it conflicts in Before this leaves draft:
To your questions: moving both headers under Then we'll run the kernel contract and its limits at 13.0 and 13.2, and compare Nemotron's head-128 machine code with main. Then we'll serve the 4-bit export on a GB10: drafted against plain, concurrent against solo at 1, 4 and 8 streams, and speed. |
Part of #1488. Stacked on #1377 (BlivionIaG's LFM2 stack, head
70f74ca34): the 10 commits below7d7d8f49eare #1377's, and this PR adds only the last four. Draft until #1377 lands, then I'll rebase onto main.What
LFM2.5-24B-A2B (
lfm2_moe) served natively on CUDA fromLiquidAI/LFM2.5-24B-A2B-MLX-4bit: plain serving with--parallel Nand TF's built-in drafts. No DSpark drafter yet. The engine reuses the shared CUDA pieces wherever they fit.addRmsTailnorms, the SwiGLU act with group sums,qk_rows(q/k norm + RoPE), the page KV write, the Affine4 experts with the grouped plan, the MoE combine, andtree_roundargmax / sampling.prefill_attention's prompt kernel at head dim 64, and the paged shared-window attention at head dim 64. Its body moves from Nemotron's file into a neutralpaged_attn_segs.cuh. Head 64 exportstf_paged_attn_chunk_segs_64/tf_paged_attn_merge_segs_64, and Nemotron's head-128 symbols keep their names and SASS.liquid_conv.cuh, templated on the tap count (tf_liquid_conv_3/tf_liquid_commit_3), so LFM3's 7-tap conv (Add native Metal support for LFM3-1.7B and LFM3-VL-2B MLX 4/6/8-bit checkpoints #1491) can reuse them; only the router stays inlfm2_moe.cu. The move is SASS-identical by function body on all five SMs, and served replies are byte-equal before and after. The router has fp32 weights, expert bias, normalized top-4 and eps 1e-6.Commits:
7d7d8f49ecuda: the paged shared-window attention at head dim 64d70fc9821lfm2_moe: CUDA glue kernels under the contractc6645063alfm2_moe: serve LFM2.5-24B-A2B on CUDA580d8f24bcuda: Liquid's short conv and its commit in liquid_conv.cuh, by tap count22 files, +2,262 / −142 against #1377.
Verification (GB10, sm_121, nvcc 13.0)
--parallel 8, greedy:lean_check: 0 new problems against LFM2: shared-round decode #1377's head.zig build testpasses.Speed (GB10)
Cold TTFT: 0.32 s at 2.8k prompt tokens, 1.32 s at 11.2k.
Not in this PR
Questions
paged_attn_segs.cuhis still compiled into thenemotron_attentionimage. I'd move it andliquid_conv.cuhunderzig/kernels/cuda/common/once cuda: shared device primitives in zig/kernels/cuda/common (#1409, part 1: SASS unchanged) #1440 lands. Does that suit you, or would you rather each get its own image?registry.zig(records), which is easy to resolve whichever lands second.