Skip to content

Commit e417e05

Browse files
rosenrodtyumin066
authored andcommitted
fix weight_loading_mode for deepseek
Signed-off-by: Anthony Chang <[email protected]>
1 parent 0e80da2 commit e417e05

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tensorrt_llm/_torch/models/modeling_deepseekv3.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from tensorrt_llm.llmapi.utils import enable_llm_debug
4646
from tensorrt_llm.mapping import Mapping
4747
from tensorrt_llm.models.modeling_utils import QuantConfig
48+
from tensorrt_llm.quantization.mode import QuantAlgo
4849
from tensorrt_llm.quantization.utils.fp8_utils import (
4950
resmooth_to_fp8_e8m0, transform_sf_into_required_layout)
5051

@@ -462,10 +463,13 @@ def __init__(self,
462463
layer_idx=layer_idx,
463464
# DS-R1 W4A8 is only supported through custom quantization script from
464465
# examples/quantization/quantize_mixed_precision_moe.py
465-
weight_loading_mode=(MoEWeightLoadingMode.W4A8_CUSTOM
466-
if model_config.quant_config.quant_mode.
467-
is_int4_weight_only_per_group() else
468-
MoEWeightLoadingMode.VANILLA))
466+
weight_loading_mode=(
467+
MoEWeightLoadingMode.W4A8_CUSTOM
468+
if self._get_experts_quant_config(
469+
model_config,
470+
layer_idx).layer_quant_mode.is_int4_weight_only_per_group()
471+
else MoEWeightLoadingMode.VANILLA),
472+
)
469473

470474
self.mapping = model_config.mapping
471475

@@ -530,6 +534,13 @@ def _compute_shared_expert_tp_size(self, intermediate_size: int,
530534

531535
return shared_tp_size, shared_output_scale
532536

537+
@staticmethod
538+
def _get_experts_quant_config(model_config, layer_idx: int) -> QuantConfig:
539+
if getattr(model_config, "quant_config_dict", None) is None:
540+
return model_config.quant_config
541+
return model_config.quant_config_dict.get(
542+
f"model.layers.{layer_idx}.mlp.experts", model_config.quant_config)
543+
533544
def compute_routed_output(self, hidden_states, hidden_states_fp4,
534545
all_rank_num_tokens, all_rank_max_num_tokens,
535546
do_finalize):
@@ -640,6 +651,9 @@ def __init__(self, model_config: ModelConfig[PretrainedConfig],
640651
quant_config = self._get_decoder_layer_quant_config(
641652
model_config, layer_idx)
642653
self.is_nvfp4 = quant_config.layer_quant_mode.has_nvfp4()
654+
assert (
655+
quant_config.quant_algo
656+
is not QuantAlgo.MIXED_PRECISION), "MIXED_PRECISION is ambiguous"
643657

644658
has_tp = mapping.has_tp()
645659

0 commit comments

Comments
 (0)