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

- Release checks: the release privacy check walks the release tree in Zig instead of the shell `find`, so `check-release-paths` and packaging's stage check run one implementation on every host and `zig build test` passes them on native Windows; a symlink, an unreadable entry or a file given as the tree is refused, and the build-root argument is validated first, as before (#2614).

- Flash Next on Metal and HIP: a config.json with a legacy `rope_scaling` (YaRN) is now refused by name; a `rope_parameters` type other than default already was. LFM2 and Kolibri-1 now refuse both forms; these readers ran plain RoPE under them. Metal Flash Next still takes its long-context factor from `--context` (#2604, fixes part of #2562). Thanks to @jschmied.
- Linux: Nemotron's io_uring checkpoint reads no longer hang at shutdown after a failed read: a read that failed partway through a batch dropped the batch's later completions, so the loader waited for them forever; every reader that skips the page cache or reads aligned spans (row and state files, Engram rows, session restore, Qwen-VL tower reads, GLM's rewritten tensors) is now tested with a file that ends inside the span it asks for (#2608).
- Flash Next on Macs: a server that closes while replies wait in its queue now ends each of them even when it is short of memory. Before, a failed copy at close left those requests waiting for good (#2616).

Expand Down
3 changes: 3 additions & 0 deletions zig/build/flashnext_batch_host.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Source and lane regressions with a recording Metal boundary, no shader compiler or GPU work.
const std = @import("std");
pub fn tests(b: *std.Build, all: *std.Build.Step) void {
const rope = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("zig/src/families/flashnext/rope_refusal_test.zig"), .target = b.graph.host }) }));
b.step("test-flashnext-rope-host", "The Metal/HIP config reader refuses scaled RoPE and keeps plain configs' rotary").dependOn(&rope.step);
all.dependOn(&rope.step);
const memory = b.createModule(.{ .root_source_file = b.path("zig/src/families/flashnext/load_memory.zig"), .target = b.graph.host });
b.step("test-flashnext-memory-host", "Flash Next allocation floor and working-set refusal without shaders").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = memory })).step);
const metal = b.createModule(.{ .root_source_file = b.path("zig/flashnext_recording_metal.zig"), .target = b.graph.host });
Expand Down
14 changes: 13 additions & 1 deletion zig/src/families/flashnext/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ fn quantBlock(root: std.json.ObjectMap, text: std.json.ObjectMap) !std.json.Obje
return error.MissingAffineConfig;
}

/// The key asking for a RoPE other than plain (`--context` sets Metal's YaRN factor, never the config), or null.
fn scaledRope(text: std.json.ObjectMap, rope: std.json.ObjectMap) ?[]const u8 {
for ([_][2][]const u8{ .{ "rope_type", "rope_parameters.rope_type" }, .{ "type", "rope_parameters.type" } }) |k| if (rope.get(k[0])) |v| {
if (v != .string or !std.mem.eql(u8, v.string, "default")) return k[1];
};
if (text.get("rope_scaling")) |v| if (v != .null) return "rope_scaling";
return null;
}

