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

- mlx_tf: a `model_type` the engine does not know is refused with `UnsupportedModelType` instead of being served as a Qwen3.5 hybrid; the absent-key default and every recognised type are unchanged, and `qwen3_vl`/`qwen3_5_vl` text towers still map to the hybrid (#6505, fixes #6501).

- The B70 contract checks Qwen sparse attention selection order, counts and flags against a host oracle. (#6425).

- docs/myelin.md: the Day-0 admission and cache sections now match the code; Day-0 uses only an explicit cache directory and does not honour `--myelin-no-cache` yet (#6512).
Expand Down
16 changes: 14 additions & 2 deletions engines/mlx_tf/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,30 @@ pub fn build(b: *std.Build) void {
const bounds_test = b.addTest(.{ .root_module = bounds_mod, .filters = &.{"TFP5 header:"} });
b.step("test-tfq5-bounds-host", "Run TFQ5 header bounds tests without a GPU").dependOn(&b.addRunArtifact(bounds_test).step);

const test_filter = b.option([]const u8, "test-filter", "Only tests containing this text");
const mla_fixture = b.createModule(.{ .root_source_file = b.path("../../zig/mla_published_fixture.zig") });
const mla_tests = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/weights_mla_test.zig"),
.target = b.graph.host,
.optimize = .Debug,
.link_libc = true,
}), .filters = if (b.option([]const u8, "test-filter", "Only tests containing this text")) |filter| &.{filter} else &.{"MLA"} });
}), .filters = if (test_filter) |filter| &.{filter} else &.{"MLA"} });
mla_tests.root_module.addImport("mla_published_fixture", mla_fixture);
b.step("test-mla-host", "Check split-MLA assembly before device upload").dependOn(&b.addRunArtifact(mla_tests).step);

