Skip to content

mlx_tf config: refuse an unknown model_type instead of serving it as Qwen3.5 - #6505

Merged
ashhart merged 3 commits into
ashhart:mainfrom
joshuaswarren:w93/mlxtf-model-type-refuse
Dec 5, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
joshuaswarren:w93/mlxtf-model-type-refuse

Conversation

@joshuaswarren

Copy link
Copy Markdown
Contributor

What this changes

parseJson in the mlx_tf engine defaulted any unrecognised model_type to the Qwen3.5 hybrid; a new architecture then served until a tensor read failed somewhere far from the cause. An unknown type is now refused with error.UnsupportedModelType at load. qwen3_vl, qwen3_5_vl and their *_text text-tower variants — the towers vision_config.zig already admits — still map to the hybrid; every recognised type is unchanged.

Checks on this head

  • Head commit: 931a1cd04
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 88 on base, 88 on head, 0 new findings.
  • Tests run:
    • zig build test-config-parse-host (new step, zig 0.17.0): 3/3 pass on this head. On the merge-base with only build.zig and the test file added, the same step fails 1/3 — the refusal test is red before the change.
    • New src/config_json_test.zig asserts every recognised model_type maps to its arch, an absent model_type keeps the hybrid default, qwen3_vl/qwen3_5_vl/qwen3_vl_text/qwen3_5_vl_text map to the hybrid, and qwen4_moe/phi4/gpt_oss are refused.
    • zig fmt --check on all touched files and git diff --check: clean.
  • CI: pending on this head.
  • Not run, and why: zig build test (the full mlx_tf suite) cannot compile on this Linux host — the test binary links Metal/Foundation/objc, and the same failure exists on the base. The host-capable coverage for this path is the test-config-parse-host step; the parser itself is platform-independent.

Receipt

  • Main against branch: n/a — the change is one dispatch line in config parsing. Admitted model_type values produce an identical ModelConfig (the new test asserts the arch mapping for every recognised type and the absent-key default), so there is no arithmetic path to A/B; the only behavioural delta is that configs which previously mis-served until a tensor-read error are refused at load.
  • Boxes it reaches: HF config.json parsing and loadAuto in the mlx_tf engine — every caller of parseJson.
  • New switch? None.
  • Environment: x86_64 Linux host, Zig 0.17.0 (.zig-version), no GPU; parse-level tests only.
  • Paths and platforms the change reaches, which I ran and which I could not: host unit tests run on Linux; Metal-dependent paths are not runnable here (same on the base).
  • Exactness: parsed output for every admitted type is unchanged — the test checks each recognised model_type maps to its previous arch.
  • Main against this branch, same machine and checkpoint: n/a, parse-only change.
  • Decode speed before and after: n/a, no kernel or arithmetic touched.
  • Speed claims: n/a.
  • Prompt speed: n/a.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

(Inference checklist skipped — this change does not touch the token path.)

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Landed in the same shape as my closed #6504 — this one's coverage is already solid. Two cases from my draft that might be worth adding, if you want them:

// model_type in text_config wins over the root's — real Qwen3.5 configs carry "qwen3_5_text" there
const nested = try parse("{\"model_type\":\"qwen3_5\",\"text_config\":{\"model_type\":\"qwen3_5_text\",\"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}}");
try std.testing.expectEqual(Arch.qwen35_hybrid, nested.arch);
// …and an unknown type hiding in text_config is still refused even when root is recognised
try std.testing.expectError(error.UnsupportedModelType, parse("{\"model_type\":\"qwen3_5\",\"text_config\":{\"model_type\":\"qwen4_moe\",\"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}}"));
// architectures-array Ergo detection is unaffected by the refusal branch
const ergo = try parse("{\"architectures\":[\"ErgoForCausalLM\"],\"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}");
try std.testing.expectEqual(Arch.ergo, ergo.arch);

The qwen3_vl_moe/qwen3_vl_moe_text spellings are already covered by your indexOf — only noting they'd exercise the MoE-VL corner in the table. Verified all of the above parse/refuse as written on aarch64 zig 0.17.0.

@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Host-only mlx_tf admission change: unknown model_type values outside the kept aliases and the Ergo override are refused before any weight loads, so a qwen4_moe folder no longer loads silently as a Qwen3.5 hybrid. Every admitted architecture parses as before, the new host test covers both, and no kernel or forward code changes.

  • Synthena

joshuaswarren and others added 3 commits December 5, 2026 17:28
…Qwen3.5

parseJson defaulted every unrecognised model_type to the Qwen3.5 hybrid;
a new architecture then served until a tensor read failed somewhere far
from the cause. An unknown type is now refused as UnsupportedModelType
up front. qwen3_vl/qwen3_5_vl and their *_text variants (the text towers
vision_config admits) count as the hybrid; everything else is refused.

Also hoist build.zig's test-filter option: it was declared twice (lines
82/101), which panics zig 0.17 on every build. And register
test-config-parse-host: config_json_test.zig checks every recognised
model_type maps to its arch, an absent field keeps the hybrid default,
and unknown types are refused.
@ashhart
ashhart force-pushed the w93/mlxtf-model-type-refuse branch from 0121138 to ee0ad03 Compare December 5, 2026 17:29
@ashhart
ashhart merged commit 796d98a into ashhart:main Dec 5, 2026
8 of 12 checks passed
ashhart pushed a commit that referenced this pull request Dec 5, 2026
@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Thank you @joshuaswarren. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mlx_tf: an unrecognised model_type loads silently as Qwen3.5 hybrid (qwen4_moe does today)

2 participants