pub fn parse(gpa: std.mem.Allocator, bytes: []const u8) !Config {
var parsed = try std.json.parseFromSlice(std.json.Value, gpa, bytes, .{});
errdefer parsed.deinit();
Expand All @@ -201,7 +210,10 @@ pub fn parse(gpa: std.mem.Allocator, bytes: []const u8) !Config {
const quant = try quantBlock(root, text);
if (quant.get("quant_method")) |v| if (v != .null and (v != .string or (!std.mem.eql(u8, v.string, "mlx") and !std.mem.eql(u8, v.string, "affine")))) return error.UnsupportedAffineMode;
const rope = if (text.get("rope_parameters")) |v| if (v == .null) std.json.ObjectMap.empty else try object(v) else std.json.ObjectMap.empty;
for ([_][]const u8{ "rope_type", "type" }) |key| if (rope.get(key)) |v| if (v != .string or !std.mem.eql(u8, v.string, "default")) return error.UnsupportedFlashRope;
if (scaledRope(text, rope)) |key| {
std.log.warn("Flash Next config.json: {s} asks for scaled RoPE (YaRN); this reader runs plain RoPE", .{key});
return error.UnsupportedFlashRope;
}
const hidden = try required(text, "hidden_size");
const heads = try required(text, "num_attention_heads");
const head_dim = if (text.get("head_dim")) |v| if (v == .null or (v == .integer and v.integer == 0)) hidden / heads else try integer(v) else hidden / heads;
Expand Down
26 changes: 26 additions & 0 deletions zig/src/families/flashnext/rope_refusal_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! The Metal/HIP reader refuses a config that asks for scaled RoPE; plain configs keep theta and rotary dims.
const std = @import("std");
const config = @import("config.zig");

test "scaled RoPE is refused in either form; plain and null rope_scaling keep theta and rotary dims" {
const a = std.testing.allocator;
const bytes = @embedFile("fixtures/config.json");
const plain = "\"rope_parameters\": {";
const keep = try std.mem.replaceOwned(u8, a, bytes, plain, "\"rope_scaling\": null, " ++ plain);
defer a.free(keep);
for ([_][]const u8{ bytes, keep }) |accepted| {
var c = try config.parse(a, accepted);
defer c.deinit();
try std.testing.expectEqual(@as(f64, 10_000_000), c.rope_theta);
try std.testing.expectEqual(@as(usize, 64), c.rotary_dim);
}
const yarn = "{\"rope_type\": \"yarn\", \"factor\": 4.0, \"original_max_position_embeddings\": 262144}";
for ([_][2][]const u8{
.{ "\"type\": \"default\"", "\"rope_type\": \"yarn\", \"factor\": 4.0, \"original_max_position_embeddings\": 262144" },
.{ plain, "\"rope_scaling\": " ++ yarn ++ ", " ++ plain },
}) |change| {
const changed = try std.mem.replaceOwned(u8, a, bytes, change[0], change[1]);
defer a.free(changed);
try std.testing.expectError(error.UnsupportedFlashRope, config.parse(a, changed));
}
}
35 changes: 35 additions & 0 deletions zig/src/families/kolibri1/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ fn setEos(c: *Config, ids: []const u32) !void {
c.eos_count = ids.len;
}

/// The key asking for a RoPE other than plain, or null.
fn scaledRope(o: std.json.ObjectMap) ?[]const u8 {
if (o.get("rope_parameters")) |p| if (p == .object) for ([_][2][]const u8{
.{ "rope_type", "rope_parameters.rope_type" },
.{ "type", "rope_parameters.type" },
}) |k| if (p.object.get(k[0])) |v| {
if (v != .string or !std.mem.eql(u8, v.string, "default")) return k[1];
};
if (o.get("rope_scaling")) |v| if (v != .null) return "rope_scaling";
return null;
}

/// config.json's text; a refusal's reason goes to `why`.
pub fn parse(allocator: std.mem.Allocator, text: []const u8, why: *Why) !Config {
var parsed = try std.json.parseFromSlice(std.json.Value, allocator, text, .{});
Expand Down Expand Up @@ -170,6 +182,10 @@ pub fn parse(allocator: std.mem.Allocator, text: []const u8, why: *Why) !Config
if (o.get("rope_parameters")) |v| if (v == .object) if (v.object.get("rope_theta")) |t| {
c.rope_theta = @floatCast(try number(t));
};
if (scaledRope(o)) |key| {
why.set("config.json's {s} asks for scaled RoPE (YaRN); Kolibri-1 runs plain RoPE", .{key});
return error.UnsupportedRope;
}
const types = o.get("layer_types") orelse {
why.set("config.json has no layer_types", .{});
return error.BadConfig;
Expand Down Expand Up @@ -282,6 +298,25 @@ test "refusals: not kolibri1, other quantization, normalised routing, other laye
try refused(short, error.BadConfig, "49 layers");
}

test "scaled RoPE is refused in either form; plain, default and null keep theta and head dim" {
const theta = "\"rope_theta\": 10000.0,";
const yarn = "{\"rope_type\": \"yarn\", \"rope_theta\": 10000.0, \"factor\": 4.0}";
const params = try replaced(theta, "\"rope_parameters\": " ++ yarn ++ ",");
defer std.testing.allocator.free(params);
try refused(params, error.UnsupportedRope, "rope_parameters.rope_type");
const legacy = try replaced(theta, theta ++ " \"rope_scaling\": " ++ yarn ++ ",");
defer std.testing.allocator.free(legacy);
try refused(legacy, error.UnsupportedRope, "rope_scaling");
const plain = try replaced(theta, "\"rope_parameters\": {\"rope_type\": \"default\", \"rope_theta\": 10000.0}, \"rope_scaling\": null,");
defer std.testing.allocator.free(plain);
for ([_][]const u8{ pinned, plain }) |text| {
var why: Why = .{};
const c = try parse(std.testing.allocator, text, &why);
try std.testing.expectEqual(@as(f32, 10000), c.rope_theta);
try std.testing.expectEqual(@as(usize, 128), c.head_dim);
}
}

test "rope_parameters' theta wins, and other shapes are refused before any kernel runs" {
const rope = try replaced("\"rope_theta\": 10000.0", "\"rope_theta\": 10000.0, \"rope_parameters\": {\"rope_theta\": 5e5}");
defer std.testing.allocator.free(rope);
Expand Down
30 changes: 30 additions & 0 deletions zig/src/families/lfm2/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ fn refusal(a: std.mem.Allocator, root: Object, nested: ?Object, text: Object) !?
.{ "no vocabulary", try int(text.get("vocab_size")) < 1 },
.{ "no MLP width (intermediate_size)", try int(text.get("intermediate_size")) < 1 },
.{ "no normalization epsilon", either(text, "norm_eps", "block_norm_eps") == null },
.{ "a rope_parameters.rope_type other than default (the kernels run plain RoPE)", scaledRope(text) },
.{ "a rope_scaling (the kernels run plain RoPE)", if (text.get("rope_scaling")) |v| v != .null else false },
};
var bad: std.ArrayList([]const u8) = .empty;
for (checks) |c| if (c[1]) try bad.append(a, c[0]);
Expand Down Expand Up @@ -167,6 +169,15 @@ fn ffnWidth(text: Object) !usize {
return std.math.lossyCast(usize, ffn);
}

/// Whether rope_parameters names a RoPE other than default, YaRN for one.
fn scaledRope(text: Object) bool {
const rope = object(text.get("rope_parameters")) orelse return false;
for ([_][]const u8{ "rope_type", "type" }) |key| if (rope.get(key)) |v| {
if (v != .string or !std.mem.eql(u8, v.string, "default")) return true;
};
return false;
}

fn theta(text: Object) !f64 {
const rope = text.get("rope_parameters");
if (truthy(rope)) return float(if (object(rope)) |o| o.get("rope_theta") else null);
Expand Down Expand Up @@ -438,6 +449,23 @@ test "a plain lfm2 text config reads without a vision tower; block_auto_adjust_f
try std.testing.expectEqual(6912, n.ffn);
}

test "a null rope_scaling or a default rope_type keeps theta; a theta-only config reads as before" {
const gpa = std.testing.allocator;
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const same = [_][]const [2][]const u8{
&.{.{ "\"rope_parameters\":", "\"rope_scaling\":null,\"rope_parameters\":" }},
&.{.{ "\"rope_type\":\"default\"", "\"type\":\"default\"" }},
&.{.{ "\"rope_parameters\":{\"rope_theta\":1000000,\"rope_type\":\"default\"}", "\"rope_theta\":1000000" }},
};
for (same) |change| {
var problem: []const u8 = "";
var c = (try Config.parse(gpa, try changed(arena.allocator(), change), &problem)).?;
defer c.deinit(gpa);
try std.testing.expectEqualSlices(f32, &.{ 1e6, 64 }, &.{ c.theta, @floatFromInt(c.dim) });
}
}

fn has(comptime what: []const u8) []const u8 {
return "TensorFold's LFM2 kernels cover Liquid AI's d1 decision checkpoints (LiquidAI/d1-3B); this one has " ++ what ++ ". " ++ own_model_help;
}
Expand All @@ -461,6 +489,8 @@ test "refusals list every problem in the checks' words and order" {
.{ &.{.{ "\"num_attention_heads\":32", "\"num_attention_heads\":30" }}, has("a hidden size that is not a whole number of heads") },
.{ &.{ .{ "\"vocab_size\":128000", "\"vocab_size\":0" }, .{ "\"intermediate_size\":10752", "\"intermediate_size\":0" } }, has("no vocabulary, no MLP width (intermediate_size)") },
.{ &.{ .{ "\"norm_eps\":", "\"unread_a\":" }, .{ "\"block_norm_eps\":", "\"unread_b\":" } }, has("no normalization epsilon") },
.{ &.{.{ "\"rope_type\":\"default\"", "\"rope_type\":\"yarn\",\"factor\":4.0" }}, has("a rope_parameters.rope_type other than default (the kernels run plain RoPE)") },
.{ &.{.{ "\"rope_parameters\":", "\"rope_scaling\":{\"rope_type\":\"yarn\",\"factor\":4.0},\"rope_parameters\":" }}, has("a rope_scaling (the kernels run plain RoPE)") },
.{ &.{.{ "\"model_type\":\"lfm2_vl\"", "\"model_type\":\"lfm2_vl\",\"quantization\":{\"bits\":4,\"group_size\":64}" }}, stores("MLX 4-bit, groups of 64") },
.{ &.{.{ "\"model_type\":\"lfm2\",", "\"model_type\":\"lfm2\",\"quantization_config\":{\"quant_method\":\"FP8\",\"quant_algo\":\"FP8_BLOCK\",\"bits\":8}," }}, stores("fp8 FP8_BLOCK (8-bit)") },
};
Expand Down
Loading