40888.diff 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. diff --git a/python/sglang/srt/models/mimo_v2.py b/python/sglang/srt/models/mimo_v2.py
  2. index 26f9c8c88fdf..41a95e4b6e2f 100644
  3. --- a/python/sglang/srt/models/mimo_v2.py
  4. +++ b/python/sglang/srt/models/mimo_v2.py
  5. @@ -1390,16 +1390,11 @@ def forward(
  6. )
  7. aux_hidden_states = None
  8. - if self.capture_aux_hidden_states:
  9. - hidden_states, hidden_states_before_norm, aux_hidden_states = self.model(
  10. - input_ids,
  11. - positions,
  12. - forward_batch,
  13. - input_embeds,
  14. - pp_proxy_tensors=pp_proxy_tensors,
  15. - )
  16. - elif self._is_multimodal:
  17. - hidden_states, hidden_states_before_norm = general_mm_embed_routine(
  18. + # Multimodal embedding must run even when aux hidden states are captured
  19. + # (DFLASH/MTP). Taking the capture branch first skipped image/audio
  20. + # feature placement and left placeholder tokens as plain text embeddings.
  21. + if self._is_multimodal:
  22. + model_out = general_mm_embed_routine(
  23. input_ids=input_ids,
  24. forward_batch=forward_batch,
  25. language_model=self.model,
  26. @@ -1408,13 +1403,17 @@ def forward(
  27. pp_proxy_tensors=pp_proxy_tensors,
  28. )
  29. else:
  30. - hidden_states, hidden_states_before_norm = self.model(
  31. + model_out = self.model(
  32. input_ids,
  33. positions,
  34. forward_batch,
  35. input_embeds,
  36. pp_proxy_tensors=pp_proxy_tensors,
  37. )
  38. + if self.capture_aux_hidden_states:
  39. + hidden_states, hidden_states_before_norm, aux_hidden_states = model_out
  40. + else:
  41. + hidden_states, hidden_states_before_norm = model_out
  42. if self.pp_group.is_last_rank:
  43. return self.logits_processor(
  44. diff --git a/python/sglang/srt/models/mimo_vl.py b/python/sglang/srt/models/mimo_vl.py
  45. index 3f4c7267bc20..f09269adc33f 100644
  46. --- a/python/sglang/srt/models/mimo_vl.py
  47. +++ b/python/sglang/srt/models/mimo_vl.py
  48. @@ -317,6 +317,10 @@ def __init__(
  49. prefix=add_prefix("merger", prefix),
  50. use_data_parallel=self.use_data_parallel,
  51. )
  52. + # MiMo-VL merger ln_q is LayerNorm (see modeling_mimo_v2.py
  53. + # MiMoVisionPatchMerger), not the Qwen2.5-VL RMSNorm. Checkpoint ships
  54. + # visual.merger.ln_q.weight only (bias omitted → zeros).
  55. + self.merger.ln_q = nn.LayerNorm(hidden_size, eps=1e-6, bias=False)
  56. self._post_init()
  57. def apply_index(self, tensor: torch.Tensor, index: torch.Tensor):
  58. @@ -327,7 +331,9 @@ def apply_index(self, tensor: torch.Tensor, index: torch.Tensor):
  59. def _post_init(self):
  60. for name, param in self.named_parameters():
  61. - if "bias" in name:
  62. + # Also zero sinks: they are torch.empty at ctor and some checkpoints
  63. + # omit individual visual.blocks.*.attn.sinks keys.
  64. + if "bias" in name or name.endswith("sinks"):
  65. param.data.zero_()
  66. def get_window_index_1d(self, grid_thw, col=True):
  67. diff --git a/python/sglang/srt/multimodal/processors/mimo_v2.py b/python/sglang/srt/multimodal/processors/mimo_v2.py
  68. index e914f00b1a0e..35a43469fdcf 100644
  69. --- a/python/sglang/srt/multimodal/processors/mimo_v2.py
  70. +++ b/python/sglang/srt/multimodal/processors/mimo_v2.py
  71. @@ -214,8 +214,12 @@ def __post_init__(self):
  72. )
  73. -_QWEN2VL_PIXEL_MEAN = torch.Tensor([123.675, 116.28, 103.53]).view(-1, 1, 1)
  74. -_QWEN2VL_PIXEL_STD = torch.Tensor([58.395, 57.12, 57.375]).view(-1, 1, 1)
  75. +# OPENAI_CLIP stats, matching Qwen2VLImageProcessor (preprocessor_config.json
  76. +# image_mean/image_std with do_rescale 1/255). Kept in 0-255 space because
  77. +# standardize_batch sees un-rescaled PIL tensors. ImageNet values were wrong
  78. +# for MiMo-VL and scrambled colors.
  79. +_QWEN2VL_PIXEL_MEAN = torch.Tensor([0.48145466, 0.4578275, 0.40821073]).view(-1, 1, 1) * 255.0
  80. +_QWEN2VL_PIXEL_STD = torch.Tensor([0.26862954, 0.26130258, 0.27577711]).view(-1, 1, 1) * 255.0
  81. _mean_std_cache = {}