diff --git a/CHANGELOG.md b/CHANGELOG.md index a27f38c20af..ee63d79f284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel ## Unreleased +- CUDA and HIP: one core gate decides `--vision` at startup: `--vision` on a checkpoint without a vision tower is refused as "--vision given but this checkpoint has no vision tower", on Qwen3.5 on HIP (which served text) and Flash Next on CUDA too; LFM2 on CUDA loads its tower only with `--vision`; a cluster model's `"vision"` that is not true or false is refused, and the System One picture refusal now says to start with `--vision` (#3456). Thanks to @jschmied. + +- Qwen 3.5 diagnostics: large output files are written in chunks of at most 256 MiB, with the same bytes in the same order (#4296). + - Inkling 2 on HIP: attention kernels under the kernel contract (#N). - Qwen3.6-35B-A3B on Metal: the text-only checkpoint serves on the routed expert path, `--vision` refuses it by name, and `tf-qwen27-run --stages DIR` writes each layer's stream for a float64 comparison (#3239). Thanks to @cshintov. diff --git a/build.zig b/build.zig index 7304591f567..2b9f55c4063 100644 --- a/build.zig +++ b/build.zig @@ -283,6 +283,7 @@ pub fn build(b: *std.Build) void { @import("zig/build/save_guard.zig").wire(b); @import("zig/build/cpu_contract.zig").steps(b, test_step); @import("zig/build/bf16_round.zig").wire(b, test_step); + @import("zig/build/chunked_write.zig").wire(b, test_step); @import("zig/build/qwen35_layers.zig").wire(b, test_step); @import("zig/build/dev_tools.zig").wire(b, target); @import("zig/build/profile.zig").wire(b, test_step); diff --git a/docs/vision.md b/docs/vision.md index fbcfe945414..a0d1f9c2e6f 100644 --- a/docs/vision.md +++ b/docs/vision.md @@ -159,6 +159,9 @@ that read images: GLM-5.3-Flash, Qwen3.8-27B, Qwen3.8 Flash Next, Gemma 4 [31B](recipes/gemma-4-native.md#images) and [12B](recipes/gemma-4-12b-native.md#images) and Step-5-Preview on one Mac, GLM-5.3-Flash on [CUDA ranks](recipes/glm-5.3-flash-cuda.md#requests) and Nemotron 3.5 Super VL on CUDA. Other native engines refuse the flag at startup. +On CUDA and HIP a tower loads only with `--vision`, d1-3B's pictures included; a checkpoint with a tower starts +text-only without it. `--vision` on a checkpoint without a tower is refused at startup as "--vision given but this + checkpoint has no vision tower" (core's gate, `zig/src/core/engine_vision.zig`), on Qwen3.5 HIP too. The CLI accepts explicit image budgets from 16 to 262,144 tokens; each engine still applies its own limits and memory admission. - Images arrive as `image_url` data URLs in user messages and tool results. With `--vision-urls` (it needs diff --git a/zig/build/chunked_write.zig b/zig/build/chunked_write.zig new file mode 100644 index 00000000000..b1ba764de70 --- /dev/null +++ b/zig/build/chunked_write.zig @@ -0,0 +1,9 @@ +//! Registers the chunked-writer host tests as `test-chunked-write`. +const std = @import("std"); + +pub fn wire(b: *std.Build, parent: *std.Build.Step) void { + const tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("zig/src/core/chunked_write_test_file.zig"), .target = b.graph.host }) }); + const step = b.step("test-chunked-write", "Bounded chunked output writes: cap respected, order preserved, the old one-shot path fails the enforcing sink"); + step.dependOn(&b.addRunArtifact(tests).step); + parent.dependOn(step); +} diff --git a/zig/build/hip.zig b/zig/build/hip.zig index 418bd4eabf7..5f2fed3ec87 100644 --- a/zig/build/hip.zig +++ b/zig/build/hip.zig @@ -311,7 +311,7 @@ fn checksExe(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil .target = target, .optimize = optimize, .link_libc = true, - .imports = &.{ .{ .name = "hip", .module = e.hip }, .{ .name = "qwen3_5", .module = e.family }, .{ .name = "lanes", .module = e.lanes }, .{ .name = "npy", .module = b.createModule(.{ .root_source_file = b.path("zig/npy_from_core.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "core", .module = e.hip.import_table.get("core").? }} }) } }, + .imports = &.{ .{ .name = "hip", .module = e.hip }, .{ .name = "core", .module = e.hip.import_table.get("core").? }, .{ .name = "qwen3_5", .module = e.family }, .{ .name = "lanes", .module = e.lanes }, .{ .name = "npy", .module = b.createModule(.{ .root_source_file = b.path("zig/npy_from_core.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "core", .module = e.hip.import_table.get("core").? }} }) } }, }) }); } fn clefExe(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, e: Engine) *std.Build.Step.Compile { diff --git a/zig/src/cluster/config.zig b/zig/src/cluster/config.zig index 231f8322db0..61db06ccd3a 100644 --- a/zig/src/cluster/config.zig +++ b/zig/src/cluster/config.zig @@ -344,7 +344,9 @@ fn models(a: Allocator, v: ?Value, probs: *Problems) ![]Model { if (str(o.get("mla"))) |split| { if (std.mem.eql(u8, split, "heads")) m.mla = .heads else if (std.mem.eql(u8, split, "streams")) m.mla = .streams else if (!std.mem.eql(u8, split, "auto")) probs.add("models.{s}.mla: \"heads\", \"streams\" or \"auto\"", .{id}); } - if (o.get("vision")) |b| m.vision = b == .bool and b.bool; + if (o.get("vision")) |b| { + if (b == .bool) m.vision = b.bool else probs.add("models.{s}.vision: true or false", .{id}); + } if (o.get("memory")) |mem| if (mem == .object) if (num(mem.object.get("margin_gb"))) |g| { m.margin = @intFromFloat(g * @as(f64, @floatFromInt(node.gib))); }; diff --git a/zig/src/cluster/config_test.zig b/zig/src/cluster/config_test.zig index c7b726dee42..6e20643db0f 100644 --- a/zig/src/cluster/config_test.zig +++ b/zig/src/cluster/config_test.zig @@ -104,6 +104,7 @@ test "every broken file names what to change" { try check(head ++ four ++ "\"models\":{\"k\":{\"path\":\"/m\",\"mode\":\"disaggregated\",\"prefill\":[\"c1\"],\"decode\":[\"c1\",\"zz\"]}}}", &.{ "both a prefill and a decode", "\"zz\" is not a node" }); try check(head ++ four ++ "\"models\":{\"k\":{\"path\":\"/m\",\"mode\":\"disaggregated\"}}}", &.{"needs \"prefill\" and \"decode\""}); try check(head ++ four ++ "\"models\":{\"k\":{\"nodes\":[\"m9\"],\"parallel\":{\"tensor\":\"many\"}}}}", &.{ "path: required", "\"m9\" is not a node", "or \"auto\"" }); + try check(head ++ four ++ "\"models\":{\"k\":{\"path\":\"/m\",\"nodes\":[\"c1\"],\"vision\":\"yes\"}}}", &.{"vision: true or false"}); try check("{\"cluster\":1}", &.{ "schema: must be", "nodes: at least one" }); try check("not json", &.{"not JSON"}); } diff --git a/zig/src/core/checkpoint_weights.zig b/zig/src/core/checkpoint_weights.zig index e6544d7d271..4238f7e7d44 100644 --- a/zig/src/core/checkpoint_weights.zig +++ b/zig/src/core/checkpoint_weights.zig @@ -1,10 +1,17 @@ -//! Header-based admission bytes for the text side and optional RADIO tower, including mixed shards. +//! Header-based admission bytes for the text side and an optional vision tower, including mixed shards. const std = @import("std"); const ck = @import("checkpoint.zig"); const st = @import("safetensors.zig"); +/// Tower and projector prefixes: RADIO's, then Qwen-VL's, Gemma 4's, LFM2-VL's, LightOn's, DeepSeek's and GLM's. +const vision_prefixes = [_][]const u8{ + "vision_model.", "vision_projector.", "mlp1.", "model.visual.", "visual.", + "vision_tower.", "model.vision_tower.", "vision_embedder.", "embed_vision.", "model.vision_model.", + "model.vision_encoder.", "model.vision_projection.", "vision.", +}; + pub fn visionTensor(name: []const u8) bool { - for ([_][]const u8{ "vision_model.", "vision_projector.", "mlp1." }) |p| + for (vision_prefixes) |p| if (std.mem.startsWith(u8, name, p)) return true; return false; } @@ -50,3 +57,10 @@ test "text admission excludes RADIO tensors even in a shared shard" { try std.testing.expectEqual(@as(u64, 8), try count(a, io, dir, false)); try std.testing.expectEqual(@as(u64, 24), try count(a, io, dir, true)); } + +test "every family's tower prefix is a vision tensor, and no text tensor of theirs is" { + for ([_][]const u8{ "model.visual.blocks.0.attn.qkv.weight", "vision_tower.blocks.0.norm1.weight", "vision.blocks.3.mlp.w1.weight", "model.vision_model.embeddings.patch_embedding.weight", "model.vision_tower.vision_model.post_layernorm.weight", "vision_embedder.patch_dense.weight", "model.vision_encoder.patch_conv.weight" }) |n| + try std.testing.expect(visionTensor(n)); + for ([_][]const u8{ "model.language_model.embed_tokens.weight", "language_model.model.layers.0.mlp.gate_proj.weight", "model.layers.0.self_attn.q_proj.weight", "backbone.layers.0.mixer.in_proj.weight", "lm_head.weight", "model.embed_tokens.weight", "mtp.layers.0.eh_proj.weight", "model.multi_modal_projector.linear_1.weight" }) |n| + try std.testing.expect(!visionTensor(n)); +} diff --git a/zig/src/core/chunked_write.zig b/zig/src/core/chunked_write.zig new file mode 100644 index 00000000000..b973eccffee --- /dev/null +++ b/zig/src/core/chunked_write.zig @@ -0,0 +1,36 @@ +//! XNU rejects individual writes larger than INT_MAX. +const std = @import("std"); + +/// Upper bound for a single write request, well under XNU's INT_MAX cap. +pub const max_write_bytes: usize = 1 << 28; // 256 MiB + +comptime { + std.debug.assert(max_write_bytes < std.math.maxInt(c_int)); +} + +/// Write bounded chunks; sink errors pass through, and a nonempty write with a zero cap refuses. +pub fn writeChunked(sink: anytype, bytes: []const u8, cap: usize) !void { + if (cap == 0 and bytes.len > 0) return error.ZeroWriteCap; + var at: usize = 0; + while (at < bytes.len) { + const n = @min(bytes.len - at, cap); + try sink.writeAll(bytes[at..][0..n]); + at += n; + } +} + +/// Write `bytes` to `sub_path` in bounded chunks; write errors pass through. +pub fn writeFileChunked(io: std.Io, dir: std.Io.Dir, sub_path: []const u8, bytes: []const u8) !void { + var file = try dir.createFile(io, sub_path, .{}); + defer file.close(io); + const FileSink = struct { + file: std.Io.File, + io: std.Io, + + fn writeAll(self: *@This(), chunk: []const u8) !void { + try self.file.writeStreamingAll(self.io, chunk); + } + }; + var sink = FileSink{ .file = file, .io = io }; + try writeChunked(&sink, bytes, max_write_bytes); +} diff --git a/zig/src/core/chunked_write_test_file.zig b/zig/src/core/chunked_write_test_file.zig new file mode 100644 index 00000000000..264709920f6 --- /dev/null +++ b/zig/src/core/chunked_write_test_file.zig @@ -0,0 +1,79 @@ +//! Regression tests for bounded output writes. +const std = @import("std"); +const cw = @import("chunked_write.zig"); + +const testing = std.testing; + +const LimitedSink = struct { + buf: std.ArrayList(u8), + cap: usize, + + const WriteError = error{ OutOfMemory, WriteTooLarge, ZeroWriteCap }; + + pub fn writeAll(self: *LimitedSink, bytes: []const u8) WriteError!void { + if (bytes.len > self.cap) return error.WriteTooLarge; + try self.buf.appendSlice(testing.allocator, bytes); + } +}; + +test "a zero cap refuses a nonempty buffer without progress" { + const zero = 0; + var sink = LimitedSink{ .buf = .empty, .cap = zero }; + defer sink.buf.deinit(testing.allocator); + + var data: [4]u8 = .{ 1, 2, 3, 4 }; + try testing.expectError(error.ZeroWriteCap, cw.writeChunked(&sink, &data, zero)); + try testing.expectEqual(@as(usize, 0), sink.buf.items.len); // no write happened + // an empty buffer is fine at a zero cap: nothing to write, nothing to refuse + try cw.writeChunked(&sink, &.{}, zero); + try testing.expectEqual(@as(usize, 0), sink.buf.items.len); +} + +test "chunked writes respect the cap and preserve order" { + const cap = 64; // injected cap: the test never allocates the production 256 MiB + var sink = LimitedSink{ .buf = .empty, .cap = cap }; + defer sink.buf.deinit(testing.allocator); + + var data: [cap + 1]u8 = undefined; + for (&data, 0..) |*b, i| b.* = @truncate(i * 31 + 7); + + try cw.writeChunked(&sink, &data, cap); + try testing.expectEqual(data.len, sink.buf.items.len); + try testing.expect(std.mem.eql(u8, sink.buf.items, &data)); +} + +test "a sink-refused request fails through the writer without flattening" { + var sink = LimitedSink{ .buf = .empty, .cap = 16 }; + defer sink.buf.deinit(testing.allocator); + + var big: [33]u8 = undefined; + @memset(&big, 1); + try testing.expectError(error.WriteTooLarge, cw.writeChunked(&sink, &big, 32)); +} + +test "empty and exact-cap buffers pass through" { + var sink = LimitedSink{ .buf = .empty, .cap = 16 }; + defer sink.buf.deinit(testing.allocator); + + try cw.writeChunked(&sink, "", 16); + try testing.expectEqual(@as(usize, 0), sink.buf.items.len); + + const exact = [_]u8{ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 }; + try cw.writeChunked(&sink, &exact, 16); + try testing.expect(std.mem.eql(u8, sink.buf.items, &exact)); +} + +test "writeFileChunked round-trips through the real file path" { + var single: std.Io.Threaded = .init_single_threaded; + defer single.deinit(); + const io = single.io(); + + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const data = "bounded file output"; + try cw.writeFileChunked(io, tmp.dir, "cw-roundtrip.bin", data); + + const result = try tmp.dir.readFileAlloc(io, "cw-roundtrip.bin", testing.allocator, .limited(data.len + 1)); + defer testing.allocator.free(result); + try testing.expectEqualSlices(u8, data, result); +} diff --git a/zig/src/core/engine_api.zig b/zig/src/core/engine_api.zig index a4ed9ccf238..af9cf2e24f7 100644 --- a/zig/src/core/engine_api.zig +++ b/zig/src/core/engine_api.zig @@ -46,6 +46,9 @@ pub const VideoOffer = vision_types.VideoOffer; pub const VisionOpen = vision_types.VisionOpen; pub const ImageShare = vision_types.ImageShare; pub const Size = vision_types.Size; +pub const visionGate = vision_types.gate; +pub const visionDeclared = vision_types.declared; +pub const visionWords = vision_types.words; pub const ocr = @import("engine_ocr.zig"); pub const SpeechRequest = @import("speech_api.zig").SpeechRequest; @@ -518,5 +521,6 @@ pub const save_guard = @import("save_guard"); test { _ = @import("engine_api_test.zig"); + _ = vision_types; _ = @import("engine_capabilities.zig"); } diff --git a/zig/src/core/engine_vision.zig b/zig/src/core/engine_vision.zig index 1f0ae2720c7..32daef60ec6 100644 --- a/zig/src/core/engine_vision.zig +++ b/zig/src/core/engine_vision.zig @@ -92,3 +92,48 @@ pub const VideoOffer = struct { /// --vision's limits (``Open.vision``); image_tokens_set: the flag given; image_share: --vision-image-share's value. pub const VisionOpen = struct { image_tokens: u32 = 4096, image_tokens_set: bool = false, max_images: u32 = 4, video_tokens: u32 = 16384, max_videos: u32 = 2, max_frames: u32 = 256, image_share: ImageShare = .request }; + +/// --vision against the checkpoint: given without a tower, refused by name; a tower without it stays unread. +pub fn gate(requested: bool, tower: bool) error{VisionWithoutTower}!bool { + if (requested and !tower) return error.VisionWithoutTower; + return requested; +} + +/// Whether config.json's bytes name a vision_config other than null; JSON that does not parse counts as one. +pub fn declared(a: Allocator, config: []const u8) bool { + const doc = std.json.parseFromSlice(std.json.Value, a, config, .{}) catch return true; + defer doc.deinit(); + if (doc.value != .object) return true; + const vc = doc.value.object.get("vision_config") orelse return false; + return vc != .null; +} + +/// The gate's words for `model` ("this LFM2 checkpoint"): one format in every family; null for any other error. +pub fn words(comptime model: []const u8, err: anyerror) ?[]const u8 { + return switch (err) { + error.VisionWithoutTower => "--vision given but " ++ model ++ " has no vision tower", + error.VisionNotLoaded => model ++ " has a vision tower; pass --vision to load it", + else => null, + }; +} + +test "the gate refuses --vision without a tower by name and leaves a tower unread without --vision" { + try std.testing.expectError(error.VisionWithoutTower, gate(true, false)); + try std.testing.expect(try gate(true, true)); + try std.testing.expect(!try gate(false, true)); + try std.testing.expect(!try gate(false, false)); + const m = "this X checkpoint"; + try std.testing.expectEqualStrings("--vision given but this X checkpoint has no vision tower", words(m, error.VisionWithoutTower).?); + try std.testing.expectEqualStrings("this X checkpoint has a vision tower; pass --vision to load it", words(m, error.VisionNotLoaded).?); + try std.testing.expect(words(m, error.OutOfMemory) == null); +} + +test "a vision_config is declared unless absent or null" { + const a = std.testing.allocator; + try std.testing.expect(declared(a, "{\"vision_config\":{\"depth\":2}}")); + try std.testing.expect(declared(a, "{\"vision_config\":[]}")); + try std.testing.expect(declared(a, "{\"vision_config\":\"x\"}")); + try std.testing.expect(!declared(a, "{\"vision_config\":null}")); + try std.testing.expect(!declared(a, "{\"text_config\":{}}")); + try std.testing.expect(declared(a, "not json")); +} diff --git a/zig/src/core/root.zig b/zig/src/core/root.zig index 9a428624b74..a93d8e4bfba 100644 --- a/zig/src/core/root.zig +++ b/zig/src/core/root.zig @@ -2,6 +2,7 @@ pub const startup_receipt = @import("profile").startup_receipt; pub const benchmark_group = @import("benchmark_group.zig"); +pub const chunked_write = @import("chunked_write.zig"); pub const weight_only = @import("weight_only.zig"); pub const profile = @import("profile"); pub const safetensors = @import("safetensors.zig"); diff --git a/zig/src/families/flashnext/cuda_images.zig b/zig/src/families/flashnext/cuda_images.zig index f7a105265d5..4297746bc2e 100644 --- a/zig/src/families/flashnext/cuda_images.zig +++ b/zig/src/families/flashnext/cuda_images.zig @@ -80,7 +80,8 @@ pub const Vision = struct { return switch (err) { error.BadImageLimits, error.BadImageCount => "image count or row budget exceeds the configured limits", error.BadImageGrid, error.BadImagePatches, error.BadImagePlaceholders => "image rows do not match the prompt placeholders", - error.NoVisionTower, error.BadVisionWidth, error.UnsupportedQwenVision => "unsupported Flash Next Qwen-VL tower configuration", + error.NoVisionTower => @import("engine_api").visionWords("this Flash Next checkpoint", error.VisionWithoutTower), + error.BadVisionWidth, error.UnsupportedQwenVision => "unsupported Flash Next Qwen-VL tower configuration", else => core.qwen_vl.geometry.problem(err), }; } diff --git a/zig/src/families/flashnext/cuda_lanes.zig b/zig/src/families/flashnext/cuda_lanes.zig index c715cd2f614..bc96b84e5bb 100644 --- a/zig/src/families/flashnext/cuda_lanes.zig +++ b/zig/src/families/flashnext/cuda_lanes.zig @@ -571,6 +571,7 @@ pub fn Namespace(comptime Tri: type) type { _ = @import("cuda_lanes_restore_test.zig").Cases(Cuda, Cuda.open, snaps.restore, dropLane); _ = @import("cuda_lanes_admission_test.zig").Cases(Cuda, Cuda.open, dropLane); _ = @import("cuda_score.zig").CapabilityCases(Cuda); + _ = @import("cuda_lanes_vision_test.zig").Cases(@This()); } test "a bad TF_FLASHNEXT_CHUNK, _CHUNK_SOLO or TF_FLASHNEXT_LOAD_THREADS is refused at load before the loader takes a stream, a module or a buffer" { diff --git a/zig/src/families/flashnext/cuda_lanes_bytes.zig b/zig/src/families/flashnext/cuda_lanes_bytes.zig index 45344947dc6..6044b73eccc 100644 --- a/zig/src/families/flashnext/cuda_lanes_bytes.zig +++ b/zig/src/families/flashnext/cuda_lanes_bytes.zig @@ -43,6 +43,6 @@ pub const worlds = struct { pub fn visionBytes(a: std.mem.Allocator, io: std.Io, dir: []const u8, rank: u32, _: u32) !u64 { if (rank != 0) return 0; const v = @import("qwen_vision"); - const c = ((try v.Settings.read(a, io, dir)) orelse return error.NoVisionTower).tower; + const c = ((try v.Settings.read(a, io, dir)) orelse return 0).tower; // no tower: open refuses --vision by name return v.Tower.weightBytes(c) + v.Tower.scratchBytes(c, v.max_patches); } diff --git a/zig/src/families/flashnext/cuda_lanes_explain.zig b/zig/src/families/flashnext/cuda_lanes_explain.zig index 51035bc9878..e6f732a84c1 100644 --- a/zig/src/families/flashnext/cuda_lanes_explain.zig +++ b/zig/src/families/flashnext/cuda_lanes_explain.zig @@ -8,6 +8,7 @@ pub fn open(err: anyerror) ?[]const u8 { error.FlashNextRanksOnCapturedGlue => "--tp 2 runs Flash Next's own glue, not a captured set: set TENSORFOLD_CUDA_KERNELS=native, or serve on one GPU", error.BadFlashNextKvPages, error.BadFlashNextPageTest, error.FlashNextPagesUnsupported, error.UnsupportedCheckpoint => explain(err), error.UnsupportedLearningFormat, error.TrainingOnCapturedGlue => explain(err), + error.VisionWithoutTower => @import("engine_api").visionWords("this Flash Next checkpoint", err), else => null, }; } diff --git a/zig/src/families/flashnext/cuda_lanes_load.zig b/zig/src/families/flashnext/cuda_lanes_load.zig index 5ad7e03cda5..7acec9e38c3 100644 --- a/zig/src/families/flashnext/cuda_lanes_load.zig +++ b/zig/src/families/flashnext/cuda_lanes_load.zig @@ -10,6 +10,8 @@ const images = @import("cuda_images.zig"); pub fn open(comptime F: type, gpa: std.mem.Allocator, io: std.Io, ctx: *const cuda.Context, dir: []const u8, captured: ?[]const u8, o: F.Options) !F.Loaded { try @import("env_validate.zig").startup(); if (o.vision) |v| try @import("qwen_vision").media.checkLimits(v); + // --vision on a checkpoint without a tower refuses by name (core's gate) before a stream or a weight loads + if (o.vision != null) _ = try @import("engine_api").visionGate(true, try @import("qwen_vision").Settings.read(gpa, io, dir) != null); var load_cache = @import("core").checkpoint.cache.Load.begin(io, o.tp > 1); defer load_cache.deinit(); const Cuda = F.Cuda; diff --git a/zig/src/families/flashnext/cuda_lanes_vision_test.zig b/zig/src/families/flashnext/cuda_lanes_vision_test.zig new file mode 100644 index 00000000000..a1d975d6176 --- /dev/null +++ b/zig/src/families/flashnext/cuda_lanes_vision_test.zig @@ -0,0 +1,24 @@ +//! --vision at Flash Next's CUDA open: refused by name by core's gate before the loader touches the driver. +const std = @import("std"); +const cuda = @import("cuda"); + +pub fn Cases(comptime F: type) type { + return struct { + test "--vision on a checkpoint without a vision tower is refused by name before a stream, a module or a buffer" { + const a = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "config.json", .data = "{\"model_type\":\"qwen3_5_moe\"}" }); + const dir = try tmp.dir.realPathFileAlloc(std.testing.io, ".", a); + defer a.free(dir); + // every driver entry point undefined: the refusal must come before the first call + var driver: cuda.Driver = undefined; + const ctx: cuda.Context = .{ .d = &driver, .device = 0, .handle = null }; + const o: F.Options = .{ .vision = .{ .image_tokens = 4096, .max_images = 4 }, .context = 4096, .drafts = true }; + try std.testing.expectError(error.VisionWithoutTower, F.open(a, std.testing.io, &ctx, dir, null, o)); + const words = @import("cuda_lanes_explain.zig").open(error.VisionWithoutTower).?; + try std.testing.expectEqualStrings("--vision given but this Flash Next checkpoint has no vision tower", words); + try std.testing.expectEqual(@as(u64, 0), try @import("cuda_lanes_bytes.zig").visionBytes(a, std.testing.io, dir)); + } + }; +} diff --git a/zig/src/families/lfm2/weights.zig b/zig/src/families/lfm2/weights.zig index 394b6ad2b61..9631d7e0a81 100644 --- a/zig/src/families/lfm2/weights.zig +++ b/zig/src/families/lfm2/weights.zig @@ -84,8 +84,8 @@ pub const Weights = struct { bytes: u64, memory: cuda.DeviceBuffer, - /// `dir`'s model.safetensors on the device as `plan` lays it out; a refusal is logged with its reason. - pub fn load(gpa: std.mem.Allocator, io: std.Io, d: *const cuda.Driver, dir: []const u8, cfg: *const Config) !Weights { + /// `dir`'s model.safetensors on the device as `plan` lays it out (the tower only with `tower`); refusals logged. + pub fn load(gpa: std.mem.Allocator, io: std.Io, d: *const cuda.Driver, dir: []const u8, cfg: *const Config, tower: bool) !Weights { const path = try std.fs.path.join(gpa, &.{ dir, "model.safetensors" }); defer gpa.free(path); var file = try core.safetensors.File.open(gpa, io, path); @@ -94,7 +94,7 @@ pub const Weights = struct { file.close(io); } var problem: []const u8 = ""; - var p = try plan(gpa, cfg, &file.names, &problem) orelse { + var p = try plan(gpa, cfg, &file.names, tower, &problem) orelse { defer gpa.free(problem); std.log.err("{s}", .{problem}); return error.UnreadableLfm2Checkpoint; @@ -158,9 +158,9 @@ fn shift(s: anytype, base: u64) void { const language = [_][]const u8{ "model.language_model.", "model.layers.", "model.embed" }; const projector = [_][]const u8{"model.multi_modal_projector."}; -/// Where every tensor `cfg` reads goes (host only), or null with `problem` (from `a`) saying why the header is refused. -pub fn plan(a: std.mem.Allocator, cfg: *const Config, header: *const Header, problem: *[]const u8) !?Plan { - var p: Planner = .{ .a = a, .header = header, .problem = problem }; +/// Where every tensor `cfg` reads goes (host only; its tower only with `tower`), or null with `problem` saying why not. +pub fn plan(a: std.mem.Allocator, cfg: *const Config, header: *const Header, tower: bool, problem: *[]const u8) !?Plan { + var p: Planner = .{ .a = a, .header = header, .problem = problem, .tower = tower }; p.build(cfg) catch |e| { p.out.deinit(a); return if (e == error.Refused) null else e; @@ -172,6 +172,7 @@ const Planner = struct { a: std.mem.Allocator, header: *const Header, problem: *[]const u8, + tower: bool, out: Plan = .{}, part: enum { language, vision } = .language, prefix_buf: [128]u8 = undefined, @@ -208,7 +209,9 @@ const Planner = struct { } } try p.unread(&language, p.out.pieces.items.len, "language tensor(s) the LFM2 kernels do not read"); - if (cfg.vision) |v| p.out.vision = try p.vision(cfg, v); + if (cfg.vision) |v| if (p.tower) { + p.out.vision = try p.vision(cfg, v); + }; } fn vision(p: *Planner, cfg: *const Config, v: config.Vision) !VisionWeights { @@ -413,7 +416,7 @@ test "plan stacks w1;w3 and q;k;v rows back to back on 256-byte boundaries, what const a = arena.allocator(); const header = try fakeHeader(a, &tiny_tensors, null); var problem: []const u8 = ""; - const p = (try plan(a, &tiny, &header, &problem)).?; + const p = (try plan(a, &tiny, &header, true, &problem)).?; try std.testing.expectEqual(tiny_tensors.len, p.pieces.items.len); try std.testing.expectEqualSlices(u64, &.{ 0, 256 }, &.{ p.embed, p.norm }); const conv, const attention = .{ p.layers[0], p.layers[1] }; @@ -456,18 +459,33 @@ test "a text-only checkpoint's model. names plan without a vision tower" { var cfg = tiny; cfg.vision = null; var problem: []const u8 = ""; - const p = (try plan(a, &cfg, &try fakeHeader(a, text.items, null), &problem)).?; + const p = (try plan(a, &cfg, &try fakeHeader(a, text.items, null), true, &problem)).?; try std.testing.expect(p.pieces.items.len == 21 and p.vision == null); try std.testing.expectEqualStrings("model.embed_tokens.weight", p.pieces.items[0].name); } +test "without --vision a VL checkpoint plans its language model alone: no tower byte is read or placed" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const header = try fakeHeader(a, &tiny_tensors, null); + var problem: []const u8 = ""; + const full = (try plan(a, &tiny, &header, true, &problem)).?; + const text = (try plan(a, &tiny, &header, false, &problem)).?; + try std.testing.expect(text.vision == null and text.pieces.items.len == 21); + for (text.pieces.items, full.pieces.items[0..21]) |t, f| try std.testing.expectEqualDeep(f, t); + try std.testing.expectEqual(full.pieces.items[20].dst + full.pieces.items[20].len, text.bytes); + // a tower the header lacks is no refusal without --vision: the planner never looks + try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tiny_tensors[0..21], null), false, &problem) != null); +} + /// The refusal `plan` gives for the tiny tensors less `drop`, plus `add`, with `f32_name` stored as f32. fn refusal(a: std.mem.Allocator, drop: ?[]const u8, add: ?Fake, f32_name: ?[]const u8) ![]const u8 { var tensors: std.ArrayList(Fake) = .empty; for (tiny_tensors) |t| if (drop == null or !std.mem.eql(u8, t[0], drop.?)) try tensors.append(a, t); if (add) |t| try tensors.append(a, t); var problem: []const u8 = ""; - try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tensors.items, f32_name), &problem) == null); + try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tensors.items, f32_name), true, &problem) == null); return problem; } @@ -492,8 +510,8 @@ test "plan refuses a missing, mistyped, misshapen or unread tensor by name" { try std.testing.expectEqualStrings("1 projector tensor(s) the LFM2-VL tower does not read: " ++ projector_norm, try refusal(a, null, .{ projector_norm, &.{16} }, null)); try std.testing.expectEqualStrings("layer_norm.weight is stored as f32, and the LFM2-VL tower reads bf16 weights", try refusal(a, null, .{ projector_norm, &.{16} }, projector_norm)); var problem: []const u8 = ""; - try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tiny_tensors[21..], null), &problem) == null); + try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tiny_tensors[21..], null), true, &problem) == null); try std.testing.expectEqualStrings("no language-model tensors in this checkpoint (a complete d1 checkpoint is needed)", problem); - try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tiny_tensors[0..21], null), &problem) == null); + try std.testing.expect(try plan(a, &tiny, &try fakeHeader(a, tiny_tensors[0..21], null), true, &problem) == null); try std.testing.expectEqualStrings("no vision tower tensors in this checkpoint, which its config's vision_config needs", problem); } diff --git a/zig/src/families/qwen3_5/backend/hip/engine/engine.zig b/zig/src/families/qwen3_5/backend/hip/engine/engine.zig index a92086d62cc..5e48045f30e 100644 --- a/zig/src/families/qwen3_5/backend/hip/engine/engine.zig +++ b/zig/src/families/qwen3_5/backend/hip/engine/engine.zig @@ -156,11 +156,12 @@ pub const Engine = struct { const e = try gpa.create(Engine); errdefer gpa.destroy(e); e.gpa = gpa; - // --vision on a checkpoint without a tower serves text, as before; an unreadable tower still refuses at open - const seen: @FieldType(Options, "vision") = if (o.vision == null) null else if (vision.Vision.config(gpa, io, dir)) |_| o.vision else |err| switch (err) { - error.NoQwenVision => null, + // --vision on a checkpoint without a tower refuses by name (core's gate); an unreadable tower refuses too + const tower = if (o.vision == null) false else if (vision.Vision.config(gpa, io, dir)) |_| true else |err| switch (err) { + error.NoQwenVision => false, else => return err, }; + const seen: @FieldType(Options, "vision") = if (try @import("engine_api").visionGate(o.vision != null, tower)) o.vision else null; e.o = o; e.o.prompt_rows = @max(o.prompt_rows, o.cut_rows); // a test's cut is one piece: the prompts arena holds it e.o.vision = seen; diff --git a/zig/src/families/qwen3_5/backend/hip/engine/native.zig b/zig/src/families/qwen3_5/backend/hip/engine/native.zig index 04fab43ecfa..66c30716938 100644 --- a/zig/src/families/qwen3_5/backend/hip/engine/native.zig +++ b/zig/src/families/qwen3_5/backend/hip/engine/native.zig @@ -1,5 +1,4 @@ //! Qwen3.5 / Qwen3.6 for the native server on HIP: the engine sized to GPU memory and the lane backend over it. - const std = @import("std"); const hip = @import("hip"); const lanes = @import("lanes"); @@ -226,6 +225,7 @@ fn prepare( "cannot read or parse /proc/meminfo's MemTotal and MemAvailable; refusing HIP unified-memory admission", .{}, ), + error.VisionWithoutTower => steps.refuseAll(a, problem, "{s}", .{@import("engine_api").visionWords("this Qwen3.5 checkpoint", err).?}), // the CUDA engine refuses these alike: --vision asks for images, so a tower it cannot read stops the start error.UnsupportedQwenVision => steps.refuseAll( a, diff --git a/zig/src/families/qwen3_5/backend/hip/engine/vision.zig b/zig/src/families/qwen3_5/backend/hip/engine/vision.zig index 3d30de8e402..ca64492d89c 100644 --- a/zig/src/families/qwen3_5/backend/hip/engine/vision.zig +++ b/zig/src/families/qwen3_5/backend/hip/engine/vision.zig @@ -24,19 +24,11 @@ pub const Vision = struct { defer arena.deinit(); const aa = arena.allocator(); const cfg = try read(aa, io, dir, "config.json") orelse return error.NoQwenVision; - if (!declared(aa, cfg)) return error.NoQwenVision; + if (!api.visionDeclared(aa, cfg)) return error.NoQwenVision; // a declared vision_config the parser cannot read is a broken tower, not a text checkpoint return try vl.Config.parse(aa, cfg, try read(aa, io, dir, "preprocessor_config.json"), try read(aa, io, dir, "processor_config.json")) orelse error.UnsupportedQwenVision; } - /// Whether config.json names a vision_config other than null: absent or null is a text-only checkpoint. - fn declared(a: std.mem.Allocator, cfg: []const u8) bool { - const doc = std.json.parseFromSliceLeaky(std.json.Value, a, cfg, .{}) catch return true; - if (doc != .object) return true; - const vc = doc.object.get("vision_config") orelse return false; - return vc != .null; - } - /// Aggregate image tokens also bound each independently encoded image; scratch is fixed at open. pub fn patchCapacity(limits: api.VisionOpen) !usize { if (limits.image_tokens == 0 or limits.image_tokens > shared.max_patches / 4 or limits.max_images == 0 or limits.max_images > 64) return error.BadImageLimits; @@ -262,14 +254,13 @@ test "Qwen HIP vision memory matches fixed weights and receipt/default scratch e } } -test "only an absent or null vision_config is a text-only checkpoint; another value is a broken tower" { - var arena = std.heap.ArenaAllocator.init(std.testing.allocator); - defer arena.deinit(); - const a = arena.allocator(); - try std.testing.expect(!Vision.declared(a, "{\"model_type\":\"qwen3_5\"}")); - try std.testing.expect(!Vision.declared(a, "{\"vision_config\":null}")); - try std.testing.expect(Vision.declared(a, "{\"vision_config\":[]}")); - try std.testing.expect(Vision.declared(a, "{\"vision_config\":\"x\"}")); - try std.testing.expect(Vision.declared(a, "{\"vision_config\":{}}")); - try std.testing.expect(Vision.declared(a, "not json")); +test "--vision on a checkpoint without a vision_config is refused by name before the HIP runtime opens" { + const a = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "config.json", .data = "{\"model_type\":\"qwen3_5\"}" }); + const dir = try tmp.dir.realPathFileAlloc(std.testing.io, ".", a); + defer a.free(dir); + // the runtime, the context and the weights open after the gate: a refusal here held none of them + try std.testing.expectError(error.VisionWithoutTower, @import("engine.zig").Engine.load(a, std.testing.io, dir, .{ .vision = .{} })); } diff --git a/zig/src/native/cuda_refusal.zig b/zig/src/native/cuda_refusal.zig index 88081b45b83..af2bd320fc7 100644 --- a/zig/src/native/cuda_refusal.zig +++ b/zig/src/native/cuda_refusal.zig @@ -42,9 +42,9 @@ pub fn backend(o: api.Open) ?[]const u8 { return null; } -/// LFM2 reads a checkpoint's pictures through its own tower without --vision: the flag is refused, not ignored. +/// LFM2 opens outside `family()`: its ranks are refused here, and --vision goes on to core's gate in its open. pub fn lfm2(o: api.Open) ?[]const u8 { - return if (o.vision != null) lfm2_vision else unranked(o); + return unranked(o); } pub const no_ranks = "this CUDA family has no tensor-parallel ranks: serve without --tp and --rank"; @@ -54,9 +54,6 @@ pub fn unranked(o: api.Open) ?[]const u8 { return if (o.tp != 1 or (o.given.rank and o.rank != 0)) no_ranks else null; } -const lfm2_vision = "--vision: LFM2 reads the checkpoint's images through its own tower without the flag; " ++ - "serve it without --vision"; - /// A given --rank below the world, as main's CLI refused it, and a world in the family's `worlds` when it lists them. pub fn place(comptime F: type, a: std.mem.Allocator, o: api.Open) !?[]const u8 { if (o.given.rank and o.rank >= o.tp) return try std.fmt.allocPrint(a, "argument --rank: {d} is not below --tp {d}", .{ o.rank, o.tp }); @@ -225,12 +222,15 @@ test "flags with nothing to do on CUDA are refused, not ignored" { try std.testing.expect(backend(.{ .dir = "d", .model_type = "nemotron_h", .prompt_cache_gib = 4 }) == null); } -test "--vision is each family's to take: Super VL reads images, LFM2 refuses the flag, the rest refuse at their open" { +test "--vision is each family's to take: LFM2 passes it on to core's gate at its open, its ranks are still refused" { for ([_][]const u8{ "nemotron_h", "nemotron_h_omni", "glm5_next", "lfm2_vl" }) |t| { try std.testing.expect(backend(.{ .dir = "d", .model_type = t, .vision = .{} }) == null); } - try std.testing.expectEqualStrings(lfm2_vision, lfm2(.{ .dir = "d", .model_type = "lfm2_vl", .vision = .{} }) orelse ""); + try std.testing.expect(lfm2(.{ .dir = "d", .model_type = "lfm2_vl", .vision = .{} }) == null); try std.testing.expect(lfm2(.{ .dir = "d", .model_type = "lfm2_vl" }) == null); + try std.testing.expectEqualStrings(no_ranks, lfm2(.{ .dir = "d", .model_type = "lfm2_vl", .vision = .{}, .tp = 2 }).?); + const one: api.Open = .{ .dir = "d", .model_type = "lfm2_vl", .vision = .{}, .rank = 1, .given = .{ .rank = true } }; + try std.testing.expectEqualStrings(no_ranks, lfm2(one).?); } test "--drafter opens only a family that takes one" { diff --git a/zig/src/native/lfm2.zig b/zig/src/native/lfm2.zig index f4e4d4b41fb..052b9b91063 100644 --- a/zig/src/native/lfm2.zig +++ b/zig/src/native/lfm2.zig @@ -162,6 +162,13 @@ pub fn open(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]c e.* = .{ .gpa = gpa, .io = io, .window = window, .driver = undefined, .ctx = undefined, .cfg = undefined, .weights = undefined, .model = undefined }; e.cfg = try lfm2.config.Config.load(gpa, io, o.dir, problem) orelse return null; errdefer e.cfg.deinit(gpa); + // --vision against the config's vision_config (core's gate): without it the tower stays on disk + const tower = api.visionGate(o.vision != null, e.cfg.vision != null) catch |err| { + problem.* = api.visionWords("this LFM2 checkpoint", err).?; + e.cfg.deinit(gpa); + gpa.destroy(e); + return null; + }; e.driver = cuda.Driver.open() catch |err| { problem.* = try std.fmt.allocPrint(a, "no CUDA driver ({s})", .{@errorName(err)}); return null; @@ -170,7 +177,7 @@ pub fn open(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]c e.ctx = try cuda.Context.init(&e.driver, 0); errdefer e.ctx.deinit(); try e.ctx.makeCurrent(); - e.weights = try lfm2.weights.Weights.load(gpa, io, &e.driver, o.dir, &e.cfg); + e.weights = try lfm2.weights.Weights.load(gpa, io, &e.driver, o.dir, &e.cfg, tower); errdefer e.weights.deinit(gpa); e.model = try lfm2.model.Model.init(gpa, &e.driver, &e.cfg, &e.weights, window); errdefer e.model.deinit(); diff --git a/zig/src/server/systemone.zig b/zig/src/server/systemone.zig index d2355a15d3c..b6a47cebf0f 100644 --- a/zig/src/server/systemone.zig +++ b/zig/src/server/systemone.zig @@ -62,6 +62,9 @@ pub fn post(srv: *Server, conn: *Conn, a: Allocator) void { routes.sendValue(conn, a, cx.status(), openai.wrapError(a, err) catch return); } +/// A server without pictures: its checkpoint has no tower, or it started without --vision (core's gate). +pub const no_pictures = "this server reads no pictures: start it with --vision on a checkpoint with a vision tower"; + /// The answers to a System One body, or its refusal. pub fn reply(srv: *Server, cx: *Cx, body: Value) errors.Refused!Value { const state = body.get("state") orelse return cx.refuse("a request needs a state (null when the question is the whole state)"); @@ -70,7 +73,7 @@ pub fn reply(srv: *Server, cx: *Cx, body: Value) errors.Refused!Value { if (raw_questions != .object or raw_questions.object.count() == 0) return cx.refuse("questions is a non-empty object of id: question"); const questions = try cx.a.alloc(Question, raw_questions.object.count()); for (raw_questions.object.keys(), raw_questions.object.values(), questions) |id, raw, *q| q.* = try parse(cx, id, raw); - if (seen.urls.len > 0 and !srv.engine.info().pictures) return cx.refuse("this checkpoint has no vision tower"); + if (seen.urls.len > 0 and !srv.engine.info().pictures) return cx.refuse(no_pictures); var f: Format = .{ .srv = srv, .cx = cx, .one = .init(cx.a) }; // with pictures the head and the state are encoded apart, the pictures' tokens between them (the processor's ids) diff --git a/zig/src/server/systemone_test.zig b/zig/src/server/systemone_test.zig index 47e3aabfeb8..80db61b202c 100644 --- a/zig/src/server/systemone_test.zig +++ b/zig/src/server/systemone_test.zig @@ -204,7 +204,7 @@ test "System One refuses in the goldens' words, before any scoring" { const pictured = "{\"state\": \"x\", \"images\": [\"data:image/png;base64,AA\"], \"questions\": {\"q\": {\"type\": \"noul\", \"instructions\": \"i\"}}}"; var cx: errors.Cx = .{ .a = a }; try std.testing.expectError(error.Refused, systemone.reply(srv, &cx, (try json.parse(a, pictured)).ok)); - try std.testing.expectEqualStrings("this checkpoint has no vision tower", cx.message); + try std.testing.expectEqualStrings(systemone.no_pictures, cx.message); head.window = 8; try std.testing.expectError(error.Refused, systemone.reply(srv, &cx, (try json.parse(a, answered[0].body)).ok)); try std.testing.expectEqualStrings("a decision sequence exceeds the 8-token context", cx.message); diff --git a/zig/src/tensorfold.zig b/zig/src/tensorfold.zig index fb87af6985f..8fb0c89bfe3 100644 --- a/zig/src/tensorfold.zig +++ b/zig/src/tensorfold.zig @@ -3,6 +3,7 @@ const std = @import("std"); pub const startup_receipt = @import("profile").startup_receipt; pub const benchmark_group = @import("core/benchmark_group.zig"); +pub const chunked_write = @import("core/chunked_write.zig"); pub const safetensors = @import("core/safetensors.zig"); /// torch.save archives and WAV files: Drama 3's codec and clips, through its `core` shim. pub const torch_pth = @import("core/torch_pth.zig"); diff --git a/zig/tests/cuda/lfm2_vision_tests.zig b/zig/tests/cuda/lfm2_vision_tests.zig index c32fb828514..0b8b0becd28 100644 --- a/zig/tests/cuda/lfm2_vision_tests.zig +++ b/zig/tests/cuda/lfm2_vision_tests.zig @@ -343,7 +343,7 @@ fn features(r: *Rig, model: []const u8) !void { return error.TestFailed; }; defer cfg.deinit(gpa); - var w = try lfm2.weights.Weights.load(gpa, io, r.gpu.d, model, &cfg); + var w = try lfm2.weights.Weights.load(gpa, io, r.gpu.d, model, &cfg, true); defer w.deinit(gpa); var v = try vision.Vision.init(gpa, r.gpu.d, &cfg, &(w.vision orelse return error.NoVisionTower)); defer v.deinit(); diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index f86ac9f2646..d8a05d7e543 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -127,11 +127,11 @@ zig/src/families/flashnext/cuda_gdn.zig bc952357f4d6c076542b419b0ee71bbdce89715f zig/src/families/flashnext/cuda_glue.zig 0bd837ea17d1bd0a7a0820dc0ee99c4da90113c15d62b3fac31bd7af47a0ecb1 raw zig/src/families/flashnext/cuda_hc.zig 01f897ac65d6edd2cd6ac76d97cb4d96619c25ffa85bd619d6d76f4f465cda9a raw zig/src/families/flashnext/cuda_head.zig 734cc1ccea8e99ce9a061273a2dd3042f32e4848b622b5de616aa4b6f546bdd4 raw #3749: TF_FLASHNEXT_SHARD_HEAD read through platform/environment.zig, blank as unset -zig/src/families/flashnext/cuda_images.zig ef78a0eb8403a73da2d19bd7ed2aa4b2349a191f408060da79bee3963cd56ff2 raw #3164 (a resumed prompt sends only the images past its kept state) +zig/src/families/flashnext/cuda_images.zig 4696ef29dc81f30882f964d69a71c5378b247bfb772b51b354569639bf5a8812 raw #3164 (a resumed prompt sends only the images past its kept state); #3164 (a resumed prompt sends only the images past its kept state); #3456: a checkpoint's vision tower loads only with --vision, images without it are refused by the shared gate; text replies are unchanged zig/src/families/flashnext/cuda_images_test.zig 4278e5241f6c7e0e710e9a8ddf0482855db158eeee2463200a2c2de32c9dadd7 raw #3164 (resumed image rows tested) -zig/src/families/flashnext/cuda_lanes.zig 7dd7869c638477f802860bbe15ab91853d253b839ff23a3cfa73f3cef2ec4de1 raw main 4f6017ced (marks inside the pass), fbca90714 (shared solo-chunk rule, #2391), 80e0fd72c (#2753: non-finite draft rows refused by name; finite rows unchanged), dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #1953: the ladder's values through snap_intermediate, #3308 (loader host test updates the named startup-refusal expectations; no runtime edit to this pinned file); #3135 (kept_disk renamed kept_view for the shared kept image; no served change), this change (the page pool opens with the load's device and io, for its arena mapped as pages are used; a new paged stream's first prompt step waits while the arena's thread maps its pieces; paging off: unchanged), #2917: one launch description and rank flags change this source; #3164 (resumed image rows passed to the tower), #3219, #2919 (the resolved rank and world reach visionBytes) +zig/src/families/flashnext/cuda_lanes.zig 0aa9e028693cff3c88253952ff82526da59879b9018a01951ad6c5cf3dacae5e raw main 4f6017ced (marks inside the pass), fbca90714 (shared solo-chunk rule, #2391), 80e0fd72c (#2753: non-finite draft rows refused by name; finite rows unchanged), dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #1953: the ladder's values through snap_intermediate, #3308 (loader host test updates the named startup-refusal expectations; no runtime edit to this pinned file); #3135 (kept_disk renamed kept_view for the shared kept image; no served change), this change (the page pool opens with the load's device and io, for its arena mapped as pages are used; a new paged stream's first prompt step waits while the arena's thread maps its pieces; paging off: unchanged), #2917: one launch description and rank flags change this source; #3164 (resumed image rows passed to the tower), #3219, #2919 (the resolved rank and world reach visionBytes) zig/src/families/flashnext/cuda_lanes_admission_test.zig a87b5320d8cda1f95d254c2148c849005c2158b70afb73da3e32b627e6d2f13d raw -zig/src/families/flashnext/cuda_lanes_load.zig 3911082a7e95c1ffdcf8f6662d2b7b8127112c66794065f2df00bf95fc638fcf raw main dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #3467: after load a shard drops its page cache except the n-gram ranges, and the sweep reaches nested shards; tensors and replies are unchanged, this change (the load's device and io handed to the page pool's arena; paging off: unchanged) +zig/src/families/flashnext/cuda_lanes_load.zig 872cf185ad0e928b565b7ba9222563b8519167e66c9db91033eeac078c492be2 raw main dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #3467: after load a shard drops its page cache except the n-gram ranges, and the sweep reaches nested shards; tensors and replies are unchanged, this change (the load's device and io handed to the page pool's arena; paging off: unchanged); main dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #3467: after load a shard drops its page cache except the n-gram ranges, and the sweep reaches nested shards; tensors and replies are unchanged, this change (the load's device and io handed to the page pool's arena; paging off: unchanged); #3456: a checkpoint's vision tower loads only with --vision, images without it are refused by the shared gate; text replies are unchanged zig/src/families/flashnext/cuda_lanes_restore_test.zig f9947521a6d9c7d7380ca1b784a93a43b364c6fa5861cad15efd3538d2b8ceff raw zig/src/families/flashnext/cuda_launch.zig f056079d88e9295455bf44bed7ed4053e55fdb8579cfdb392c31a4c3af18e73c raw exports cuda_moe_exchange.zig for its device test; no served change; #2837 (Flash Next TP=2 graph replay); #3413 exports cuda_tiles.zig and readout_fused.zig for their tests zig/src/families/flashnext/cuda_media.zig 394601e8a807f5516f501efcaefa6fb3308f392ee322db7296b11c90814f8eea raw diff --git a/zig/tests/qwen35/hidden_run.zig b/zig/tests/qwen35/hidden_run.zig index a78bd3d4f65..9ad43cb5b4c 100644 --- a/zig/tests/qwen35/hidden_run.zig +++ b/zig/tests/qwen35/hidden_run.zig @@ -2,6 +2,7 @@ const std = @import("std"); const hip = @import("hip"); +const core = @import("core"); const qwen35 = @import("qwen3_5"); const ids_file = @import("ids_file.zig"); @@ -96,7 +97,7 @@ pub fn run(gpa: std.mem.Allocator, io: std.Io, args: []const [:0]const u8) !void @memset(out[10 + dict.len ..][0..pad], ' '); out[head - 1] = '\n'; if (layers) try residuals(e, ids, out[head..]) else try rows(e, ids, cut, out[head..]); - try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = args[2], .data = out }); + try core.chunked_write.writeFileChunked(io, std.Io.Dir.cwd(), args[2], out); const what = if (layers) "layers' residual rows" else "final-norm rows"; std.debug.print("wrote {d} {s} x {d} ({s}, pieces of {d}) to {s}\n", .{ ids.len, what, m.spec.hidden, descr, piece, args[2] }); } diff --git a/zig/tests/qwen35/logits_run.zig b/zig/tests/qwen35/logits_run.zig index 61ac1c10870..12f210a2452 100644 --- a/zig/tests/qwen35/logits_run.zig +++ b/zig/tests/qwen35/logits_run.zig @@ -2,6 +2,7 @@ const std = @import("std"); const hip = @import("hip"); +const core = @import("core"); const qwen35 = @import("qwen3_5"); const ids_file = @import("ids_file.zig"); const Kind = @import("logit_kind.zig").Kind; @@ -115,6 +116,6 @@ pub fn run(gpa: std.mem.Allocator, io: std.Io, args: []const [:0]const u8) !void out[head - 1] = '\n'; var file: File = .{ .body = out[head..], .width = width }; try stream(gpa, e, ids, mode, .{ .ctx = &file, .put = File.put }); - try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = args[2], .data = out }); + try core.chunked_write.writeFileChunked(io, std.Io.Dir.cwd(), args[2], out); std.debug.print("wrote {d}{s} rows x {d} logits to {s}\n", .{ ids.len, if (mode.decode) " decoded" else "", vocab(e), args[2] }); } diff --git a/zig/tests/qwen35_cuda_main.zig b/zig/tests/qwen35_cuda_main.zig index b76da69e0b4..7356485459a 100644 --- a/zig/tests/qwen35_cuda_main.zig +++ b/zig/tests/qwen35_cuda_main.zig @@ -255,7 +255,7 @@ pub fn main(init: std.process.Init) !u8 { try out.appendSlice(a, copy.host.bytes[0..@intCast(copy.len)]); } else try out.appendSlice(a, std.mem.sliceAsBytes(cache.logits)); } - try std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = args[4], .data = out.items }); + try core.chunked_write.writeFileChunked(init.io, std.Io.Dir.cwd(), args[4], out.items); return 0; } diff --git a/zig/tests/qwen35_forward.zig b/zig/tests/qwen35_forward.zig index 1092dfedb0f..13fa3d8fa6c 100644 --- a/zig/tests/qwen35_forward.zig +++ b/zig/tests/qwen35_forward.zig @@ -31,6 +31,6 @@ pub fn main(init: std.process.Init) !void { @memcpy(out[at * q.config.vocab * 2 ..][0 .. n * q.config.vocab * 2], scratch.logits.contents()[0 .. n * q.config.vocab * 2]); at += n; } - try std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = args[3], .data = out }); + try tf.chunked_write.writeFileChunked(init.io, std.Io.Dir.cwd(), args[3], out); std.debug.print("native Qwen forward: {d} rows, bf16 logits, fp32 recurrent state\n", .{ids.len}); } diff --git a/zig/tests/qwen35_pipe.zig b/zig/tests/qwen35_pipe.zig index 3cf77043dd9..f257319e303 100644 --- a/zig/tests/qwen35_pipe.zig +++ b/zig/tests/qwen35_pipe.zig @@ -1,6 +1,7 @@ //! `tf-qwen35-cuda pipe [fp8]`: greedy streams decoded in `k` groups, one engine or a stage ring. const std = @import("std"); const cuda = @import("cuda"); +const core = @import("core"); const stage = @import("stage"); const q = @import("qwen35"); const E = q.engine; @@ -123,7 +124,7 @@ fn finish(init: std.process.Init, a: std.mem.Allocator, e: *E.Engine, lead: *S.L try lead.step(closes[0..set.streams], &.{}, .window); var out: std.ArrayList(u8) = .empty; for (streams) |x| try out.appendSlice(a, std.mem.sliceAsBytes(x.hist.items[set.prompt..][0..set.tokens])); - try std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = out_path, .data = out.items }); + try core.chunked_write.writeFileChunked(init.io, std.Io.Dir.cwd(), out_path, out.items); const ms = @as(f64, @floatFromInt(t2 - t1)) / 1e6; const made = @as(f64, @floatFromInt(set.streams * set.tokens)); std.debug.print("pipe {s}: {{\"streams\":{d},\"k\":{d},\"draft\":{d},\"prompt\":{d},\"tokens\":{d},\"prompt_ms\":{d:.1},\"decode_ms\":{d:.1},\"tok_s\":{d:.2},\"rounds\":{d},\"drafted\":{d},\"kept_drafts\":{d}}}\n", .{ role, set.streams, set.k, set.draft, set.prompt, set.tokens, @as(f64, @floatFromInt(t1 - t0)) / 1e6, ms, made * 1e3 / ms, rounds, drafted, taken }); diff --git a/zig/tests/qwen35_stage.zig b/zig/tests/qwen35_stage.zig index db64bff16c9..b0d7d2cb761 100644 --- a/zig/tests/qwen35_stage.zig +++ b/zig/tests/qwen35_stage.zig @@ -1,6 +1,7 @@ //! `tf-qwen35-cuda stage [fp8]`: one scenario's logits from one engine, or rank 0 of a stage ring. const std = @import("std"); const cuda = @import("cuda"); +const core = @import("core"); const stage = @import("stage"); const q = @import("qwen35"); const E = q.engine; @@ -79,7 +80,7 @@ fn finish(init: std.process.Init, a: std.mem.Allocator, e: *E.Engine, lead: *S.L for (toks) |t| std.debug.print(" {d}", .{t}); std.debug.print("\n", .{}); report(0, role); - try std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = out_path, .data = out.items }); + try core.chunked_write.writeFileChunked(init.io, std.Io.Dir.cwd(), out_path, out.items); return 0; }