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

- Metal: Inkling 2 with a DFlash 2 drafter now saves and restores the drafter's lane state in the prompt cache, so warm cache hits restore the drafter alongside the target (#5032, thanks @gilby).

- `tensorfold info --hexagon FILE.gguf` checks a Gemma 4 E4B IT Q4_0 GGUF export against the Hexagon layout (architecture, text geometry and all 666 tensors) without the Qualcomm SDK; a match reports device execution as unverified, and a mismatch names the reason and exits with status 2 (#5475, thanks @tgerighty).

- Qwen3.8-27B on Metal: Q and K head norm and RoPE run as one `q27_qk_norm_rope` dispatch instead of two head-norm launches, the barrier between them and two RoPE launches, on every chip and pass, keys-only prompt tails included; on an M5 Ultra every cache row and `qa` byte and the served replies match the previous path (#2955, part of #2940).
Expand Down
22 changes: 9 additions & 13 deletions zig/src/families/inkling2/metal/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ const fwd = @import("forward.zig");
const Model = @import("model.zig").Model;
const snapshot = @import("snapshot.zig");
const img = @import("images.zig");
const dspark = @import("dspark.zig");
const dspark_state = @import("dspark_state.zig");
const drafter_snap = @import("drafter_snap.zig");
const cfg = @import("../config.zig");
const draws = @import("draw.zig");
const flight = @import("flight.zig");
const sample = @import("sample.zig");
const be = lanes.backend;

const SavedSnap = struct {
target: snapshot.Snap,
dspark: ?dspark_state.Snap = null,
};
pub const DrafterHandle = drafter_snap.Drafter;
pub const SavedSnap = drafter_snap.Saved;

pub const Options = struct { capacity: usize, streams: u32 = 4, budget: u64, images: ?img.Encoder = null, gpu_tokens: bool = false };
const shared_widths = [_]usize{ 24, 32, 48, 64 };
Expand Down Expand Up @@ -54,7 +51,7 @@ pub const Metal = struct {
shared: [shared_widths.len]lanes.config.Cost = undefined,
shared_timed: usize = 0,
tap_gen: u64 = 0,
drafter: ?*dspark.Drafter = null,
drafter: ?DrafterHandle = null,
verify_gen: u64 = 0,
pub var fail_first_draw_for_test: if (builtin.is_test) bool else void = if (builtin.is_test) false else {};

Expand Down Expand Up @@ -253,8 +250,8 @@ pub const Metal = struct {
try self.feed(cache, ids[cache.len..], stream, &pictures);
}

fn restoreSnap(self: *Metal, cache: *st.Cache, stream: *lanes.Stream, snap: *const SavedSnap) !void {
if (self.drafter) |d| try d.restoreSnap(stream, if (snap.dspark) |*ds| ds else null, snap.target.at);
pub fn restoreSnap(self: *Metal, cache: *st.Cache, stream: *lanes.Stream, snap: *const SavedSnap) !void {
if (self.drafter) |d| try d.restoreSnap(stream, if (snap.drafter) |*dr| dr else null, snap.target.at);
try snapshot.restore(cache, self.model.queue, &snap.target);
}

Expand Down Expand Up @@ -548,7 +545,7 @@ pub const Metal = struct {

pub fn snapBytes(ptr: *anyopaque, at: u32) u64 {
const self = cast(ptr);
return snapshot.bytes(at) + if (self.drafter != null) dspark_state.Snap.bytes(at) else 0;
return snapshot.bytes(at) + if (self.drafter) |d| d.snapBytes(at) else 0;
}

fn syncQueue(self: *Metal) !void {
Expand Down Expand Up @@ -578,7 +575,7 @@ pub const Metal = struct {
snap.* = .{ .target = try snapshot.save(self.model.device, self.model.queue, cache) };
errdefer snap.target.free();
if (self.drafter) |d| {
snap.dspark = try d.saveSnap(stream, at, cache.tap, self.tap_gen);
snap.drafter = try d.saveSnap(stream, at, cache.tap, self.tap_gen);
}
return snap;
}
Expand All @@ -589,8 +586,7 @@ pub const Metal = struct {

pub fn snapDrop(ptr: *anyopaque, saved: *anyopaque) void {
const snap: *SavedSnap = @ptrCast(@alignCast(saved));
if (snap.dspark) |*ds| ds.free();
snap.target.free();
snap.free();
cast(ptr).gpa.destroy(snap);
}
};
Expand Down
Loading
Loading