fix(module): fall back to .inner-qualified key when loading quantized safetensors #1
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/load-safetensors-inner-key-remap-onmain"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
QuantizedEmbedding/QuantizedLinearwrap their real weight in a#[param] inner: Embedding/inner: Linearfield, so the flattened Rust param path is<path>.inner.weight, while mlx-community checkpoints store it flat as<path>.weight.Module::load_safetensorsonly did an exact-match lookup with no else/error branch, so any such key silently matched nothing -- the quantized weight stayed attry_into_quantized's throwaway random-init value (correct shape/dtype, so it loads and runs without error), whilescales/biases(whose names have no such prefix mismatch) loaded correctly. Net effect: every quantized linear/embedding in a loaded model produced plausible-shaped but semantically wrong output.Qwen3-Embedding-8B-4bit-DWQcheckpoint by comparing rawdequantize()output (correct, bit-exact vs. a known-good Pythonmlx_embeddingsreference) against the full model's output (wrong) -- isolating the bug to weight loading, not the dequantization math..innerinserted before the final segment before giving up.Test plan
cargo test -p mlx-rs-- newinner_qualified_keyunit tests passmlx-lm'sload_qwen3_model, before vs. after this fix -- cosine similarity between semantically related sentences went from ~0.02 (near-random) to 0.73 (matching a Pythonmlx_embeddingsreference to 3 decimal places)