Repository navigation
[Bugfix][Model Loader] Run post-load processing for raw Tensorizer weights - #55318
nicole-lihui wants to merge 1 commit into
Conversation
Reuse the shared loading lifecycle so raw/HF weights have the state required by forward. Keep native tensorized restoration unchanged. Refs vllm-project#55198 Co-authored-by: Codex <noreply@openai.com> Signed-off-by: nicole-lihui <nicole.li@daocloud.io>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughTensorizerLoader now delegates non-vLLM tensorized model loading to ChangesTensorizer loading
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to Raw Tensorizer checkpoints now receive the shared post-load preparation required for CPU linear inference, with regression coverage confirming the first forward matches the source model. No current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This looks totally LLM generated. By the way, even for the raw Huggingface path, why did you remove the call to |
… hook Several models finalized weight-derived state from inside load_weights, from forward(), or not at all. BaseModelLoader.load_model already dispatches the model's process_weights_after_loading once per cold load, including dummy loads, which never call load_weights. Move that work to the hook so every cold load path runs it exactly once after all weights are in place. Moved to process_weights_after_loading: - Kimi-K3 MTP: MegaMoE finalize_weights (was in load_weights). - DeepSeek-V4 (NVIDIA and XPU) target, MTP and DSpark: finalize_mega_moe_weights (was in load_weights). The VL wrapper drops its finalizes_weights_during_load handshake and always delegates the hook. - MiniCPM-V/O: moving the resampler to the device (was in load_weights, so a dummy load left pos_embed on CPU and the first forward failed). - OpenPangu: the text root and the MTP model sweep post_weight_load over submodules; the VL root delegates to its language model. The MTP model previously never refreshed its sink keys after loading. OpenPanguModel.load_weights keeps its own sweep. Removed lazy fallbacks: - Kimi-K3 and DeepSeek-V4 XPU MegaMoE forward() and DeepSeek-V4 NVIDIA get_expert_weights() no longer call finalize_weights(); they assert that the transformed weights exist. The NVIDIA MegaMoE shared-expert fusion now always sees scales the linear hook has already packed, which the parent commit makes correct. DeepSeek-V4.1 still finalizes inside load_weights: its mega-attention finalize permutes the wq_b / wo_a weight scales in place, and running it after the linear hook is not verified yet. Loaders: - TensorizerLoader: a raw (not vLLM-serialized) tensorizer checkpoint now loads through BaseModelLoader.load_model instead of a private helper that called model.load_weights and returned, skipping per-layer quant processing and the model hook. Block-FP8 checkpoints crashed in their first forward on that path. Delegating also builds the model from the passed model_config and honours load_config.device, as other loaders do. Same change and test as vllm-project#55318. - BaseModelLoader.load_weights documents that a cold load bypassing load_model must dispatch the hook itself, and the vLLM-serialized tensorizer exception. - finalize_layerwise_reload gets a typed signature and a docstring stating it does not dispatch the model hook. Also: drop a no-op token_map.to() in Medusa whose result was discarded, and move the DeepSeek-V4 VL wrapper tests out of the ROCm-gated file. Co-authored-by: nicole-lihui <44200120+nicole-lihui@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: aoshen02 <aoshen@inferact.ai>
Purpose
Raw/Hugging Face Tensorizer checkpoints can load their weights successfully but
return a model with state required by forward still uninitialized. For example,
a CPU
UnquantizedLinearMethodfails withAttributeError: 'Linear' object has no attribute 'cpu_linear'.Route the non-vLLM-tensorized branch through
BaseModelLoader.load_modelandremove its separate loading helper. This reuses the existing weight iterator
and shared post-load lifecycle before returning the model. The native
vLLM-tensorized path is unchanged; its state-restoration and eval behavior are
outside this PR's scope.
Refs #55198.
The shared path also honors
model_configandload_config.device, includingonline-quantization finalization when applicable. Calling the existing
load_weightsadds one format-detection read on the raw path.Duplicate-work checks on 2026-09-04 found no open PR implementing this fix
(
55198 in:body,Tensorizer post-load, andTensorizerLoader). #42823 excludesTensorizer; #37677 addresses storage URIs. The issue has a contributor's
expression of interest; this PR is limited to the reproduced raw/HF failure.
Test Plan
The regression writes a real Tensorizer file, loads it through the public loader,
and compares the first forward with the source module. It replaces full-model
construction with a tiny module and uses vLLM's real CPU linear method. CPU
selection is local to the test so accelerator CI hosts can also execute it.
VLLM_TARGET_DEVICE=cpu .venv/bin/python -m pytest \ tests/model_executor/model_loader/tensorizer_loader/test_tensorizer.py \ -k 'deserialized_hf_weights_are_ready_for_forward or tensorize_vllm_model_shuts_down_engine' -q .venv/bin/pre-commit run --files \ vllm/model_executor/model_loader/tensorizer_loader.py \ tests/model_executor/model_loader/tensorizer_loader/test_tensorizer.py .venv/bin/pre-commit run mypy-3.12 --hook-stage manual --files \ vllm/model_executor/model_loader/tensorizer_loader.py \ tests/model_executor/model_loader/tensorizer_loader/test_tensorizer.pyExisting full-model comparison for the standard test environment:
Test Result
9cd956c7e6: 1 failed atforward with missing
cpu_linear. The baseline loader was loaded in memory,with its model factory forwarded to the same tiny-model test factory.
Tensorizer 2.10.1, cached
facebook/opt-125m. HF and raw Tensorizer-loaded vLLMgenerated identical outputs for four prompts, up to 50 greedy tokens each.
The existing test used the public resource settings shown below.
binary. No C++ source or dependency changes are included.
Reproduce the local CPU full-model comparison
The default memory fraction exceeded this machine's available memory. The local
run used 256 MiB KV cache, eight sequences, a 1,024-token batch limit, and eager
execution. The test body, loading, kernels, and output assertions were unchanged.
The executed local helper was
.venv/bin/python dist/contribute-pr/issue-55198/run_cpu_model_regression.py.That investigation file is excluded from the commit. For another checkout, save
the equivalent helper below as
run_cpu_tensorizer_test.pyat the repository rootand run
.venv/bin/python run_cpu_tensorizer_test.pyafter caching OPT-125m:AI assistance: Codex assisted with investigation, implementation, regression-test
design, and local validation.
Essential elements