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 @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Qwen3.5 on Metal: the text-only server no longer keeps the vision tower stored between the language-model tensors in GPU memory, so the 2B holds 1.7 GiB instead of 2.3 GiB measured with `footprint` after load, with replies unchanged (#3407). Thanks to @jschmied.

- Server: `TENSORFOLD_REQUEST_JOURNAL=PATH` records each chat or completion request in three JSON lines (start, prepared, finish), so a request unfinished at a crash is flagged on the next start, one in flight at two crashes is refused with 400 `request_quarantined`, and `tools/replay_request.py` replays a journaled request and compares the reply's `tensorfold.token_sha256`; off unless set (#3221).

- CLI: `tensorfold config validate FILE` (source builds only, not `tensorfold-native`) reads a cluster.json with the same parser and 16 MiB limit the server uses, prints the node and model counts on success or every problem the parser collected, and exits 0, 1 or 2 without planning models or probing hosts; `cluster check` is unchanged (#3189). Thanks to @mvanhorn.
Expand Down
1 change: 1 addition & 0 deletions zig/src/families/qwen3_5/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,5 @@ pub const draw = draws.draw;

test {
_ = draws;
_ = @import("model.zig");
}
40 changes: 39 additions & 1 deletion zig/src/families/qwen3_5/model.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const shards = @import("../../core/checkpoint.zig");
const weights = @import("weights.zig");
const kernels = @import("kernels.zig");

/// The language model's tensors pack into their own buffer, not the file span between them that holds the vision tower.
fn never(_: []const u8, _: usize) bool {
return false;
}

pub const Model = struct {
gpa: std.mem.Allocator,
device: mtl.Device,
Expand All @@ -30,7 +35,7 @@ pub const Model = struct {
errdefer m.checkpoint.deinit();
const files = try shards.shardFiles(gpa, io, dir);
defer shards.freeShardFiles(gpa, files);
for (files) |path| try m.checkpoint.addFileSelected(m.device, path, "", "language_model.");
for (files) |path| try m.checkpoint.addFileSplit(m.device, path, "", "language_model.", never);
m.weights = try weights.load(&m.checkpoint, config.tied);
m.kernels = try kernels.load(m.device);
return m;
Expand All @@ -44,3 +49,36 @@ pub const Model = struct {
m.gpa.destroy(m);
}
};

test "the language model's tensors are held without the vision tower stored between them" {
if (comptime !@hasDecl(mtl.Device, "init")) return error.SkipZigTest;
const device = mtl.Device.init() catch return error.SkipZigTest;
defer device.deinit();
const gpa = std.testing.allocator;
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
// the order a Qwen3.5 checkpoint stores: a language-model tensor, the vision tower, then the next one
const header =
\\{"language_model.a":{"dtype":"BF16","shape":[2],"data_offsets":[0,4]},
\\ "vision_tower.x":{"dtype":"U8","shape":[4096],"data_offsets":[4,4100]},
\\ "language_model.b":{"dtype":"BF16","shape":[3],"data_offsets":[4100,4106]}}
;
var data: [8 + header.len + 4106]u8 = undefined;
std.mem.writeInt(u64, data[0..8], header.len, .little);
@memcpy(data[8..][0..header.len], header);
for (data[8 + header.len ..], 0..) |*b, i| b.* = @truncate(i);
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "model.safetensors", .data = &data });
const path = try std.fmt.allocPrintSentinel(gpa, ".zig-cache/tmp/{s}/model.safetensors", .{tmp.sub_path}, 0);
defer gpa.free(path);
var span = ckpt.Checkpoint.init(gpa);
defer span.deinit();
try span.addFileSelected(device, path, "", "language_model.");
try std.testing.expectEqual(@as(usize, 4106), span.residentBytes());
var packed_ = ckpt.Checkpoint.init(gpa);
defer packed_.deinit();
try packed_.addFileSplit(device, path, "", "language_model.", never);
try std.testing.expectEqual(@as(usize, ckpt.alignment + 6), packed_.residentBytes());
try std.testing.expect(!packed_.has("vision_tower.x"));
inline for (.{ "language_model.a", "language_model.b" }) |name|
try std.testing.expectEqualSlices(u16, (try span.get(name)).host(u16), (try packed_.get(name)).host(u16));
}
Loading