Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
477403d
glm: a kept state that goes stale drops its cache entry at once
heitke Oct 14, 2026
8be4d32
glm: expire dead cache states at the host boundary, borrow safely
heitke Oct 14, 2026
027ddea
Merge remote-tracking branch 'origin/main' into glm-cache-slot-guard
heitke Oct 14, 2026
5a4987b
Living Weights: the learner, pocket and fits move to zig/src/living, …
ZackSample Oct 15, 2026
75978a1
Living Weights learns into any family described as data: the family's…
ZackSample Oct 15, 2026
c6418f3
Flash Next's embedding row matches the host dequant of the same MLX g…
AdrianBinDC Oct 7, 2026
1dca5c1
Layer 0's first hyper-connection matches its host check on one token,…
AdrianBinDC Oct 7, 2026
cd57bfc
Layer 0's linear-attention projection matches the host group-32 dot o…
AdrianBinDC Oct 7, 2026
37dec96
Layer 0's linear-attention convolution, recurrence and output multipl…
AdrianBinDC Oct 7, 2026
2590dfc
Layer 0's second hyper-connection matches its host check on one token…
AdrianBinDC Oct 7, 2026
58fed6c
Layer 0's experts match the host check on one token, the top 10 and t…
AdrianBinDC Oct 7, 2026
69c4888
Layer 3's full attention matches the host check on one decode token, …
AdrianBinDC Oct 7, 2026
8a4add2
Layer 7's full attention matches the host check on one decode token, …
AdrianBinDC Oct 7, 2026
40472fb
Layer 11's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
307312a
Layer 15's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
d91b049
Layer 19's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
fcd0c15
Layer 23's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
0b4eab2
Layer 27's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
fbb2776
Layer 31's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
43961f6
Layer 35's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
8949cd1
Layer 39's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
2bb8a78
Layer 43's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
8c50b42
Layer 47's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
1bbed57
Layer 2's n-gram table matches the host dequant on one decode token, …
AdrianBinDC Oct 7, 2026
994c2ff
The final mix and the word scores match the host check on one decode …
AdrianBinDC Oct 7, 2026
7f0794d
One drafts-off prompt matches the Python engine, eight greedy token i…
AdrianBinDC Oct 7, 2026
0d04c43
Keep the drafts-off prompt match after splitting the forward and pack…
AdrianBinDC Oct 7, 2026
785896e
Flash Next CUDA: prompt ids and positions upload on the compute strea…
ZackSample Oct 11, 2026
8391cac
native/cuda.zig takes each CUDA family's prompt-cache copies, cache r…
ZackSample Oct 15, 2026
bd35940
CUDA experts over a window's or a prompt chunk's rows, each row with …
ZackSample Oct 15, 2026
2484c93
triton_aot_pack.py: a constexpr Triton folded from None is left out, …
ZackSample Oct 15, 2026
5cf4291
Flash Next CUDA: prompts and decode rounds on one batched pass, with …
ZackSample Oct 15, 2026
035b7f9
Flash Next CUDA: the MTP head, its draft chains, verify windows and t…
ZackSample Oct 15, 2026
1ac9bd0
Flash Next CUDA serves several streams through the lane core: drafted…
ZackSample Oct 15, 2026
62865ab
Flash Next CUDA: buffers are zeroed on the compute stream, so a pass …
ZackSample Oct 15, 2026
8d32cd3
Docs: Flash Next on CUDA, its recipe, the CUDA and Flash Next pages, …
ZackSample Oct 15, 2026
b45e26a
Flash Next CUDA refuses the config.json settings its kernels fix: RMS…
ZackSample Oct 15, 2026
9fa628b
Flash Next CUDA: a failed zero fill frees the buffer it was filling
ZackSample Oct 15, 2026
475df92
Flash Next CUDA: a pass's uploads read pinned staging the scratch own…
ZackSample Oct 15, 2026
1e86036
Core: router logits and softmax top-k rows for every CUDA family (rou…
ZackSample Oct 15, 2026
794d273
Core: token rows in groups of 32 with a copy a stream, and RMS rows w…
ZackSample Oct 15, 2026
ea7d098
Flash Next CUDA: its own glue kernels, flashnext_hc.cu and flashnext_…
ZackSample Oct 15, 2026
38c9c63
Flash Next CUDA boots on its own glue; a captured set that holds ever…
ZackSample Oct 15, 2026
235ea01
Flash Next CUDA: TF_FLASHNEXT_OWNED runs named entry points on our gl…
ZackSample Oct 15, 2026
7746bb9
Docs: Flash Next on CUDA boots on its own kernels; a captured set is …
ZackSample Oct 15, 2026
e7163c5
Flash Next CUDA: each layer_types label must be the exact role the ke…
ZackSample Oct 15, 2026
4b46157
Flash Next CUDA: a failed upload or record drains the stream before t…
ZackSample Oct 15, 2026
354f60d
CUDA: a Gated DeltaNet layer's input-gradient backward, every gradien…
ZackSample Oct 15, 2026
c106f2e
CUDA: input gradients of 4-bit (group 32) products, routed SwiGLU exp…
ZackSample Oct 15, 2026
a41cc2c
CUDA: gated attention's input gradients over 4-bit projections (a hea…
ZackSample Oct 15, 2026
0211f4d
Flash Next CUDA: the hyper-connections' and the pocket's input gradie…
ZackSample Oct 15, 2026
8e234db
Merge lw-b-core (#878, Living Weights as a core module) onto lw-c-fnb…
ZackSample Oct 15, 2026
e2779f6
Flash Next CUDA: a taught folder's pocket in every pass, and the batc…
ZackSample Oct 15, 2026
41ad4d4
Flash Next CUDA: Living Weights' trainer over the batched pass, and f…
ZackSample Oct 15, 2026
f5d6a4c
Living Weights learns into Qwen3.8 Flash Next on CUDA (--slide, GB10)…
ZackSample Oct 15, 2026
bad3a2a
Docs: Living Weights on Qwen3.8 Flash Next (CUDA, GB10), as measured;…
ZackSample Oct 15, 2026
514e4ee
Flash Next's pocket leaves an untaught stream's rows: a lesson writer…
ZackSample Oct 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Flash Next CUDA: prompt ids and positions upload on the compute strea…
…m; prompts past 512 keys; LR7 capture.

The ids and position uploads were synchronous copies, which do not wait for the non-blocking compute stream, so
a later row overwrote a queued row's token id or position: wrong tokens on most prompts. Both now go on the
stream. attnStep launches one 512-key chunk per started chunk of the row's keys (as attention.attention does)
instead of always one, so prompts run to the captured NCH * 512 keys; the lanes engine defaults to that window
and refuses a larger one. The prompt check prints each run's top five scores and its timing.

zig/tests/cuda/flashnext: capture.py and capture.sh (Python engine 0.6.1, drafts off, greedy, 1536 cache slots)
and the Unbound-LR7 prompts with their references; flashnext-prompt matches the teacher paths on all three.
  • Loading branch information
ZackSample committed Oct 15, 2026
commit 785896e1981ecc17dac520a369fe72d2d54edc08
4 changes: 3 additions & 1 deletion zig/src/families/flashnext/cuda_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub fn Namespace(comptime Tri: type) type {
return struct {
pub const model_type = "qwen4_exp";
pub const formats: []const []const u8 = &.{"mlx-q4g32"};
pub const default_context: i64 = 262144;
// dense attention over the captured scratch (NCH chunks of 512 keys, QSA off): no sparse indexer yet
pub const default_context: i64 = @intCast(prompt.max_tokens);
pub const prefill_step: u32 = 0;

pub const Options = struct { context: usize, drafts: bool };
Expand Down Expand Up @@ -98,6 +99,7 @@ pub fn Namespace(comptime Tri: type) type {

pub fn open(gpa: std.mem.Allocator, io: std.Io, ctx: *const cuda.Context, dir: []const u8, kernels: []const u8, o: Options) !Loaded {
_ = o.drafts; // this model is served one token at a time; there is no draft head
if (o.context > prompt.max_tokens) return error.ContextOverDenseAttention;
const driver: *cuda.Driver = @constCast(ctx.d);
const own = try gpa.create(Cuda);
errdefer gpa.destroy(own);
Expand Down
39 changes: 37 additions & 2 deletions zig/src/families/flashnext/cuda_prompt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ pub fn argmax(raw: []const u8) u32 {
return @intCast(at);
}

/// The five best scores of one row, best first, as "id:score" pairs on stderr (the capture's top5 field).
fn printTop(raw: []const u8) void {
var ids: [5]usize = @splat(0);
var vals: [5]f32 = @splat(-std.math.inf(f32));
for (0..vocab) |i| {
const v = promote(std.mem.readInt(u16, raw[2 * i ..][0..2], .little));
if (v <= vals[4]) continue;
var at: usize = 4;
while (at > 0 and v > vals[at - 1]) : (at -= 1) {
vals[at] = vals[at - 1];
ids[at] = ids[at - 1];
}
vals[at] = v;
ids[at] = i;
}
std.debug.print("top5", .{});
for (ids, vals) |id, v| std.debug.print(" {d}:{d:.4}", .{ id, v });
std.debug.print("\n", .{});
}

const Pass = struct {
gpa: std.mem.Allocator,
io: std.Io,
Expand Down Expand Up @@ -95,7 +115,9 @@ const Pass = struct {

fn embedRow(comptime Tri: type, p: *Pass, tri: Tri, token: u32, h: u64) !void {
const id: i32 = @intCast(token);
try p.s.ids.upload(0, std.mem.asBytes(&id));
// stream-ordered: a synchronous copy does not wait for the non-blocking stream, so a later row's id
// would overwrite this one before its queued _embed reads it
try p.s.ids.uploadAsync(0, std.mem.asBytes(&id), p.stream.handle);
try tri.embed(p.s.ids.ptr, p.table.w.ptr, p.table.s.ptr, p.table.b.ptr, h, dims, streams, 1);
}

Expand Down Expand Up @@ -165,6 +187,8 @@ fn forward(comptime Tri: type, p: *Pass, tri: Tri, layers: []Layer, ids: []const
}

pub const vocabulary: usize = vocab;
/// Prompt plus reply tokens a sequence can hold: the attention kernels' NCH chunks of 512 keys.
pub const max_tokens: usize = weights.nch * 512;

/// One loaded checkpoint: the embedding table, the mixer, the head, and a scratch row the forwards share.
pub const Engine = struct {
Expand Down Expand Up @@ -373,22 +397,33 @@ fn freeOwned(gpa: std.mem.Allocator, bs: []cuda.DeviceBuffer) void {

/// `out` receives `new_tokens` greedy ids. The first is the prompt's argmax. The rest are fed back one at a time.
pub fn run(comptime Tri: type, gpa: std.mem.Allocator, io: std.Io, driver: *cuda.Driver, stream: *cuda.Stream, tri: Tri, model_dir: []const u8, tokens: []const u32, new_tokens: usize, out: []u32) !void {
if (tokens.len == 0 or new_tokens == 0 or out.len < new_tokens or tokens.len + new_tokens > 256) return error.UnexpectedTensor;
if (tokens.len == 0 or new_tokens == 0 or out.len < new_tokens or tokens.len + new_tokens > max_tokens) return error.UnexpectedTensor;
var e = try Engine.init(gpa, io, driver, stream, model_dir);
defer e.deinit();
var seq = try e.newSeq(tokens.len + new_tokens);
defer seq.deinit(gpa);
const t0 = std.Io.Clock.awake.now(io).toNanoseconds();
try e.predict(Tri, tri, &seq, tokens);
const t1 = std.Io.Clock.awake.now(io).toNanoseconds();
out[0] = argmax(seq.logits);
printTop(seq.logits);
std.debug.print("token {d}\n", .{out[0]});
var tok = out[0];
for (1..new_tokens) |i| {
var one = [_]u32{tok};
try e.predict(Tri, tri, &seq, &one);
tok = argmax(seq.logits);
if (i < 4) printTop(seq.logits);
out[i] = tok;
std.debug.print("token {d}\n", .{tok});
}
const t2 = std.Io.Clock.awake.now(io).toNanoseconds();
const ms = struct {
fn of(ns: i96) f64 {
return @as(f64, @floatFromInt(ns)) / 1e6;
}
}.of;
std.debug.print("timing prompt {d} rows {d:.1} ms, decode {d} tokens {d:.2} ms/token\n", .{ tokens.len, ms(t1 - t0), new_tokens - 1, if (new_tokens > 1) ms(t2 - t1) / @as(f64, @floatFromInt(new_tokens - 1)) else 0 });
}

test "linear layers skip every fourth index and attention starts at 3" {
Expand Down
8 changes: 6 additions & 2 deletions zig/src/families/flashnext/cuda_prompt_step.zig
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,13 @@ pub fn gdnStep(gpa: std.mem.Allocator, driver: *cuda.Driver, stream: *cuda.Strea

pub fn attnStep(comptime Tri: type, driver: *cuda.Driver, stream: *cuda.Stream, tri: Tri, s: *Scratch, proj_q: Q4, out_q: Q4, q_scale: u64, k_scale: u64, i_scale: u64, kc: u64, vc: u64, ikc: u64, pos: i32) !void {
try qmm.matmul(driver, stream.*, s.mixed.ptr, s.xsm.ptr, proj_q.w.ptr, proj_q.s.ptr, proj_q.b.ptr, s.pa.ptr, 1, proj_n, dims);
try s.pos.upload(0, std.mem.asBytes(&pos));
// stream-ordered, like the ids: the previous row's queued attention kernels still read s.pos
try s.pos.uploadAsync(0, std.mem.asBytes(&pos), stream.handle);
try tri.attnPrep(s.pa.ptr, s.pos.ptr, q_scale, k_scale, i_scale, s.inv.ptr, s.q.ptr, kc, vc, s.dummy.ptr, s.dummy.ptr, s.iq.ptr, ikc, s.dummy.ptr, s.dummy.ptr, eps, 1, 0);
try tri.attnChunks(s.q.ptr, kc, vc, s.dummy.ptr, s.dummy.ptr, s.pos.ptr, s.po.ptr, s.pm.ptr, s.pl.ptr, s.dummy.ptr, s.dummy.ptr, s.dummy.ptr, 1, kv_heads, 1);
// attention.attention: chunks of 512 keys up to the row's position, at most the scratch's nch
const keys: usize = @as(usize, @intCast(pos)) + 1;
if (keys > nch * 512) return error.UnexpectedTensor;
try tri.attnChunks(s.q.ptr, kc, vc, s.dummy.ptr, s.dummy.ptr, s.pos.ptr, s.po.ptr, s.pm.ptr, s.pl.ptr, s.dummy.ptr, s.dummy.ptr, s.dummy.ptr, 1, kv_heads, (keys + 511) / 512);
try tri.attnMerge(s.po.ptr, s.pm.ptr, s.pl.ptr, s.pos.ptr, s.ao.ptr, s.dummy.ptr, s.dummy.ptr, 1, kv_heads);
try tri.attnGate(s.ao.ptr, s.pa.ptr, s.gated.ptr, s.gxs_attn.ptr, 1, proj_n, q_heads, head_dim);
try qmm.partials(driver, stream.*, s.gated.ptr, s.gxs_attn.ptr, out_q.w.ptr, out_q.s.ptr, out_q.b.ptr, s.dummy.ptr, s.part.ptr, 1, dims, out_k, out_sk);
Expand Down
178 changes: 178 additions & 0 deletions zig/tests/cuda/flashnext/capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/usr/bin/env python3
"""Flash Next's Python CUDA engine (qwen4_exp, drafts off, greedy) as the Zig port's oracle: every Triton launch,
prompt ids, and two greedy references per prompt (the served path: chunked prefill then serial decode; the teacher
path: every prompt token as its own decode row, the way zig's flashnext-prompt runs it)."""

from __future__ import annotations

import argparse
import json
import sys
import time
from pathlib import Path

PROMPTS = {
"short": "What is the capital of France?",
"mid": ("Explain in plain words why the sky looks blue during the day but turns red and orange at sunset. "
"Mention the role of the atmosphere and the wavelength of light, and keep it under five sentences."),
}
TOP_STEPS = 4 # sampled steps whose five best logits the teacher paths keep
LONG_TOKENS = 600 # the long prompt: module source cut to make the whole prompt about this many tokens


def chat(user: str) -> str:
return f"<|im_start|>user\n{user}<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n"


def prompts(model: Path) -> dict[str, list[int]]:
from tokenizers import Tokenizer
import textwrap

tok = Tokenizer.from_file(str(model / "tokenizer.json"))
enc = lambda s: tok.encode(s, add_special_tokens=False).ids # noqa: E731
out = {name: enc(chat(text)) for name, text in PROMPTS.items()}
head = enc("<|im_start|>user\nSummarize what this Python module does, then list its public functions:\n\n")
tail = enc("<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n")
body = enc(Path(textwrap.__file__).read_text())[:LONG_TOKENS - len(head) - len(tail)]
out["long"] = head + body + tail
return out


def specialization() -> dict:
"""Each JIT function's parameter names and which ones Triton never specializes (aot_pack.py's --jit)."""

from triton.runtime.jit import JITFunction
import gc

out = {}
for fn in gc.get_objects():
if isinstance(fn, JITFunction):
name = f"{fn.fn.__module__}.{fn.fn.__qualname__}"
out[name] = {"params": [p.name for p in fn.params],
"do_not_specialize": [p.name for p in fn.params if p.do_not_specialize],
"no_align": [p.name for p in fn.params if p.do_not_specialize_on_alignment]}
return out


def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--model", required=True, help="the checkpoint's snapshot dir")
ap.add_argument("--out", required=True)
ap.add_argument("--tools", default="", help="folder of triton_aot_manifest.py: record every Triton launch")
ap.add_argument("--tokens", type=int, default=32, help="greedy tokens per prompt")
ap.add_argument("--context", type=int, default=1536,
help="the cache window; 1025..1536 gives the port's NCH=3, QSA=0 attention specialization")
ap.add_argument("--only", default="", help="comma list of prompt names (default all)")
a = ap.parse_args()
out = Path(a.out)
out.mkdir(parents=True, exist_ok=True)
rec = None
if a.tools:
sys.path.insert(0, a.tools)
import triton_aot_manifest as aot

rec = aot.Recorder().install()

import torch
from contextlib import nullcontext

def phase(name: str, detail: bool = False):
return rec.scope(name, detail) if rec is not None else nullcontext()

model = Path(a.model)
ids = prompts(model)
if a.only:
ids = {k: v for k, v in ids.items() if k in a.only.split(",")}
(out / "prompts.json").write_text(json.dumps(ids) + "\n")
for name, p in ids.items():
(out / f"{name}.ids").write_text(" ".join(map(str, p)) + "\n")

from tensorfold.families.qwen4_exp.cuda.engine import FlashNextEngine
from tensorfold.families.qwen4_exp.cuda.forward import commit

t0 = time.perf_counter()
with phase("startup"):
eng = FlashNextEngine(model, depth=0, max_len=a.context, context_explicit=True, streams=1,
ple_on_ssd=True, kv_dtype="bf16", graphs=False)
e = eng.e
info = {"startup_s": round(time.perf_counter() - t0, 2), "max_len": eng.max_len, "prefill_rows": eng.prefill_rows,
"nch": e.buf.attn.nch, "qsa": bool(e.buf.attn.qsa), "idw": e.buf.attn.idw, "eos": list(eng.eos),
"torch": torch.__version__, "gpu": torch.cuda.get_device_name(0),
"prompt_lengths": {k: len(v) for k, v in ids.items()}}
print(json.dumps(info), flush=True)

results: dict[str, dict] = {}
from functools import partial
from tensorfold.families.qwen4_exp.cuda.state import Buffers

teach = partial(_teach, phase, results, a, commit, nullcontext)
fp32 = None
for name, prompt in ids.items():
# the served path: chunked prefill, then one token a round (draft=False is FlashNextEngine._serial)
toks: list[int] = []
with phase(f"serial-{name}"):
torch.cuda.synchronize()
start = time.perf_counter()
stats = eng.generate(prompt, a.tokens, None, lambda new: toks.extend(map(int, new)) and False,
draft=False, stop_eos=False)
torch.cuda.synchronize()
wall = time.perf_counter() - start
results[f"serial/{name}"] = {"tokens": toks, "wall_s": round(wall, 4), **stats}
print(f"serial {name} ({len(prompt)} prompt): {toks} {stats}", flush=True)
if fp32 is None:
# teacher32: the decode-form experts (fp32 slot outputs, Buffers' default and the MTP head's), the
# arithmetic zig's flashnext-prompt runs; the serial engine's buffers take the prompt-form experts
fp32 = eng.serial.twin()
fp32.buf = Buffers(eng.e.w, eng.e.rows, eng.e.capacity)

for label, t in (("teacher", eng.serial), ("teacher32", fp32)):
teach(label, name, prompt, t, toks)

(out / "results.json").write_text(json.dumps({"info": info, "results": results}, indent=1) + "\n")
if rec is not None:
rec.dump(out / "launches.json")
(out / "jit.json").write_text(json.dumps(specialization(), indent=1, sort_keys=True) + "\n")
eng.close()
print("done", flush=True)
return 0


def _teach(phase, results, a, commit, nullcontext, label, name, prompt, t, served):
"""Every prompt token one decode row, as zig's flashnext-prompt feeds them, then greedy rows."""

import torch

t.reset()
got: list[int] = []
top: list = []
steps = 0
with phase(f"{label}-{name}"):
torch.cuda.synchronize()
start = time.perf_counter()
feed = list(prompt)
dec_start = None
while len(got) < a.tokens:
tok = feed.pop(0) if feed else got[-1]
with (phase(f"{label}-{name}-detail", detail=True) if name == "short" and steps < 2
else nullcontext()):
logits = t.forward([tok])
if not feed:
got.append(t.sample(logits[:1], [t.st.pos + 1], None)[0])
if len(got) <= TOP_STEPS:
v, i = logits[0].float().topk(5)
top.append([[int(x), round(float(y), 4)] for x, y in zip(i.tolist(), v.tolist())])
if dec_start is None:
torch.cuda.synchronize()
dec_start = time.perf_counter()
commit(t.w, t.st, t.buf, 1, 1)
steps += 1
torch.cuda.synchronize()
end = time.perf_counter()
ms = (end - dec_start) / max(1, a.tokens - 1) * 1e3
results[f"{label}/{name}"] = {"tokens": got, "wall_s": round(end - start, 4),
"decode_ms_per_token": round(ms, 3), "top5": top}
print(f"{label} {name}: {got} ({ms:.2f} ms/token) same as serial: {got == served}", flush=True)


if __name__ == "__main__":
raise SystemExit(main())
25 changes: 25 additions & 0 deletions zig/tests/cuda/flashnext/capture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Flash Next (qwen4_exp) capture -> manifest -> kernel set for zig's flashnext-prompt and the native lanes engine.
# Usage: capture.sh WORK SNAPSHOT_DIR [IMAGE]
# WORK a host dir this script owns: WORK/cache (Triton + torch extension caches), WORK/out/cap, WORK/kernels
# SNAPSHOT_DIR the checkpoint's HF snapshot dir (its blobs must sit at ../../blobs, as in an HF cache)
# IMAGE TensorFold 0.6.1 image, default tensorfold-qwen38:v0.6.1
# The Python engine runs drafts off, greedy, --context 1535 (1536 cache slots: _chunks/_merge NCH=3, QSA=0, the dense
# attention the port launches), --ple-on-ssd, bf16 KV. Needs the GPU free (~78 GiB).
set -euo pipefail
WORK=$(readlink -f "$1"); SNAP=$(readlink -f "$2"); IMAGE=${3:-tensorfold-qwen38:v0.6.1}
REPO=$(cd "$(dirname "$0")/../../../.." && pwd)
HF=$(dirname "$(dirname "$(dirname "$SNAP")")") # .../hub/models--X/snapshots/REV -> .../hub (holds the blobs)
REL=${SNAP#"$HF"/}
mkdir -p "$WORK/cache" "$WORK/out/cap"
docker run --rm --name fn-capture --gpus all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 \
--user "$(id -u):$(id -g)" -e HOME=/tmp -e HF_HUB_OFFLINE=1 -e TENSORFOLD_NO_UPDATE_CHECK=1 \
-e TENSORFOLD_MEMORY_RESERVE_GIB=2 \
-v "$HF":/hf:ro -v "$WORK/cache":/cache -v "$REPO":/src:ro -v "$WORK/out":/out -w /out \
"$IMAGE" python -u /src/zig/tests/cuda/flashnext/capture.py --model "/hf/$REL" --out /out/cap \
--tools /src/tools/zig --tokens 32 --context 1535
python3 -B "$REPO/tools/zig/triton_aot_manifest.py" --cache "$WORK/cache/triton" \
--launches "$WORK/out/cap/launches.json" --mount /cache/triton --out "$WORK/out/cap/manifest.json"
python3 -B "$REPO/zig/tests/cuda/nemotron/aot_pack.py" --manifest "$WORK/out/cap/manifest.json" \
--cache "$WORK/cache/triton" --jit "$WORK/out/cap/jit.json" --out "$WORK/kernels"
echo "kernel set: $WORK/kernels; prompt ids and references: $WORK/out/cap/{short,mid,long}.ids, results.json"
1 change: 1 addition & 0 deletions zig/tests/cuda/flashnext/lr7/long.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
248045 846 198 8917 5437 537 1092 411 12654 4536 1503 11 1179 1103 1141 569 5568 25 271 12237 1138 39834 321 20621 13 198 12237 271 2 2861 318 34 8 220 16 24 24 24 12 17 15 15 16 41550 387 13 25788 13 198 2 2861 318 34 8 220 17 15 15 17 11 220 17 15 15 18 12654 4236 4846 13 198 2 32770 539 15573 25788 361 70 1550 31 12305 4909 29 271 464 311 271 548 528 548 283 2429 1138 11210 504 359 9797 504 359 7320 504 359 9497 305 504 359 31752 504 359 8412 268 642 271 2 10906 1787 279 14541 35169 5587 310 279 2201 12 54556 198 2 35169 5587 13 220 561 1822 2781 364 3604 411 369 421 198 2 1010 34707 12258 318 4650 1088 84 15 15 64 15 8 513 2397 52483 21201 26453 13 198 83201 283 5031 83 1639 3351 15 65 3351 15 66 11674 359 271 1005 2824 11210 25 198 262 4071 198 262 2907 364 39834 6454 9121 1414 13 220 561 569 3622 16661 314 198 262 279 14623 363 321 4990 363 5245 26 279 975 5245 513 1066 1017 364 198 262 65878 310 2723 303 1906 310 49324 279 1581 16501 13 198 262 1368 488 1318 310 6379 8032 279 1822 39834 11767 11 198 262 488 3172 4507 599 310 2723 696 9797 63261 973 271 262 24876 2774 7944 2444 5090 13173 314 39834 25 198 406 2297 318 2186 25 220 22 15 8 198 285 279 6966 2297 314 18880 4965 318 37488 1387 17268 18408 198 285 369 867 8 198 406 2763 66708 318 2186 25 11363 198 285 886 421 668 381 20671 2789 310 279 1118 1500 314 18880 198 285 2468 13 220 82699 6757 279 1500 579 2297 13 198 406 16905 66708 318 2186 25 11363 198 285 886 421 668 381 20671 2789 310 660 4965 3462 279 1118 198 285 314 18880 2468 26 1048 14159 6757 1754 1500 579 2297 13 198 406 8952 56008 318 2186 25 804 8 198 285 48455 21700 303 1879 1414 310 12258 1518 4473 8427 13 198 285 8618 5474 668 3512 220 15 5074 359 5999 2073 6 12258 11 11313 383 1141 2234 198 285 303 1141 1500 13 220 1368 867 11 1754 5474 369 11421 430 264 3074 3542 13 198 406 5474 2073 318 2186 25 220 23 8 198 285 48455 21700 303 1879 1414 310 220 15 5074 359 5999 2073 6 12258 11 7014 198 285 359 31251 56008 6 369 867 13 198 406 8032 83201 318 2186 25 804 8 198 285 28592 660 35169 5587 303 279 1879 1414 539 12258 198 285 1238 5474 14046 13 220 6817 421 413 8952 56008 369 867 321 198 285 8032 83201 369 804 11 1396 5474 668 381 15625 310 264 198 285 3074 3433 0 198 406 4884 46720 6018 793 318 2186 25 867 8 198 285 28320 421 11316 64541 59429 369 2590 7854 198 285 539 1330 12258 13 220 3978 539 1581 1521 279 11767 369 198 285 318 354 46261 2752 8 65669 13 198 406 1387 17268 18408 318 2186 25 804 8 198 285 15164 4105 4860 1056 359 2998 4282 220 1368 867 11 1782 4105 668 524 198 285 381 10548 11 321 1010 4965 2493 248046 198 248045 74455 198 248068 271 248069 271
1 change: 1 addition & 0 deletions zig/tests/cuda/flashnext/lr7/mid.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
248045 846 198 814 20139 303 13983 4105 3069 279 12515 5686 6105 2261 279 1834 694 10263 2438 321 18016 506 41564 13 82210 279 3364 314 279 16078 321 279 43796 314 3000 11 321 2426 424 1172 4097 22157 13 248046 198 248045 74455 198 248068 271 248069 271
Loading