{"record":{"id":"3a75d3561b64c5d1","repo":"sgl-project/sglang","slug":"tp-size-self-tp-size-num-experts-config-num-e","errorCode":null,"errorMessage":"TP size {self.tp_size} > num_experts {config.num_experts}.","messagePattern":"TP size (.+?) > num_experts (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/laguna.py","lineNumber":152,"sourceCode":"\n\nclass LagunaMoE(nn.Module):\n    def __init__(\n        self,\n        config: LagunaConfig,\n        layer_id: int,\n        quant_config: Optional[QuantizationConfig] = None,\n        prefix: str = \"\",\n    ):\n        super().__init__()\n        self.tp_size = get_parallel().tp_size\n        self.routed_scaling_factor = config.moe_routed_scaling_factor\n        self.router_logit_softcapping = getattr(\n            config, \"moe_router_logit_softcapping\", 0.0\n        )\n\n        if self.tp_size > config.num_experts:\n            raise ValueError(\n                f\"TP size {self.tp_size} > num_experts {config.num_experts}.\"\n            )\n\n        self.gate = LagunaMoEGate(config, prefix=add_prefix(\"gate\", prefix))\n\n        self.experts = get_moe_impl_class(quant_config)(\n            num_experts=config.num_experts + get_exec().moe.ep_num_redundant_experts,\n            top_k=config.num_experts_per_tok,\n            layer_id=layer_id,\n            hidden_size=config.hidden_size,\n            intermediate_size=config.moe_intermediate_size,\n            quant_config=quant_config,\n            reduce_results=False,\n            apply_router_weight_on_input=bool(config.moe_apply_router_weight_on_input),\n            prefix=add_prefix(\"experts\", prefix),\n        )\n\n        self.topk = TopK(","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/laguna.py#L134-L170","documentation":"Laguna's MoE layer shards experts across tensor-parallel ranks; laguna.py:152 enforces tp_size <= num_experts (each rank must get at least one expert). Exceeding it raises at model init because expert sharding would produce empty ranks.","triggerScenarios":"Launching with --tp-size larger than config.num_experts, e.g. tp=8 on a model with 4 routed experts.","commonSituations":"Small-expert-count MoE checkpoints run on many GPUs; copying TP flags from a dense-model deployment.","solutions":["Choose tp_size <= num_experts (prefer expert parallelism: --enable-ep-moe / --dp-size)","Check config.num_experts before selecting --tp-size","Rebalance: use DP + EP for many-GPU serving of small-expert MoEs"],"exampleFix":"# before\n--tp-size 8 --enable-ep-moe  (model has 4 experts)\n# after\n--tp-size 4 --enable-ep-moe --dp-size 2","handlingStrategy":"validation","validationCode":"assert args.tp_size <= cfg.num_experts, f\"tp {args.tp_size} > experts {cfg.num_experts}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute max TP from expert count before allocating GPUs","Use EP/DP for MoE scaling"],"tags":["laguna","moe","tensor-parallel","startup-validation"],"backgroundTag":"tp-expert-count-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}