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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel
- HIP: the OCR families share one host protocol, with the same replies (#2040). Thanks to @laudney.
- `THIRD_PARTY_NOTICES.md` names the model release and library code that five sets of files follow, with the LFM Open License text.

- Persisted prompt states include the resolved profile values that can affect a family's arithmetic or experimental/debug path. Changing one moves the disk namespace, so the first long prompt under that setting prefills again; an unset boolean and an explicit 0 share the same key. Native CUDA and the four Metal persistence owners use the same scoped helper. Qwen and Flash Next on CUDA have such rows even with nothing set, so their disk states from before this version aren't reused: the first long prompt after upgrading prefills again (#2131).

- Lane host: the paged KV pool's promises now count in the host's one ledger, with no change in behaviour (#2127). Thanks to @jschmied.

- Qwen3.5 on HIP: the prompt conv writes q, k and v to their own rows, which drops 144 of the 27B's 160 column copies, with the same results (#2117). Thanks to @AbrahamCete.
Expand Down
27 changes: 27 additions & 0 deletions docs/recipes/persisted-profile-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Persisted prompt keys and reviewed profile values

The native disk identities call `zig/src/native/disk_identity.zig`'s profile helper. It visits every registered entry whose class is arithmetic, experimental or debug and whose family/backend scope applies. CUDA passes the loaded Nemotron model_type or the generic registered family name; the Metal owners pass their family and metal backend, with Qwen distinguishing dense and routed configurations. No eligible entries means the helper leaves its input hash unchanged.

Environment values take precedence over the entry's stable default, as in the profile resolver. Exact-one booleans resolve to0 or1, so unset and explicit0 share a key. Counts use their numeric value, including equivalent decimal spellings; absent counts default to0. Auto values default to auto. Entries with special reporting values retain their explicit/default distinction. Malformed counts retain their raw value in a separate hash domain; this helper introduces no new startup refusal.

Names, classes and resolved values are length-framed, with family/backend and a format tag. A changed relevant value gives a new namespace. The old files remain under their old identity; the first long prompt for the new namespace prefills again. State bytes, token matching, kernels and serving defaults are unchanged.

The supplied main has no arithmetic-class entry. The regression therefore supplies a clearly marked fake arithmetic row, with an isolated environment callback, to the actual CUDA identity function and recording driver. It verifies unset=0, unset!=1, a same-key reopen hit and a changed-key persisted-index miss. Other tests cover all non-identical classes, every applicable row, defaults and out-of-scope/identical controls. This is a host contract, not qualification of a real arithmetic switch or device. TF_QWEN_REQUEST_STARTS is a separate contribution (#2176).

## Audit of the supplied main

The table covers the common native disk owners. Numeric token-prefix matching, chunk starts, decoded spans and image identity are shared preconditions, so tokenizer/template filenames need not independently invalidate identical numeric state. A tokenizer or template change that changes those inputs misses through the shared matcher. This is a prompt-state cache, with no stored rendered reply.

| Owner | Source/checkpoint binding already present | Arithmetic and KV form | Tokenizer/template, adapters and learned epoch | Remaining gap or fix |
| --- | --- | --- | --- | --- |
| CUDA Nemotron and generic kept-state families | Embedded CUDA strings, optional aot.json, device/driver, family facts, fixed probe; checkpoint config/index and safetensors stamps | Family facts/probe plus this helper for every applicable non-identical profile entry | Shared exact numeric prefix/modes/images; loaded-family ownership; learner clear barrier | Profile omission fixed here. Full executable/captured-cubin binding remains in the separate source-binding follow-up #2163. |
| Metal Qwen dense/routed host | Main and drafter config/index/shard stamps, runtime/shared source texts, OS/chip and probe | Tensor-unit/ANE/drafter facts, probe and this helper | Same shared matching and learner barrier; drafter checkpoint included | Profile omission fixed here. Complete executable/layout binding belongs to #2163. |
| Metal Nemotron | Config/index/shard stamps, MTP header, kernel source hash, OS/chip and probe | Chunk/head facts, attention precision, probe and this helper | Same shared matching and learner barrier | Profile omission fixed here. Complete host/shared source binding belongs to #2163. |
| Metal GLM | Config/index model hash, kernel source hash, OS/chip and probe | TP, chunk rows, EP presence, probe and this helper | Same shared matching and learner barrier | Profile omission fixed here. Current supplied main still lacks shard-payload stamp binding at this owner; checkpoint/source follow-up #2163 handles it. |
| Metal Flash Next | Prepared checkpoint identity, selected source hash, OS/chip and probe | Three loaded mode bits, probe and this helper | Same shared matching and learner barrier | Profile omission fixed here. Current main still needs current shard stamps, complete loaded variant/policy and executable binding from #2163. |

The shared matcher is `prompt_imprint.Imprint.best` plus `prompt_cache.Store`'s decoded-span/image checks. The live learned epoch is an invalidation barrier: `lane_host_learn.zig` clears the cache after changed learning steps; `Store.clear` stops disk writes, expires states and detaches both disk stores. It is not a persisted epoch counter. Supported weight commits move checkpoint stamps before a later process opens a store. This change does not introduce an external adapter loader; adapter-specific cross-process reuse remains unqualified.

DeepSeek reference sessions use fresh-start behavior rather than these common disk owners; adapters without a disk attachment have no cross-process store in this scope. The source-binding follow-up is separate from this profile fix. No claim that the supplied main closes every #2131 gap follows from the table.

Host checks: `zig build test-disk-identity-host test-cuda-disk-open-host check-native-cuda-host compile-disk-identity-metal-host -j1`. The Metal step only emits an object for the four real identity bodies and their probes; it has no shader producer or execution step. Actual model/device resume-versus-fresh qualification remains required separately.
4 changes: 1 addition & 3 deletions zig/build/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ pub fn hostTests(b: *std.Build, draft_ids: *std.Build.Module, build_options: *st
for ([_]*std.Build.Module{ native, mods.nemotron }) |m| safety.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = &.{"kv safety:"} })).step);
b.step("test-cache-capacity-host", "Startup cache capacity facts and warnings without a GPU").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = native, .filters = &.{"cache capacity:"} })).step);
b.step("test-snap-fork-host", "CUDA prompt-cache rules: no fork marks unless a family sets snap_fork, its marks when it does").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = native, .filters = &.{"snap fork:"} })).step);
const disk_open = b.addRunArtifact(b.addTest(.{ .root_module = native, .filters = &.{"CUDA disk open:"} }));
b.step("test-cuda-disk-open-host", "CUDA's disk store takes --spill-gib's mode and --checkpoint-slots").dependOn(&disk_open.step);
step.dependOn(&disk_open.step);
@import("disk_identity_host.zig").steps(b, native, step);
const merge_checks = b.step("test-kv-merge-host", "KV page integration with landed snapshot modes and budgets");
for ([_]*std.Build.Module{ native, mods.nemotron }) |m| merge_checks.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = &.{"kv merge:"} })).step);
const nemo_safety = b.step("test-nemotron-learning-host", "Actual Nemotron CUDA close, checked pocket reads and retry under fake driver failures");
Expand Down
18 changes: 18 additions & 0 deletions zig/build/disk_identity_host.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Persistence identities and disk-open options under recording drivers, without shader producers.
const std = @import("std");
pub fn steps(b: *std.Build, native: *std.Build.Module, all: *std.Build.Step) void {
const open = b.addRunArtifact(b.addTest(.{ .root_module = native, .filters = &.{"CUDA disk open:"} }));
b.step("test-cuda-disk-open-host", "CUDA's disk store takes --spill-gib's mode and --checkpoint-slots").dependOn(&open.step);
all.dependOn(&open.step);
const identity = b.addRunArtifact(b.addTest(.{ .root_module = native, .filters = &.{"disk identity:"} }));
b.step("test-disk-identity-host", "Actual CUDA identity, resolved profile values and stale disk misses").dependOn(&identity.step);
all.dependOn(&identity.step);
}

