From 9dd62d80abad5d2ebeb0a4a60ad005a23c23d0e9 Mon Sep 17 00:00:00 2001 From: wkutak Date: Mon, 20 Jul 2026 20:31:48 +0200 Subject: [PATCH] Cosmos3 FP8 ModelOpt/Diffusers remapping (#48952) Signed-off-by: Wojciech Kutak Signed-off-by: wkutak Signed-off-by: Isotr0py Co-authored-by: Isotr0py Co-authored-by: Roger Wang --- tests/models/multimodal/test_mapping.py | 38 +++++++++++++++++++++++++ vllm/model_executor/models/cosmos3.py | 5 ++++ 2 files changed, 43 insertions(+) diff --git a/tests/models/multimodal/test_mapping.py b/tests/models/multimodal/test_mapping.py index ce9b8a9d45..674ef731d8 100644 --- a/tests/models/multimodal/test_mapping.py +++ b/tests/models/multimodal/test_mapping.py @@ -74,6 +74,44 @@ def test_cosmos3_new_checkpoint_weights_mapper(): ) +def test_cosmos3_modelopt_quantizer_weights_mapper(): + """ModelOpt/Diffusers FP8 checkpoints ship native fake-quant buffers + (``*_quantizer._amax`` / ``._scale``) alongside the vLLM-consumable + ``weight_scale`` / ``input_scale`` sidecars. vLLM must drop the former + (it has no parameter for them) while keeping the latter.""" + from vllm.model_executor.models.cosmos3 import Cosmos3ForConditionalGeneration + + mapper = Cosmos3ForConditionalGeneration.hf_to_vllm_mapper + + # Native ModelOpt quantizer buffers are dropped. + assert ( + mapper.apply_list( + [ + "layers.0.self_attn.to_q.input_quantizer._amax", + "layers.0.self_attn.to_q.weight_quantizer._amax", + "layers.0.self_attn.to_q.weight_quantizer._scale", + "layers.0.mlp.down_proj.output_quantizer._amax", + ] + ) + == [] + ) + + # The FP8 scale sidecars vLLM actually consumes are kept and remapped. + assert mapper.apply_list( + [ + "layers.0.self_attn.to_q.weight", + "layers.0.self_attn.to_q.weight_scale", + "layers.0.self_attn.to_q.input_scale", + "layers.0.mlp.down_proj.input_scale", + ] + ) == [ + "language_model.model.layers.0.self_attn.q_proj.weight", + "language_model.model.layers.0.self_attn.q_proj.weight_scale", + "language_model.model.layers.0.self_attn.q_proj.input_scale", + "language_model.model.layers.0.mlp.down_proj.input_scale", + ] + + def test_cosmos3_edge_checkpoint_weights_mapper(): from vllm.model_executor.models.cosmos3_edge import ( Cosmos3EdgeForConditionalGeneration, diff --git a/vllm/model_executor/models/cosmos3.py b/vllm/model_executor/models/cosmos3.py index 71629196a7..7e4e827457 100644 --- a/vllm/model_executor/models/cosmos3.py +++ b/vllm/model_executor/models/cosmos3.py @@ -37,6 +37,11 @@ class Cosmos3ForConditionalGeneration(Qwen3VLForConditionalGeneration): ".to_out.": ".o_proj.", ".norm_q.": ".q_norm.", ".norm_k.": ".k_norm.", + # ModelOpt-native dialect (diffusers/transformers read these; vLLM reads + # weight_scale/input_scale instead), drop so AutoWeightsLoader passes + ".input_quantizer.": None, + ".weight_quantizer.": None, + ".output_quantizer.": None, }, orig_to_new_prefix={ "proj_in.": None,