Repository navigation
Description
Summary
qwen3_next could not load or run any real mlx-community checkpoint (verified with mlx-community/Qwen3-Next-80B-A3B-Instruct-4bit). Two independent, pre-existing bugs, both invisible to the synthetic-shape unit tests, surfaced only on a real-model run. The model had apparently never been validated end to end on a real checkpoint.
Bug 1: MoE expert leaf naming uses Mixtral w1/w2/w3
SwitchGLU::from_weights (src/models/qwen3_next.rs) and the MoE stacking in sanitize_weights used w1/w3/w2 leaf names under ...mlp.switch_mlp. Real qwen3_next checkpoints (and mlx-lm) store experts as gate_proj/up_proj/down_proj (stacked under switch_mlp.{proj} or unstacked under experts.{i}.{proj}). Result: Error: Missing weight: model.layers.0.mlp.switch_mlp.w1. The shared src/models/switch_layers.rs SwitchGLU already defaults to gate/up/down; qwen3_next's hand-rolled copy diverged.
Bug 2: gated-delta layout uses -1 slice stop (truncates by one)
build_projection_layout (src/models/qwen3_next_helpers.rs) set z_range/a_range stops to -1. Those ranges are fed to raw mlxcel_core::slice, where a stop of -1 means dim_size - 1 (drops the last element), NOT "to end". So the z (and a) slice came out one column short; reshaping z to v_shape then failed at layer 0: [reshape] Cannot reshape array of size 53040 into shape (1,13,31,128) (53040 = [1,13,16,255] instead of [1,13,16,256]). Note: mlxcel_core::utils::slice_axis treats -1 as "to end", but raw slice does not; mixing the two mental models is the root cause.
Fix
- SwitchGLU::from_weights + sanitize_weights: use
gate_proj/up_proj/down_projleaf names. - build_projection_layout: explicit
z_range = (2*dn + v_size, 2*dn + 2*v_size)anda_range = (b_size, 2*b_size)(no-1). - Update
qwen3_next_helpers_tests.rsexpectations (they asserted the buggy-1).
Validation
mlx-community/Qwen3-Next-80B-A3B-Instruct-4bit(44.9 GB, fits a 128 GB M1 Ultra): loads, generates coherently, and single-process (dense) vs--pp-size 2outputs match at temperature 0.- The larger real DSA checkpoints for the sibling deferrals (DeepSeek-V3.2 ~378 GB, GLM-5 ~418 GB) exceed 128 GB unified memory and are not runnable on this hardware.
Impact
Unblocks real-model use of qwen3_next, including the pipeline-parallel stage support added in #510 (its logic was only synthetic-CI-validated).
Files
- src/models/qwen3_next.rs
- src/models/qwen3_next_helpers.rs
- src/models/qwen3_next_helpers_tests.rs
Activity