/// Compile the actual four Metal identity bodies without a shader producer, link or execution.
pub fn metal(b: *std.Build, metal_module: *std.Build.Module, engine: *std.Build.Module, api: *std.Build.Module) void {
const root = b.createModule(.{ .root_source_file = b.path("zig/disk_identity_metal_compile.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{ .{ .name = "metal", .module = metal_module }, .{ .name = "tensorfold", .module = engine }, .{ .name = "engine_api", .module = api } } });
const object = b.addObject(.{ .name = "disk-identity-metal-host", .root_module = root });
_ = object.getEmittedBin();
b.step("compile-disk-identity-metal-host", "Compile four production Metal persistence identities without shaders").dependOn(&object.step);
}
1 change: 1 addition & 0 deletions zig/build/gemma4_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub fn compileHost(b: *std.Build, metal: *std.Build.Module, engine: *std.Build.M
b.step("compile-gemma4-contract-host", "Compile normal contract runner, family hooks and reflection without a metallib").dependOn(&contract_object.step);
b.step("test-glm-disk-charge-host", "Actual GLM snapshot save/read byte accounting without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = engine, .filters = &.{"GLM disk charge:"} })).step);
const api = b.createModule(.{ .root_source_file = b.path("zig/src/core/engine_api.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{.{ .name = "lanes", .module = lanes }} });
@import("disk_identity_host.zig").metal(b, metal, engine, api);
const host = b.createModule(.{ .root_source_file = b.path("zig/src/native/gemma4.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{ .{ .name = "metal", .module = metal }, .{ .name = "tensorfold", .module = engine }, .{ .name = "engine_api", .module = api } } });
const root = b.createModule(.{ .root_source_file = b.path("zig/gemma4_host_compile.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{ .{ .name = "host", .module = host }, .{ .name = "tensorfold", .module = engine } } });
const object = b.addObject(.{ .name = "gemma4-host-compile", .root_module = root });
Expand Down
7 changes: 7 additions & 0 deletions zig/disk_identity_metal_compile.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Compile the actual Metal identities and their probe callers; never execute a device or compile shaders.
export fn compiledDiskIdentities() usize {
return @intFromPtr(&@import("src/native/metal_identity.zig").learned) ^
@intFromPtr(&@import("src/native/qwen27_disk.zig").identity) ^
@intFromPtr(&@import("src/native/glm_disk.zig").identity) ^
@intFromPtr(&@import("src/native/flashnext_disk.zig").identity);
}
1 change: 1 addition & 0 deletions zig/src/native/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ test {
_ = kv_pages;
_ = drafted;
_ = cuda_disk; // its tests run under test-cuda-disk-open-host's filter
_ = @import("cuda_disk_identity_test.zig");
}
test "Learner ownership: actual native close drains Nemotron before any source, trainer or parent free" {
try @import("nemotron_trainer_test.zig").run(Host, Host.serve, Host.close, false);
Expand Down
11 changes: 6 additions & 5 deletions zig/src/native/cuda_disk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ fn whole(_: *anyopaque, saved: api.prompt_cache.Saved) bool {
}

/// What disk states are read under: the checkpoint, kernels (ours or a captured set), driver, device, a probe's bits.
pub fn identity(a: Allocator, io: std.Io, g: *const cuda.Context, dir: []const u8, kernels: ?[]const u8, backend: lanes.backend.Backend, t: *Target) !struct { id: u64, rate: f64 } {
pub fn identity(a: Allocator, io: std.Io, g: *const cuda.Context, dir: []const u8, kernels: ?[]const u8, backend: lanes.backend.Backend, t: *Target, family: []const u8) !struct { id: u64, rate: f64 } {
const p = try probe(a, io, backend, t);
return .{ .id = try identityOf(a, io, g, dir, kernels, &[_]u64{@intFromBool(t.head != null)}, p.hash), .rate = p.rate };
return .{ .id = try identityOf(a, io, g, dir, kernels, &[_]u64{@intFromBool(t.head != null)}, p.hash, .{ .family = family, .backend = "cuda" }), .rate = p.rate };
}

/// The identity's hash: the checkpoint, kernels, device, driver, a family's facts, then its probe's hash.
pub fn identityOf(a: Allocator, io: std.Io, g: *const cuda.Context, dir: []const u8, kernels: ?[]const u8, facts: []const u64, probed: u64) !u64 {
pub fn identityOf(a: Allocator, io: std.Io, g: *const cuda.Context, dir: []const u8, kernels: ?[]const u8, facts: []const u64, probed: u64, profile: disk_identity.Profile) !u64 {
var h = std.hash.Wyhash.init(0x6375);
try disk_identity.checkpoint(&h, a, io, dir);
inline for (comptime std.meta.declarations(cuda.kernels)) |d| {
Expand All @@ -109,6 +109,7 @@ pub fn identityOf(a: Allocator, io: std.Io, g: *const cuda.Context, dir: []const
h.update(std.mem.sliceAsBytes(&device));
h.update(std.mem.sliceAsBytes(facts));
h.update(std.mem.asBytes(&probed));
disk_identity.profile(&h, profile);
return h.final();
}

Expand Down Expand Up @@ -153,7 +154,7 @@ fn probe(a: Allocator, io: std.Io, backend: lanes.backend.Backend, t: *Target) !
/// --learn-conversations: the identity probed on this thread (its context current), the store opened and attached.
pub fn attach(a: Allocator, io: std.Io, ctx: *const cuda.Context, o: api.Open, root: []const u8, kernels: ?[]const u8, loaded: anytype, store: *api.prompt_cache.Store) !void {
loaded.target.ctx = ctx;
const id = try identity(a, io, ctx, o.dir, kernels, loaded.backend, loaded.target);
const id = try identity(a, io, ctx, o.dir, kernels, loaded.backend, loaded.target, o.model_type);
try open(o, root, id.id, id.rate, store, "nemotron");
}

Expand All @@ -170,7 +171,7 @@ pub fn attachKept(comptime K: type, name: []const u8, a: Allocator, io: std.Io,
const p = try K.probe(a, io, loaded.backend, loaded.target);
const facts = K.facts(loaded.target); // an array, or a slice
const list: []const u64 = if (@typeInfo(@TypeOf(facts)) == .pointer) facts else &facts;
try open(o, root, try identityOf(a, io, ctx, o.dir, kernels, list, p.hash), p.rate, store, name);
try open(o, root, try identityOf(a, io, ctx, o.dir, kernels, list, p.hash, .{ .family = name, .backend = "cuda" }), p.rate, store, name);
}
}

Expand Down
Loading
Loading