diff --git a/vllm/patches/deepseek_v4.py b/vllm/patches/deepseek_v4.py index 36e7ef8e..4c5096cc 100644 --- a/vllm/patches/deepseek_v4.py +++ b/vllm/patches/deepseek_v4.py @@ -515,11 +515,12 @@ class DeepseekV4MegaMoEExperts(nn.Module): # Set activation global scales from checkpoint input_scale # The input_scale is the pre-computed activation normalization factor # for each projection. Using hardcoded 1/2688 gives wrong scale for most layers. + # Read from the nn.Parameters BEFORE they're freed below. # input_scale shape: (num_experts, 2) for w13 (gate, up), (num_experts, 1) for w2 - l1_igs = self._w13_input_scale[:, 0] if self._w13_input_scale is not None else None # gate input_scale - l2_igs = self._w2_input_scale[:, 0] if self._w2_input_scale is not None else None # down input_scale - self._cutedsl_runner.l1_activation_global_scale = l1_igs.mean().item() if l1_igs is not None else 1.0 / 2688.0 - self._cutedsl_runner.l2_activation_global_scale = l2_igs.mean().item() if l2_igs is not None else 1.0 / 2688.0 + l1_igs = self.w13_input_scale.data[:, 0] # gate input_scale + l2_igs = self.w2_input_scale.data[:, 0] # down input_scale + self._cutedsl_runner.l1_activation_global_scale = l1_igs.mean().item() + self._cutedsl_runner.l2_activation_global_scale = l2_igs.mean().item() # Drop the original loader-side parameters self._w13_input_scale = self.w13_input_scale.data.clone()