[Fix] DSv4.1: Fix BCG image handling and add multimodal bounded replay coverage (#44131)

This commit is contained in:
Yuwei An
2026-10-15 22:32:55 -07:00
committed by GitHub
parent 2a08e261ec
commit 06934575b9
6 changed files with 176 additions and 19 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ test = [
# Pinned: a bump moves scoring for every eval test at once, so re-baseline
# MODEL_SCORE_THRESHOLDS in test/registered/eval/test_text_models_gsm8k_eval.py
# and the mmlu thresholds of run_eval's other callers before changing it.
"sgl-eval==0.1.2",
"sgl-eval==0.1.3",
"sglang[fastokens]",
"tabulate",
]
@@ -332,6 +332,9 @@ class PrefillCudaGraphRunner(BaseCudaGraphRunner):
# --- model flags ----------------------------------------------
self.quant_config = getattr(model_runner.model, "quant_config", None)
self.is_multimodal = model_runner.model_config.is_multimodal
self.is_dsv41_model = (
model_runner.model_config.hf_config.model_type == "deepseek_v41"
)
self.enable_lora = model_runner.lora_manager is not None
# Classification/reward forwards branch on return_pooled_hidden_states;
# capture must use the same flag value as replay for those models.
@@ -2115,6 +2118,12 @@ class PrefillCudaGraphRunner(BaseCudaGraphRunner):
full_path = self._is_full_backend
def replay_layer_forward(*args, **layer_kwargs):
prepared_ids = layer_kwargs.get("input_ids", args[0] if args else None)
# TODO: Add general multimodal replay tests before enabling for other models.
if self.is_dsv41_model and prepared_ids is not None:
static_forward_batch.input_ids[: prepared_ids.shape[0]].copy_(
prepared_ids
)
# The captured body graph reads activations from the static
# input_embeds slot. The outer model.forward (run eagerly)
# passes the live embeddings into layer_model.forward as the
-3
View File
@@ -3786,12 +3786,9 @@ class DeepseekV4Model(nn.Module):
forward_batch,
cp_all_tokens=cp_extend,
)
# Only multimodal placeholders become image_token_id, so a text-only
# batch skips this full-residual where.
if (
self.config.model_type == "deepseek_v41"
and self.config.vision_n_layers > 0
and forward_batch.contains_mm_inputs()
):
hidden_states = torch.where(
(input_ids == self.config.image_token_id)[:, None, None],