Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 6 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Internal: core gains one walk for copying kept prompt states, and GLM's copies on CUDA and Metal go through it, with the same copies in the same order; other families keep their own loops. Nothing a user sees changes (#2215, part of #1293). Thanks to @jschmied.

- CUDA, opt-in build (`-Dnative-fp-decode`): qmmf's FP4 decode rows use the shared native e2m1 pair decode, `tf_common::e2m1_pairs`, which equals the existing decode on all 2^33 inputs; the default build's 113 fatbins are byte-identical and GB10 decode is level (#2721). Thanks to @jschmied.

- Qwen3.8-27B on Metal: while a request runs, the keep-warm ticker now commits the residency sets' probe each interval, so the first command buffer after a wide prompt pass no longer waits in the kernel (likely for macOS to wire the model again; not traced). On an M5 Ultra with a 14 GiB prompt cache filling memory, five cold 24K- to 64K-token prompts in a row reach their first tokens 3.5% to 5.9% sooner in total; with the cache off, cold prompts are level. Replies are unchanged (#2725, fixes #2724). Thanks to @mrv777.

- CUDA: beside a DSpine drafter, the dense Qwen3.8-27B copies from its context after 12 matching tokens instead of 20 (DFlash2 keeps 20), so agent turns decode about 6-7% faster at one stream on a GB10 with chat and code level; greedy replies are unchanged (#2703, after #2633). Thanks to @jschmied.

- Tests: a HIP GPU test runs one synthetic DeltaNet layer of Flash Next through `linear()` with the fused prompt prep and with the chain, compares the two bit for bit, and checks from its scratch use that the fused branch ran (#2706, after #2582). Thanks to @AbrahamCete.
Expand All @@ -22,7 +28,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Qwen 3.5 and 3.8 configs: one tied-head rule reads `tie_word_embeddings` from `text_config` then the root, and a checkpoint that sets neither loads untied, as transformers does (HIP had loaded it tied; Metal's 2B still requires the key); a root and `text_config` that disagree, or a value that isn't a flag, are refused with `BadTiedHead`. Flash Next, LFM2, Kolibri-1 and Qwen 3.5 read `rope_parameters`, legacy `rope_scaling` and their top-level keys through one core reader, and every config they accepted parses as before (#2714, fixes #2561, part of #2460). Thanks to @jschmied.


- CUDA: a family can declare that it keeps no prompt states, so the pool plans no prompt cache for it and `--prompt-cache-gib` is refused by name before the weights load, and that its replies carry no reasoning block, as HIP already allows; every family on main is unchanged (#2710). Thanks to @laudney.

- Tests: `zig build test-fsr-cli-host` compiles again (its module now gets the server's shared json imports), so `zig build test` no longer stops there on a Mac (#2782). Thanks to @BobClawblaw for the report.
Expand Down Expand Up @@ -70,7 +75,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- `--instruct-sampling card` (or `field=value` pairs) serves the model card's instruct sampling to sampled chat requests with thinking off that leave those fields unset; request fields, then the serve flags, then the pairs decide, and the server's own requests never take it (#2626). Thanks to @BobClawblaw.


- XPU: Qwen3.8-27B's DFlash2 drafts go through the core Drafter and Drafted, and each stream's draft tree is keyed with its own request (a sampled shared round read another's) (#2672, #2460 item 5). Thanks to @jschmied, and to @Mirrdhyn for the Arc Pro B70 runs.

- `POST /v1/images/generations` serves an engine's image capability: one picture a request as a base64 PNG, with an `n` other than 1, sizes past 1536 a side or 1,572,864 pixels, `response_format` `url`, unknown fields and a `negative_prompt` that is null or not valid UTF-8 refused by name; a text model's routes are unchanged (#2253, part of #1573). Thanks to @devopsfortunato.
Expand Down Expand Up @@ -296,7 +300,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- HIP: the qwen3_5 engine reads a DFlash2 drafter's `config.json` against its target, refusing one it can't run, and loads its weights as MLX affine-4 (groups of 64), quantized on the host as on CUDA; the server doesn't use the drafter (#2477, part 2 of #1563). Thanks to @AbrahamCete.


- Developers: the Qwen3.8-27B Metal lane check initializes its draft-window costs, and the served draft check compares complete state at the consumed token position, with exact tokens and state bytes (#2493, fixes #2489).

- Developers: `tools/zig/cuda_fragment_check.py` checks that every CUDA file including a function-body fragment (`prefill_attention_rows.cuh`, `qmmf_body.cuh`) declares each name the fragment uses on the branches it takes, and CI runs it beside the shared-copy check. It would have caught the `contract_controls.cu` miss that #2463 fixed (#2495).
Expand Down Expand Up @@ -496,7 +499,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Docs: `docs/optimization-ledger.md` lists which speed and memory optimizations apply to which native family, and where each stands, with links to the PRs that measured them (#2232). Thanks to @jschmied.


- Docs: the pull request pre-flight asks a PR that adds, finishes or drops a family's optimization to update that family's cell in the optimization ledger (#2243). Thanks to @jschmied.

- Server: a refused `--api-key-file` logs the path it was given, the mode the file system reported and which test failed, once at startup and once when a reload is refused (#2365). Thanks to @Whq02.
Expand Down Expand Up @@ -692,7 +694,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- `cached_tokens` and `prompt_tokens_cached_total` can no longer exceed the prompt, whatever a backend reports (#1899).


- GLM on CUDA at TP=2 with `TF_KV_PAGES=on` and `TF_GLM_KV_HOST=1`: a prompt chunk's MTP pass reads the pooled keys at the device stride, so a long first prompt no longer faults (#2173, fixes #2119). Thanks to @Bizuayeu.
- Living Weights: a refused lesson round names the sub-check that failed (#1587).

Expand Down Expand Up @@ -731,7 +732,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- `--profile stable`'s registry covers GLM's host KV tier: `TF_GLM_KV_HOST` and `TF_GLM_KV_HOST_SHARED` are now rows in the table, with [#1795](https://github.com/ashhart/TensorFold/pull/1795)'s identical tokens at TP=2, and their readers resolve through the registry. A switch looked up by name now goes through `core.profile.lookup`, which serves registered names from the table and every other name from the environment as before. Stable supplies no value, so nothing is enabled or changed by default (#1660).


- LFM3-1.7B runs on Intel GPUs through XPU, Iris Xe first (#1696). Thanks to @jschmied.
- Disk prompt-state startup preserves valid files when allocation fails, and reports the failure instead of treating them as damaged (#2134).

Expand Down Expand Up @@ -942,7 +942,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- On Ryzen AI Max (RDNA 3.5) GPUs, one- and two-row decode launches use narrower stream tiles, so Qwen3.6-35B-A3B chat decodes about 18% faster with drafts on, and Qwen3.8-27B about 5% faster, with the same tokens (#1855). Thanks to @AbrahamCete.


- CUDA's Qwen DFlash2 drafters must declare sliding attention on every layer (`use_sliding_window` and one `sliding_attention` per layer), which the kernels run, so a drafter declaring a full-attention layer is refused before loading instead of running through the sliding ring (#1946, part of #1863). Thanks to @garvrao80.

- Flash Next on HIP gathers n-gram drafts in parallel and releases the checkpoint's weight pages after uploading them, so the page cache falls from 31.5 to 2.8 GiB and the first cold prompt runs in 28.55 s instead of 48.44 s on a gfx1151 (#1611). Thanks to @gilby.
Expand Down Expand Up @@ -1240,7 +1239,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Qwen3.8-27B on Metal: the quantized projection tiles (`simd_qmm`'s MMA and chunk-pair kernels) now unroll their fixed loops, which the compiler had left rolled, and a shared round whose drafts get no rows no longer runs the drafter. Outputs are bit-identical. On an M3 Ultra with the MLX 4-bit checkpoint and DFlash2, decode goes from 80.3 to 91.0 tok/s at one stream (+13.4%), +19.0% at 4 streams, +24.9% at 8 and from 145.7 to 209.4 tok/s at 16 (+43.8%); without a drafter, prompts are 17% faster at 2k and 8k tokens and 4 and 16 streams are 14% faster, with prompt-test tokens equal to before. Pre-M5 lane windows can reach 64 rows with head and context copies (`TF_QWEN27_WINDOW`, `TF_QWEN27_COPIES`), off by default until qualified; unknown `TF_QWEN27_*` startup switches are refused by name, and the startup line names the effective loop and lane width. The kernel contract's measured M1/M2 limit records are corrected for three q4 tiles and GLM's row gather (#1621).


- LFM2.5-24B-A2B on Metal can hand an external drafter the rows of the layers it reads (its taps), copied on the GPU by a new kernel, `lfm2_tap`, that the kernel contract checks bit for bit with two planted controls (#1390, part of #1374). A drafting stream resumes a kept prompt state only when it also holds the drafter's context. Nothing uses the taps yet: without a drafter none are kept and every forward runs as before. Thanks to @BlivionIaG.

- Nemotron on CUDA: the MoE residual's norm, Mamba's group norm, the MTP input norms and the bf16 token rows run on the shared norm and embedding kernels instead of Nemotron's own copies, which are removed. The shared kernels keep Nemotron's summation order, so replies are the same tokens as before, and one fewer CUDA image loads (#1353, step 1 of #548). Thanks to @jschmied.
Expand Down Expand Up @@ -1329,7 +1327,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## 1.1.9


- Qwen3.8-27B on Metal: `TF_Q27_PROFILE=N` logs each kernel class's GPU time, the DFlash2 drafter's included, every N decode rounds (`1` means every 64), and adds `gpu_seconds` to replies: the GPU time of the forward passes the reply ran in, with a round shared by several replies counted in each (#1215). It is a diagnostic and off by default: without it replies are byte-identical to before, and a value it cannot read leaves it off with a warning. Timing every round is slow: on an M5 Ultra one stream decodes at about a ninth of its usual rate with it on, so use it to diagnose, not to serve. Thanks to @grantoverton.

- Qwen3.8 Flash Next on Metal: when a reply repeats text from its prompt or from earlier in the reply (edits, rewrites, renames, quotes), its copied drafts now verify in windows as wide as their measured acceptance pays for, about 11 rows where they stopped at about 4, and a copy skips the MTP head's later draft steps it replaces. Requests whose prompt plus max_tokens passes about 2,000 tokens, which includes every request at the server's default max_tokens of 4,096, now get the GPU gate that sets each round's width from the head's confidence, as shorter requests already did. On an M3 Ultra, copy-heavy edits ran 212 to 257 tok/s and rewrites 222 to 300; at the default max_tokens, prose ran 138 to 142 and long documents 173 to 179. Every reply is the same tokens as before, drafted or not.
Expand Down
11 changes: 6 additions & 5 deletions docs/kernel-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ its own is checked against the one below it, so its differences show as stale re
`kernel-contract-limits` and add a set for that release rather than loosening the audit. Launch dimensions, dynamic
shared memory, the device's limits and the planted controls are checked the same way under every release.

`-Dnative-fp-decode` (off by default; nvcc 13.2 or later) builds prompt16 and fp8_experts for `sm_<n>a` from sm_120
on and decodes their FP4/FP8 weight pairs with PTX ISA 9.2's `cvt.rn.bf16x2.e2m1x2`/`.e4m3x2`. Known finding: the
hardware decode equals `fp4pair` on all 256 e2m1 bytes and `fp8pair` on every e4m3 pair without a NaN code; the 1,020
pairs holding `0x7F` or `0xFF` decode to NaN, where the software gives ±480 (`tf-cuda-test native-fp`). Those codes
are NaN in e4m3, so only a broken checkpoint can tell the two apart. Default images keep the software decode.
`-Dnative-fp-decode` (off by default; nvcc 13.2 or later) builds prompt16, qmmf and fp8_experts for `sm_<n>a` from
sm_120 on and decodes their FP4/FP8 weight pairs with PTX ISA 9.2's `cvt.rn.bf16x2.e2m1x2`/`.e4m3x2` (qmmf: FP4 only).
Known finding: the hardware decode equals `fp4pair` on all 256 e2m1 bytes and `fp8pair` on every e4m3 pair without a
NaN code; the 1,020 pairs holding `0x7F` or `0xFF` decode to NaN, where the software gives ±480 (`tf-cuda-test
native-fp`). Those codes are NaN in e4m3, so only a broken checkpoint can tell the two apart. Default images keep the
software decode.

A restored 13.0 receipt can arrive after the later compiler sets. Such records mark `later_pending` so 13.0 and
13.1 use their base usage, while 13.2 and later keep their independently measured or pending selection.
Expand Down
15 changes: 14 additions & 1 deletion zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub const kernels = [_]Kernel{
.{ .name = "gemma4_ple", .flags = &.{"-O3"} }, // ours: Gemma 4 E-series per-layer inputs (gemma4/cuda_ple.zig)
.{ .name = "gdn_prep", .flags = &.{"-O3"} }, // ours: Gated DeltaNet conv, norms, g and beta (cuda/gdn_prep.zig)
.{ .name = "qk_rows", .flags = &.{"-O3"} }, // ours: QK norm, RoPE and the cache write (cuda/qk_rows.zig)
.{ .name = "qmmf", .flags = &.{"-O3"} }, // nvfp4/qmmf.cu's device code (FP8G, FP4), tensorfold_nvfp4_v3
.{ .name = "qmmf", .flags = &.{"-O3"}, .native_fp = true }, // nvfp4/qmmf.cu (FP8G, FP4), tensorfold_nvfp4_v3
.{ .name = "prompt16", .flags = &.{"-O3"}, .native_fp = true }, // nvfp4/prompt.cu FP4/FP8 tile 4, nvfp4_prompt_v1
.{ .name = "tree_attention", .flags = &.{"-O3"} }, // ours: committed keys and paths (cuda/tree_attention.zig)
.{ .name = "block_attention", .flags = &.{"-O3"} }, // ours: a drafter's block over its context (cuda/block_attention.zig)
Expand Down Expand Up @@ -200,3 +200,16 @@ test "profile: arch-specific kernels take sm_<n>a from sm_120 on, others plain,
try std.testing.expectEqual(Profile{ .number = 120, .arch_specific = false }, profile(plain, Target.parse("120")).?);
try std.testing.expectEqual(@as(?Profile, null), profile(plain, Target.parse("75")));
}

test "native_fp units: exactly fp8_experts, qmmf and prompt16 (without the flag native-fp only skips)" {
const want = [_][]const u8{ "fp8_experts", "qmmf", "prompt16" };
var seen: usize = 0;
for (kernels) |k| {
if (!k.native_fp) continue;
seen += 1;
for (want) |w| {
if (std.mem.eql(u8, k.name, w)) break;
} else return error.UnexpectedNativeFpUnit;
}
try std.testing.expectEqual(want.len, seen);
}
2 changes: 1 addition & 1 deletion zig/build/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const Cuda = struct {
/// The CUDA options for every target: a script that passes them where no CUDA step runs is not refused.
pub fn cuda(b: *std.Build) Cuda {
const sm_help = "SASS targets, comma separated (default 121; 80, 86, 89, 120 and 121 build)";
const native_help = "prompt16 FP4 and fp8_experts prompt tiles decode natively (PTX ISA 9.2: nvcc 13.2+, sm_120a+)";
const native_help = "prompt16/qmmf FP4 and fp8_experts tiles decode natively (PTX ISA 9.2: nvcc 13.2+, sm_120a+)";
const strip_help = "No debug info in the CUDA executables: no build machine paths leave with them";
return .{
.nvcc = b.option([]const u8, "nvcc", "nvcc (or a wrapper) that builds the CUDA kernel fatbins"),
Expand Down
8 changes: 8 additions & 0 deletions zig/kernels/cuda/common/fp_pairs.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ __device__ __forceinline__ uint32_t e4m3x2(uint32_t h) {
asm("{ .reg .b16 a; cvt.u16.u32 a, %1; cvt.rn.bf16x2.e4m3x2 %0, a; }" : "=r"(r) : "r"(h));
return r;
}

// fp4pair(w, 8q), fp4pair(w, 8q + 4) bit for bit: byte q of x holds nibbles (2q, 2q + 4), of y (2q + 1, 2q + 5)
__device__ __forceinline__ void e2m1_pairs(uint32_t w, int q, uint32_t& b0, uint32_t& b1) {
const uint32_t lo = w & 0x0F0F0F0Fu, hi = (w >> 4) & 0x0F0F0F0Fu;
const uint32_t x = lo | (lo >> 12), y = hi | (hi >> 12);
b0 = e2m1x2(q ? x >> 8 : x);
b1 = e2m1x2(q ? y >> 8 : y);
}
#endif

} // namespace tf_common
42 changes: 42 additions & 0 deletions zig/kernels/cuda/qmmf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,45 @@ template __global__ void reduce_kernel<true>(const float* __restrict__, void* __
template __global__ void reduce_kernel<false>(const float* __restrict__, void* __restrict__, long long, int, float);

}

#if defined(TF_NATIVE_FP_DECODE)
// tf-cuda-test native-fp: e2m1_pairs == fp4pair on all words, codes x e4m3 scales; out: misses, first, checks
extern "C" __global__ void tf_qmmf_native_fp4_check(unsigned long long* __restrict__ out) {
#if TF_FP_NATIVE
const unsigned long long n = 1ull << 33, step = 1ull * gridDim.x * blockDim.x;
unsigned long long bad = 0, first = ~0ull, seen = 0;
for (unsigned long long i = 1ull * blockIdx.x * blockDim.x + threadIdx.x; i < n; i += step) {
const uint32_t w = static_cast<uint32_t>(i >> 1);
const int q = static_cast<int>(i & 1);
uint32_t b0, b1;
tf_common::e2m1_pairs(w, q, b0, b1);
++seen;
if (b0 != tf_common::fp4pair(w, 8 * q) || b1 != tf_common::fp4pair(w, 8 * q + 4)) {
++bad;
first = i < first ? i : first;
}
}
const unsigned long long t = 1ull * blockIdx.x * blockDim.x + threadIdx.x;
if (t < 16 * 256) {
const uint32_t c = static_cast<uint32_t>(t >> 8), s = static_cast<uint32_t>(t & 255);
const uint32_t hw = tf_common::e2m1x2(c | (c << 4)), sw = tf_common::fp4pair(c | (c << 16), 0);
const float sf = tf_common::e4m3f(s);
const uint32_t sp = tf_common::fp8pair_unit(s | (s << 8), 0x7B807B80u);
const float h = __uint_as_float(hw << 16) * sf, g = __uint_as_float(sw << 16) * sf;
++seen;
// fp32 products compare as bits (NaN scale included); so do the bf16x2 products by the e4m3 scale pair
if (__float_as_uint(h) != __float_as_uint(g) || tf_common::mul2(hw, sp) != tf_common::mul2(sw, sp)) {
++bad;
first = ((1ull << 40) + t) < first ? (1ull << 40) + t : first;
}
}
if (bad) {
atomicAdd(&out[0], bad);
atomicMin(&out[1], first);
}
atomicAdd(&out[2], seen);
#else
if (blockIdx.x == 0 && threadIdx.x < 3) out[threadIdx.x] = ~0ull;
#endif
}
#endif
4 changes: 4 additions & 0 deletions zig/kernels/cuda/qmmf_body.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@
uint32_t b0, b1;
if constexpr (MODE == FP4) {
const uint32_t word = kt < 2 ? wq[j].x : wq[j].y;
#if TF_FP_NATIVE
tf_common::e2m1_pairs(word, kt & 1, b0, b1);
#else
b0 = fp4pair(word, (kt & 1) * 8);
b1 = fp4pair(word, (kt & 1) * 8 + 4);
#endif
} else if constexpr (MODE == BF16) {
#ifdef TF_QMMF_K32
const uint2 v = reinterpret_cast<const uint2*>(pw)[((wn * T::NT + j) * (BK / 16) + kt) * 32 + lane];
Expand Down
Loading
Loading