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

## Unreleased

- DeepSeek-V4.1-Flash-1017's release checkpoint is read as published (FP8 blocks, MXFP4 experts and the FP8 Engram table), with a manifest-checked Engram pack; the CUDA engine refuses it by name, as it runs EXL3 (#1705, part of #1676). Thanks to @gilby.

- Windows: the server loads the grammar library as `tfgrammar.dll`, so structured output and required or named tool calls serve there too (#1796, fixes #1789). Thanks to @wesley4546.

- With `TF_DSV41_PF_4K=1`, `aot-needs` also lists the 2,048-row prefill variants the forward still runs, so a pack built with it no longer fails its first operation with `MissingTritonVariant _kv_store … RING 4096` (#1683). Thanks to @jayleaton.
Expand All @@ -29,6 +31,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Spark 2.5 on CUDA: `TF_KV_SHARE=n` keeps prompts as the KV pool's pages in the shared prompt store, with at most n kept states, so a conversation resumes at the store's last 256-token mark from pages it already holds instead of a full copy. Unset or 0, nothing changes. The native CUDA adapter it uses is family-neutral; Kolibri-1 follows.

- DeepSeek-V4.1 reads the release checkpoint as published (`deepseek-ai/DeepSeek-V4.1-Flash-1017`): FP8 E4M3 blocks with 32x32 E8M0 scales, MXFP4 routed experts and the FP8 Engram table, beside the EXL3 trellises. `tf-dsv41-engram-pack pack` writes the release's Engram tables as row shards with a manifest (the source tensors, each table's SHA-256 and a seeded row sample), `manifest` writes one for tables packed earlier after checking sampled rows against the release, and the CUDA engine refuses a release checkpoint by name before loading it (#1705, for #1676).

- MOSS-Image's prompt encoder runs on Metal inside the `moss_image` family, in bf16 as published with fp32 sums where the reference sums, under the Metal kernel contract (`tf-kernel-contract --only "moss image"`).

- GLM-5.3-Flash on CUDA with `--vision`: `TF_GLM_VISION_HOST=1` keeps the vision tower's bf16 weights in pinned host memory mapped into the device and copies each unit into one device slot just before it runs, so rank 0 keeps 240 MiB for the tower instead of 1.05 GiB and every rank gets that room back for KV pages and the prompt cache (#1760). Unset, nothing changes.
Expand Down
10 changes: 10 additions & 0 deletions zig/build/dsv41_shared.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ pub fn steps(b: *std.Build) void {
b.step("test-dsv41-token-map", "PCG64 and Unicode normalization without Metal").dependOn(&token_tests.step);
const tool = b.addExecutable(.{ .name = "tf-dsv41-token-map", .root_module = builder });
b.step("compile-dsv41-token-map", "Compile actual token-map CLI without running or Metal").dependOn(&tool.step);
const pack_host = moduleAt(b, b.graph.host, .ReleaseSafe, "neutral.zig");
@import("dsv41_draft.zig").addImportsAt(b, pack_host, b.graph.host, .ReleaseSafe);
const pack_tool = b.addExecutable(.{ .name = "tf-dsv41-engram-pack", .root_module = b.createModule(.{
.root_source_file = b.path("zig/tools/dsv41_engram_pack.zig"),
.target = b.graph.host,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{.{ .name = "dsv41", .module = pack_host }},
}) });
b.step("dsv41-engram-pack", "Build and install tf-dsv41-engram-pack (release Engram tables to packed row shards)").dependOn(&b.addInstallArtifact(pack_tool, .{}).step);
}
67 changes: 58 additions & 9 deletions zig/src/families/deepseek_v41/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ pub const Rope = struct {
/// The attention a layer runs: sliding window only, KV source + indexer, own indexer on a source's keys, or reuse.
pub const Mode = enum { swa, full, reindex, reuse };

/// How the checkpoint stores its weights: the EXL3 trellises or the release's own FP8 blocks and MXFP4 experts.
pub const Format = enum { exl3, release_fp8 };

pub const Config = struct {
/// how the checkpoint stores its weights; the release's own format is admitted beside the EXL3 trellises
format: Format = .exl3,
vocab: u32 = 129280,
hidden: u32 = 5120,
layers: u32 = 40,
Expand Down Expand Up @@ -109,17 +114,25 @@ pub const Config = struct {
return parse(gpa, bytes);
}

/// How far a config.json is read: a full checkpoint, asset metadata, or a small backend checkpoint's shapes.
const Check = enum { checkpoint, metadata, shapes };

/// Checkpoint JSON (text_config, else top level); absent keys keep release values, unknown routing is refused.
pub fn parse(gpa: std.mem.Allocator, json: []const u8) !Config {
return parseWith(gpa, json, true);
return parseWith(gpa, json, .checkpoint);
}

/// CPU asset generation checks release geometry without admitting the checkpoint's matrix representation.
pub fn parseMetadata(gpa: std.mem.Allocator, json: []const u8) !Config {
return parseWith(gpa, json, false);
return parseWith(gpa, json, .metadata);
}

/// As `parse`, the release's shapes not required: a small checkpoint of the same format (a backend's smoke test).
pub fn parseShapes(gpa: std.mem.Allocator, json: []const u8) !Config {
return parseWith(gpa, json, .shapes);
}

fn parseWith(gpa: std.mem.Allocator, json: []const u8, checkpoint: bool) !Config {
fn parseWith(gpa: std.mem.Allocator, json: []const u8, check: Check) !Config {
const parsed = try std.json.parseFromSlice(std.json.Value, gpa, json, .{ .parse_numbers = false });
defer parsed.deinit();
if (parsed.value != .object) return error.BadConfig;
Expand Down Expand Up @@ -179,8 +192,12 @@ pub const Config = struct {
}
}
try c.validate();
if (checkpoint) try requireCheckpoint(top, text) else try requireMetadata(top, text);
try c.validateRelease();
switch (check) {
.checkpoint => c.format = try requireCheckpoint(top, text),
.metadata => try requireMetadata(top, text),
.shapes => c.format = try requireFormat(top),
}
if (check != .shapes) try c.validateRelease();
return c;
}

Expand Down Expand Up @@ -438,12 +455,27 @@ pub fn tiny() Config {
};
}

fn requireCheckpoint(top: std.json.ObjectMap, text: std.json.ObjectMap) !void {
/// The checkpoint's storage format, its shapes not required: a backend's small checkpoint admits it this way.
fn requireFormat(top: std.json.ObjectMap) !Format {
const model = top.get("model_type") orelse return error.MissingField;
if (model != .string or !std.mem.eql(u8, model.string, "deepseek_v41")) return error.UnsupportedCheckpoint;
const quant = top.get("quantization_config") orelse return error.MissingField;
try @import("checkpoint_metadata.zig").require(quant);
if (quant != .object) return error.BadConfig;
const method = quant.object.get("quant_method") orelse return error.MissingField;
if (method != .string) return error.UnsupportedCheckpoint;
if (std.mem.eql(u8, method.string, "exl3")) {
try @import("checkpoint_metadata.zig").require(quant);
return .exl3;
}
if (std.mem.eql(u8, method.string, "fp8")) return requireReleaseFp8(quant.object);
return error.UnsupportedCheckpoint;
}

/// A full checkpoint: the storage format, then the release's metadata.
fn requireCheckpoint(top: std.json.ObjectMap, text: std.json.ObjectMap) !Format {
const format = try requireFormat(top);
try requireMetadata(top, text);
return format;
}

fn requireMetadata(top: std.json.ObjectMap, text: std.json.ObjectMap) !void {
Expand All @@ -461,6 +493,21 @@ fn requireMetadata(top: std.json.ObjectMap, text: std.json.ObjectMap) !void {
if (kind != .string or !std.mem.eql(u8, kind.string, "yarn")) return error.UnsupportedArchitecture;
}

/// The release's own format: FP8 weights in 32x32 blocks with E8M0 scales, the routed experts in MXFP4.
fn requireReleaseFp8(quant: std.json.ObjectMap) !Format {
const block = quant.get("weight_block_size") orelse return error.UnsupportedCheckpoint;
if (block != .array or block.array.items.len != 2) return error.UnsupportedCheckpoint;
for (block.array.items) |v| {
const n = unsigned(u64, v) catch return error.UnsupportedCheckpoint;
if (n != 32) return error.UnsupportedCheckpoint;
}
const scale_fmt = quant.get("scale_fmt") orelse return error.UnsupportedCheckpoint;
if (scale_fmt != .string or !std.mem.eql(u8, scale_fmt.string, "ue8m0")) return error.UnsupportedCheckpoint;
const expert_dtype = quant.get("expert_dtype") orelse return error.UnsupportedCheckpoint;
if (expert_dtype != .string or !std.mem.eql(u8, expert_dtype.string, "fp4")) return error.UnsupportedCheckpoint;
return .release_fp8;
}

test "config integers retain exact unsigned boundaries and integral notation" {
try std.testing.expectEqual(@as(u32, 4294967295), try unsigned(u32, .{ .number_string = "4294967295" }));
try std.testing.expectEqual(@as(u64, 18446744073709551615), try unsigned(u64, .{ .number_string = "18446744073709551615.0" }));
Expand Down Expand Up @@ -491,13 +538,15 @@ test "Engram pad alias cannot override the admitted token id" {
try std.testing.expectError(error.BadConfig, Config.parse(a, conflict));
}

test "asset metadata preserves release checks without widening checkpoint admission" {
test "asset metadata preserves release checks, and the release's own config parses as its FP8 format" {
const a = std.testing.allocator;
const bytes = @embedFile("fixtures/flash1017-config.json");
const c = try Config.parseMetadata(a, bytes);
try std.testing.expectEqual(@as(u32, 99092), c.engram_compressed_vocab);
try std.testing.expectEqual(@as(u32, 5120), c.hidden);
try std.testing.expectError(error.MissingField, Config.parse(a, bytes));
// the release's own config parses for the backends that run it; the metadata path stays the asset generator's
const full = try Config.parse(a, bytes);
try std.testing.expectEqual(Format.release_fp8, full.format);
const missing = try std.mem.replaceOwned(u8, a, bytes, "engram_n_heads", "unused_engram_heads");
defer a.free(missing);
try std.testing.expectError(error.MissingField, Config.parseMetadata(a, missing));
Expand Down
22 changes: 22 additions & 0 deletions zig/src/families/deepseek_v41/cuda_format.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! The CUDA engine's checkpoint format gate: its kernels run EXL3 trellises, so a release FP8 pack is refused early.

const std = @import("std");
const Config = @import("config.zig").Config;

/// Why a release FP8-block checkpoint cannot run on the CUDA engine, and what to feed the engine instead.
pub const release_fp8_problem = "DeepSeek V4.1 CUDA: this checkpoint stores the release's own FP8 blocks and MXFP4 experts; the CUDA engine executes EXL3 trellises, so pack the checkpoint to EXL3 (or serve it on Metal) first";

/// The refusal's text for `c`, null when the checkpoint's format is one this engine runs.
pub fn problem(c: *const Config) ?[]const u8 {
return if (c.format == .release_fp8) release_fp8_problem else null;
}

test "the CUDA gate refuses a release checkpoint by name and admits the EXL3 one" {
const a = std.testing.allocator;
const exl3 = try Config.parse(a, @embedFile("fixtures/config.json"));
try std.testing.expect(problem(&exl3) == null);
const release = try Config.parse(a, @embedFile("fixtures/flash1017-config.json"));
const text = problem(&release).?;
try std.testing.expect(std.mem.indexOf(u8, text, "FP8") != null);
try std.testing.expect(std.mem.indexOf(u8, text, "EXL3") != null);
}
5 changes: 5 additions & 0 deletions zig/src/families/deepseek_v41/cuda_model.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ pub const Model = struct {
const world: u32 = @intCast(comm.world());
try @import("session_protocol.zig").preflight(&m.session.plan);
m.cfg = try Config.read(gpa, io, pack_dir);
// the release's FP8 blocks parse (Metal runs them); refused here, before any pack or launch on CUDA
if (@import("cuda_format.zig").problem(&m.cfg)) |text| {
if (!quiet) std.log.err("{s}", .{text});
return error.UnsupportedCheckpoint;
}
if (o.own_prefill) try @import("block_admission.zig").nativePrefill(&m.cfg, world);
m.pack = try Pack.open(gpa, io, pack_dir);
const backbone = if (o.layers) |ls| try a.dupe(u32, ls) else blk: {
Expand Down
1 change: 1 addition & 0 deletions zig/src/families/deepseek_v41/cuda_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test {
_ = @import("block_test.zig");
inline for (.{ @import("block.zig").Emitter, @import("block_attn.zig"), @import("block_index.zig"), @import("block_moe.zig"), @import("block_prefetch.zig"), @import("block_wide.zig"), @import("buffers.zig") }) |m| std.testing.refAllDecls(m);
_ = @import("catalog_test.zig");
_ = @import("cuda_format.zig");
_ = @import("launch_bounds_test.zig");
inline for (.{ dk, dk.Kernels, dk.dense, dk.dense.Functions, dk.dense.Ops, dk.exl3, dk.exl3.Functions, dk.exl3.Ops, dk.ops, dk.ops.Functions, dk.ops.Ops, dk.replay, dk.kv_glue.Ops, dk.sampling }) |m| std.testing.refAllDecls(m);
}
Loading
Loading