const config_parse_test = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/config_json_test.zig"),
.target = b.graph.host,
.optimize = .Debug,
.link_libc = true,
.imports = &.{.{ .name = "shaders", .module = shaders_mod }},
}), .filters = if (test_filter) |filter| &.{filter} else &.{} });
const config_parse_step = b.step("test-config-parse-host", "Check config.json arch selection and model_type refusal without Metal");
config_parse_step.dependOn(&b.addRunArtifact(config_parse_test).step);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(vision_step);
test_step.dependOn(config_parse_step);
const ergo_ref = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/ergo_ref_test.zig"),
.target = b.graph.host,
Expand All @@ -98,7 +110,7 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
.target = b.graph.host,
.optimize = .Debug,
}), .filters = if (b.option([]const u8, "test-filter", "Only tests containing this text")) |filter| &.{filter} else &.{} });
}), .filters = if (test_filter) |filter| &.{filter} else &.{} });
const pack_validate_step = b.step("test-pack-validate-host", "Check byte-backed pack sources without Metal");
pack_validate_step.dependOn(&b.addRunArtifact(pack_test).step);
const pack_experts_test = b.addTest(.{ .root_module = b.createModule(.{
Expand Down
8 changes: 7 additions & 1 deletion engines/mlx_tf/src/config_json.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ pub const Methods = struct {
const is_lfm2_moe = std.mem.eql(u8, mtype, "lfm2_moe");
const is_lfm = is_lfm2 or is_lfm2_moe;
const is_dense_attn = is_qwen2 or is_llama or is_mistral or is_mixtral or is_qwen3 or is_qwen3_moe or is_gemma or is_mla or is_glm or is_lfm;
const arch: Arch = if (is_ergo) .ergo else if (is_nemotron) .nemotron_h else if (is_dense_attn) .qwen2_dense else .qwen35_hybrid;
// vision_config admits any root model_type containing "qwen3_vl"/"qwen3_5_vl"; its text
// tower then parses here under names like "qwen3_vl_text" (Qwen3-VL) rather than the root's
const is_qwen35_vl = std.mem.indexOf(u8, mtype, "qwen3_vl") != null or std.mem.indexOf(u8, mtype, "qwen3_5_vl") != null;
const is_qwen35 = std.mem.eql(u8, mtype, "qwen3_5") or std.mem.eql(u8, mtype, "qwen3_5_text") or
is_qwen35_vl or is_qwen35_moe;
// an unrecognised model_type is refused by name, not served as a Qwen3.5 hybrid: a wrong architecture shows up later as a bad tensor
const arch: Arch = if (is_ergo) .ergo else if (is_nemotron) .nemotron_h else if (is_dense_attn) .qwen2_dense else if (is_qwen35) .qwen35_hybrid else return error.UnsupportedModelType;

const hidden_size = getUsize(tc, "hidden_size");
const num_heads = getUsize(tc, "num_attention_heads");
Expand Down
47 changes: 47 additions & 0 deletions engines/mlx_tf/src/config_json_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! Host parse tests for config_json.zig's architecture selection: recognised model_type
//! values keep their arch, a missing field keeps the Qwen3.5 hybrid default, and a
//! model_type the engine does not know is refused instead of falling through.
const std = @import("std");
const config_json = @import("config_json.zig");
const config = @import("config.zig");
const Arch = config.Arch;
const ModelConfig = config.ModelConfig;

const fields = "\"hidden_size\":1024,\"intermediate_size\":2816,\"num_hidden_layers\":4,\"vocab_size\":32000,\"num_attention_heads\":8,\"num_key_value_heads\":4,\"rms_norm_eps\":1e-5";

fn parse(mtype: ?[]const u8) !ModelConfig {
const a = std.testing.allocator;
const json = if (mtype) |t|
try std.fmt.allocPrint(a, "{{\"model_type\":\"{s}\",{s}}}", .{ t, fields })
else
try std.fmt.allocPrint(a, "{{{s}}}", .{fields});
defer a.free(json);
return config_json.Methods.parseJson(a, json);
}

test "config maps every recognised model_type to its arch" {
const hybrid = [_][]const u8{ "qwen3_5", "qwen3_5_text", "qwen3_5_moe", "qwen3_5_moe_text", "qwen3_next", "qwen3_6_moe", "qwen3_6_moe_text", "qwen3_vl", "qwen3_5_vl", "qwen3_vl_text", "qwen3_5_vl_text" };
for (hybrid) |t| {
const cfg = try parse(t);
try std.testing.expectEqual(Arch.qwen35_hybrid, cfg.arch);
}
const dense_attn = [_][]const u8{ "llama", "mistral", "mixtral", "qwen2", "qwen3", "qwen3_moe", "gemma2", "gemma3_text", "gemma4_unified", "deepseek_v2", "deepseek_v32", "glm4", "glm4_moe", "glm_moe_dsa", "lfm2_vl", "lfm2_moe" };
for (dense_attn) |t| {
const cfg = try parse(t);
try std.testing.expectEqual(Arch.qwen2_dense, cfg.arch);
}
try std.testing.expectEqual(Arch.nemotron_h, (try parse("nemotron_h")).arch);
try std.testing.expectEqual(Arch.ergo, (try parse("ergo")).arch);
}

test "config keeps the Qwen3.5 hybrid default when model_type is absent" {
const cfg = try parse(null);
try std.testing.expectEqual(Arch.qwen35_hybrid, cfg.arch);
}

test "config refuses a model_type it does not know, instead of serving it as Qwen3.5" {
const unknown = [_][]const u8{ "qwen4_moe", "qwen4_exp", "qwen4_exp_text", "qwen3_8", "made_up_arch" };
for (unknown) |t| {
try std.testing.expectError(error.UnsupportedModelType, parse(t));
}
}
1 change: 1 addition & 0 deletions lines/6505.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- mlx_tf: a `model_type` the engine does not know is refused with `UnsupportedModelType` instead of being served as a Qwen3.5 hybrid; the absent-key default and every recognised type are unchanged, and `qwen3_vl`/`qwen3_5_vl` text towers still map to the hybrid (#6505, fixes #6501).
Loading