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
16 changes: 2 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Checkpoints: a bf16 weight stored in DFloat11's lossless form is read under its own name and decoded on the host at load to the bf16 bytes it was coded from, where such a checkpoint was refused by the missing tensor's name; GLM-5.3-Flash on CUDA is the one loader that attaches it, a damaged group is refused by name, and a checkpoint with no coded tensor loads as before (#3807, refs #3649). Thanks to @Bizuayeu.

- Flash Next on CUDA: `TF_FLASHNEXT_SPLIT_DENSE` and `TF_FLASHNEXT_SHARD_HEAD` are checked by name when the engine loads, so a malformed value names the variable, the supplied text and the accepted forms, and an empty or blank value reads as unset; valid values and defaults are unchanged (#3749, refs #2370). Thanks to @devopsfortunato.

- Tests: the Web loopback startup regression sets its stand-in past the three-second warm-up, so it passes standalone and in the full suite alike (#4086, fixes #3752).

- Docs: a one-GB10 recipe serves DeepSeek-V4-Pro-Qwen3.5-9B from a locally converted MLX 4-bit checkpoint, thinking and drafts off, with its health, model-list and chat checks (#4085, fixes #3905).



- Qwen 3.5/3.6/3.8 on CUDA: `TF_QWEN35_CHUNK_SOLO=8192` lets a foreground prompt pass take up to 8,192 rows while no other stream decodes, back to 4,096 once one does and in background warm passes; unset or 4096 is off, and tokens match it off (#3294). Thanks to @jschmied.

- Docs: the Flash Next CUDA recipe pulls the checkpoint and serves it by name, and supported models gives it as a 105.5 GiB download of which 73.3 GiB goes to the GPU (#4024). Thanks to @jayleaton.
Expand All @@ -38,8 +38,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Docs: on unified memory, `MemAvailable` can settle a little above the reserve after start-up and the pool's page count can differ by a few tens between launches with the same settings, because the room is read once while the host is still settling (#4079, fixes #3940). Thanks to @Bizuayeu.



- Web: the development stand-in reports native 1.3.0, in a checkout and in the built wheel, where it still said 1.2.10 (#4077, fixes #4074). Thanks to @AIFlowML.

- CI: a landing train's pull request skips GitHub's hosted checks, which our own runners already run on its tip (a red local run still starts them by hand), and a newer push cancels an older Zig format run, so main's and contributors' checks no longer queue behind trains (#4106).
Expand All @@ -48,22 +46,16 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Qwen3.8-27B on Metal: a request cancelled during its prompt pass, a drafted round or a streamed reply keeps the prompt state it completed when the prompt cache has room, so a follow-up on the same conversation resumes there instead of re-reading the history; after a cancelled reply, slot 0 first rewinds to its saved prompt state, and in the shared lane core a cancelled pass gives up only its own cache reservation (#3643, for #3618).



- Server: every prompt-cache lookup records why it did not resume further (for example `cold`, `evicted`, `shed`, `prompt_changed` or `reply_changed`), and `/metrics` counts them as `prompt_cache_miss_total{reason}` over a fixed list of reason names (#3706, for #3686). Thanks to @bikepresentball.

- DeepSeek-V4.1 on Metal: the prompt layer's compressor, indexer key and weight, and MoE gate projections run on a new simdgroup-matrix kernel (`tf_dsv41_mv_mma`) at 16 or more rows, bit-equal to the matrix-vector kernel it replaces (#3668, refs #2984). Thanks to @gilby.



- Qwen on CUDA: a development build for sm_110 (`-Dsm=110`, NVIDIA Thor) refuses by name, before paging or weight loading, the modes not qualified there: `--slide`, a DSpine `--drafter`, `TF_DSPINE_WINDOW`, `--kv-cache fp8`, `--prompt-precision int8`, `--rope-yarn`, `TF_QWEN_KV_PAGES`, `TF_QWEN_KV_PAGES_ALL=1`, `TF_QWEN_KV_SHARE`, `TF_QWEN_REQUEST_STARTS=1`, `TF_QWEN_KV_PAGE_TEST`, `TF_QWEN_KEEP_LATE=1`, `TF_NO_TREES` and `TF_DRAFT_NODES`; the default path and the DFlash2 drafter are still served, and other GPUs are unchanged (#3057, refs #2319). Thanks to @yguanrong.

- CUDA: a Flash Next prompt pass holds 3,072 rows while other streams decode (it held 1,536), so a long prompt beside running streams takes half as many passes (#3726). Thanks to @BadAd84.

- GLM-5.3-Flash on CUDA: the sampled draw takes its rule from the shared `cuda.sample.rule`, as MiniMax M3 does, instead of building its own copy with a fixed `near` value (#3705, part of #2680). Thanks to @jschmied.



- Server: `GET /v1/models/{id}` (and `/models/{id}`) returns the entry `/v1/models` lists for the served name or an alias, the id sent as written or percent-escaped (`org%2Fname`); any other id is a 404 `model_not_found`, and API keys and key scopes treat the route as they treat `/v1/models` (#3535).

- Server: the next turn's background prefill puts the reply's reasoning into its guess when the client sends reasoning back, so thinking requests resume from the real next prompt instead of redoing the pass from before the reply; clients whose history drops reasoning keep the old guess (#3264).
Expand All @@ -76,8 +68,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- GLM-5.3-Flash on CUDA: GLM's kernels and qmmf's decode linears launch as programmatic dependent launches, so a decode token's kernels lose most of their launch gaps; experts, the router plan and the RoCE exchange stay plain launches, a prompt chunk's KDA chain launches plain from 64 rows, and `TF_GLM_PDL=0` launches everything plain (#3776, refs #3652). Thanks to @ultradaoto.



- dots.mocr on CUDA: `--vision` now serves images through the image tower instead of refusing them, within the request's `--vision-image-tokens` budget; text-only replies keep their pinned hashes, and the GB10 runner gains `tf-cuda-test dots-text` (three prompts of our own, served with and without `--vision`, against pinned reply hashes) and `dots-invariants` (image prompts cut into chunks against the uncut run) (#2771, refs #1927). Thanks to @laudney.

- Qwen3.8-27B on Metal before M5: decode rounds read their cached keys through the prefix kernels, as on an M5, and prompt passes size their memory the same way; `TF_QWEN27_SHARED_PREFIX=0` keeps cached keys on the tail kernel (#3677, refs #3604). Thanks to @hobbesd.
Expand All @@ -90,8 +80,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Desktop: an MCP server's startup diagnostics reach the Plugins preview as whole lines, masked as a whole and capped at 64 KiB, instead of one row per stderr write (#3759). Thanks to @AIFlowML.



- Flash Next on HIP: the prompt chunk fallback counts the window plan's slot bytes as used before deciding whether a smaller chunk admits more streams, where it counted them as free and could keep the larger chunk (#3419). Thanks to @gilby.

- DeepSeek-V4.1 on Metal: its GPU work goes through a Metal 4 command queue by default where the Mac has one (macOS 26 and later), with the same kernels in the same order and bit-identical outputs; `TF_METAL4=0` keeps Metal 3, `TF_METAL4_TIMELINE=n` logs per-stage GPU times for n rounds of each kind, and `TF_DSV41_ROUND_PROF=1` logs decode rounds' host and GPU milliseconds (#3374).
Expand Down
25 changes: 21 additions & 4 deletions zig/src/core/checkpoint.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const index_format = @import("checkpoint_index.zig");
const prefetching = @import("checkpoint_prefetch.zig");

pub const cache = @import("checkpoint_cache.zig");
pub const coded = @import("checkpoint_coded.zig");
pub const direct = @import("checkpoint_direct.zig");
pub const Tensor = st.Tensor;
pub const DType = st.DType;
Expand Down Expand Up @@ -72,6 +73,8 @@ pub const Checkpoint = struct {
scope: []const u8 = "",
/// Copies `get` returns in place of the mapping's bytes, by full name (checkpoint_direct's current layer).
copies: ?*const std.StringHashMapUnmanaged([]const u8) = null,
/// DFloat11 groups answered under their members' weight names (`coded.attach`); null: every name is a header's.
coded: ?*coded.Coded = null,

fn scoped(self: *const Checkpoint, buf: *[320]u8, name: []const u8) ![]const u8 {
if (self.scope.len == 0) return name;
Expand Down Expand Up @@ -107,6 +110,7 @@ pub const Checkpoint = struct {
}

pub fn close(self: *Checkpoint) void {
if (self.coded) |c| c.deinit(self.gpa);
for (self.files.items) |*f| f.close(self.io);
self.files.deinit(self.gpa);
self.used.deinit(self.gpa);
Expand All @@ -116,7 +120,11 @@ pub const Checkpoint = struct {
/// The tensor named `name`, marked as used; a missing name is an error naming it.
pub fn get(self: *Checkpoint, short: []const u8) !Tensor {
var buf: [320]u8 = undefined;
const name = try self.scoped(&buf, short);
return self.find(try self.scoped(&buf, short), null);
}

/// The tensor a header names `name` (the full name), marked as used; null when no file holds it.
pub fn stored(self: *Checkpoint, name: []const u8) !?Tensor {
for (self.files.items) |*f| if (f.get(name)) |t| {
const key = f.names.getKey(name).?;
try self.used.put(self.gpa, key, {});
Expand All @@ -126,13 +134,21 @@ pub const Checkpoint = struct {
};
return out;
};
return null;
}

/// A header's tensor, else a coded one in `shape` (its loader's shape for the name without one).
fn find(self: *Checkpoint, name: []const u8, shape: ?[]const usize) !Tensor {
if (try self.stored(name)) |t| return t;
if (self.coded) |c| if (try c.get(self, name, shape)) |t| return t;
std.log.err("checkpoint has no tensor {s}", .{name});
return error.MissingTensor;
}

/// `get` with the dtype and shape checked.
pub fn expect(self: *Checkpoint, name: []const u8, dtype: DType, shape: []const usize) !Tensor {
const t = try self.get(name);
var buf: [320]u8 = undefined;
const t = try self.find(try self.scoped(&buf, name), shape);
if (!t.is(dtype, shape)) {
std.log.err("{s}: {t} {any}, expected {t} {any}", .{ name, t.dtype, t.shape[0..t.rank], dtype, shape });
return error.UnexpectedTensor;
Expand All @@ -145,7 +161,7 @@ pub const Checkpoint = struct {
var buf: [320]u8 = undefined;
const name = self.scoped(&buf, short) catch return false;
for (self.files.items) |*f| if (f.get(name) != null) return true;
return false;
return if (self.coded) |c| c.names.contains(name) else false;
}

/// Marks every name starting with `prefix` as used: a part the loader leaves out on purpose.
Expand All @@ -157,8 +173,9 @@ pub const Checkpoint = struct {
};
}

/// Every file's pages out of the page cache (safetensors.File.release).
/// Every file's pages out of the page cache (safetensors.File.release), and every decoded group freed.
pub fn release(self: *const Checkpoint) void {
if (self.coded) |c| c.drop(self.gpa);
for (self.files.items) |*f| f.release(self.gpa);
}

Expand Down
157 changes: 157 additions & 0 deletions zig/src/core/checkpoint_coded.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//! DFloat11-coded weights under a Checkpoint's names: groups found in the headers, each decoded once until a release.

const std = @import("std");
const st = @import("safetensors.zig");
const dfloat11 = @import("dfloat11.zig");
const layout = @import("dfloat11_config.zig");
const Checkpoint = @import("checkpoint.zig").Checkpoint;

/// A family's shapes for the names its loader takes with `get`: the files hold each member's element count alone.
pub const Shapes = struct {
ctx: *const anyopaque,
of: *const fn (ctx: *const anyopaque, name: []const u8, buf: *[st.max_rank]usize) ?[]const usize,
};

const stream = ".encoded_exponent";
const parts = [_]struct { []const u8, st.DType }{
.{ ".luts", .u8 }, .{ stream, .u8 }, .{ ".sign_mantissa", .u8 },
.{ ".output_positions", .u8 }, .{ ".gaps", .u8 }, .{ ".split_positions", .i64 },
};

const Name = struct { group: u32, member: u32 };
const Group = struct {
prefix: []const u8,
members: u32,
/// The whole group as little-endian BF16, from the first `get` of a member until `drop`.
decoded: ?[]align(64) u8 = null,
};

pub const Coded = struct {
arena: std.heap.ArenaAllocator,
bytes_per_thread: u32,
threads_per_block: u32,
shapes: ?Shapes,
names: std.StringHashMapUnmanaged(Name) = .empty,
groups: std.ArrayList(Group) = .empty,

/// Coded `name` in `want`'s shape (the family's without one), alive until the next `release`; null: not coded.
pub fn get(c: *Coded, ck: *Checkpoint, name: []const u8, want: ?[]const usize) !?st.Tensor {
const at = c.names.get(name) orelse return null;
const g = &c.groups.items[at.group];
var buf: [st.max_rank]usize = undefined;
const shape = want orelse (if (c.shapes) |s| s.of(s.ctx, name, &buf) else null) orelse {
refuse("{s} is DFloat11-coded, and its loader names no shape for it", .{name});
return error.CodedShapeUnknown;
};
if (shape.len > st.max_rank) return error.RankTooHigh;
var stored: [parts.len][]const u8 = undefined;
var part: [320]u8 = undefined;
for (parts, &stored) |p, *bytes| {
const full = std.fmt.bufPrint(&part, "{s}{s}", .{ g.prefix, p[0] }) catch return error.MissingTensor;
bytes.* = ((try ck.stored(full)) orelse return error.MissingTensor).bytes;
}
const n = stored[2].len;
const range = try dfloat11.member(stored[5], g.members, n, at.member);
var count: usize = 1;
for (shape) |d| count = std.math.mul(usize, count, d) catch return error.UnexpectedTensor;
if (count != range.end - range.begin) {
refuse("{s}: {d} coded elements, expected {any}", .{ name, range.end - range.begin, shape });
return error.UnexpectedTensor;
}
if (g.decoded == null) {
const bytes = std.math.mul(usize, 2, n) catch return error.UnexpectedTensor;
const out = try ck.gpa.alignedAlloc(u8, .@"64", bytes);
errdefer ck.gpa.free(out);
dfloat11.decode(.{
.luts = stored[0],
.encoded_exponent = stored[1],
.sign_mantissa = stored[2],
.output_positions = stored[3],
.gaps = stored[4],
.bytes_per_thread = c.bytes_per_thread,
.threads_per_block = c.threads_per_block,
}, out) catch |err| {
refuse("DFloat11 group {s}: {t}", .{ g.prefix, err });
return err;
};
g.decoded = out;
}
var t: st.Tensor = .{ .dtype = .bf16, .rank = @intCast(shape.len), .shape = @splat(1), .bytes = g.decoded.?[2 * range.begin .. 2 * range.end] };
@memcpy(t.shape[0..shape.len], shape);
return t;
}

/// Frees every decoded group: tensors `get` returned are gone, and the next `get` decodes again.
pub fn drop(c: *Coded, gpa: std.mem.Allocator) void {
for (c.groups.items) |*g| if (g.decoded) |bytes| {
gpa.free(bytes);
g.decoded = null;
};
}

pub fn deinit(c: *Coded, gpa: std.mem.Allocator) void {
c.drop(gpa);
c.arena.deinit();
gpa.destroy(c);
}
};

/// Has `ck` answer the member weight names of its groups (a `<module>.encoded_exponent` and five more tensors each).
pub fn attach(ck: *Checkpoint, config: layout.Config, shapes: ?Shapes) !void {
std.debug.assert(ck.coded == null);
const c = try ck.gpa.create(Coded);
c.* = .{ .arena = .init(ck.gpa), .bytes_per_thread = config.bytes_per_thread, .threads_per_block = config.threads_per_block, .shapes = shapes };
errdefer {
c.arena.deinit();
ck.gpa.destroy(c);
}
const a = c.arena.allocator();
for (ck.files.items) |*f| for (f.names.keys()) |k| {
if (!std.mem.endsWith(u8, k, stream)) continue;
const prefix = k[0 .. k.len - stream.len];
const pattern = (try config.group(prefix)) orelse {
refuse("DFloat11 group {s}: no pattern of dfloat11_config describes it", .{prefix});
return error.CodedGroupUnlisted;
};
var split: usize = 0;
for (parts) |p| {
const e = entry(ck, try std.fmt.allocPrint(a, "{s}{s}", .{ prefix, p[0] })) orelse {
refuse("DFloat11 group {s}: no {s}", .{ prefix, p[0][1..] });
return error.CodedGroupPartial;
};
if (e.dtype != p[1]) return error.CodedGroupPartial;
split = e.end - e.begin;
}
const members = @max(1, pattern.members.len);
if (split != 8 * (members - 1)) {
refuse("DFloat11 group {s}: {d} members listed, {d} split positions stored", .{ prefix, members, split / 8 });
return error.CodedMembers;
}
const group: u32 = @intCast(c.groups.items.len);
try c.groups.append(a, .{ .prefix = try a.dupe(u8, prefix), .members = @intCast(members) });
for (0..members) |j| {
const name = if (pattern.members.len == 0)
try std.fmt.allocPrint(a, "{s}.weight", .{prefix})
else
try std.fmt.allocPrint(a, "{s}.{s}.weight", .{ prefix, pattern.members[j] });
// a name stored plain as well, or coded by two groups, has no one answer
const slot = try c.names.getOrPut(a, name);
if (slot.found_existing or entry(ck, name) != null) {
refuse("{s} is DFloat11-coded in {s} and also stored elsewhere", .{ name, prefix });
return error.CodedNameStored;
}
slot.value_ptr.* = .{ .group = group, .member = @intCast(j) };
}
};
ck.coded = c;
}

/// A refusal's line for the log; host tests refuse on purpose, and a logged error fails their run.
fn refuse(comptime fmt: []const u8, args: anytype) void {
if (!@import("builtin").is_test) std.log.err(fmt, args);
}

fn entry(ck: *const Checkpoint, name: []const u8) ?st.Entry {
for (ck.files.items) |*f| if (f.names.get(name)) |e| return e;
return null;
}
Loading