transformers
e0aae61b - GGUF: uniform meta-time swap, no rename, bind kernels post-load

Commit
147 days ago
GGUF: uniform meta-time swap, no rename, bind kernels post-load Replace the rename-based swap plan with a uniform meta-time swap and post-load binding. The gguf_name -> hf_name mapping is no longer computed twice. - GgufLinear / GgufExperts take an optional quant_type: the swap creates uint8 placeholders sized from the Q4_K_M average (good enough for device_map memory estimation), and the exact quant type + metal kernels are bound post-load from the bytes that arrive (bind_after_load). Forward stays branch-free (compile). - GGUFQuantizedTensor.__torch_function__ now propagates quant_type through every subclass-preserving op (the loader's .to, the Q/K permute, the gate/up cat) so bind_after_load can read it back; these subclasses only exist during load. - replace_with_gguf_linear is a uniform swap (modules_to_not_convert + tied output embeddings skipped); the on-the-fly path passes its single config quant_type. load_checkpoint_state drops per-tensor work: a coarse metadata-only "all kernel-supported?" check gates the byte path vs full dequant. - postprocess_model reconciles: bind each module's kernels (from the bytes, or module_quant_types on reload), revert float-source Linears (MoE routers) to nn.Linear, and record module_quant_types for the save round-trip. It also drops the GGUF load-renames so save_pretrained writes HF names (the swapped model is now standard safetensors, re-swapped on reload) — fixes the round-trip. Validated on MPS: dense (qwen2) and MoE (qwen2moe: router revert + experts) swap generation, gemma2/nemotron/gemma3 de-offset conversion, on-the-fly swap, dequant-on-load, and save_pretrained -> from_pretrained round-trip; 64 fast tests.
Author
Parents
Loading