{"record":{"id":"de21ad61a3e6cb6d","repo":"sgl-project/sglang","slug":"intermediate-size-must-be-specified-for-scaled-act","errorCode":null,"errorMessage":"intermediate_size must be specified for scaled activation functions.","messagePattern":"intermediate_size must be specified for scaled activation functions\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/layers/activation.py","lineNumber":483,"sourceCode":"}\n\n\ndef get_act_fn(\n    act_fn_name: str,\n    quant_config: Optional[QuantizationConfig] = None,\n    intermediate_size: Optional[int] = None,\n    input_is_parallel: bool = True,\n    params_dtype: Optional[torch.dtype] = None,\n) -> nn.Module:\n    \"\"\"Get an activation function by name.\"\"\"\n    act_fn_name = act_fn_name.lower()\n    if act_fn_name not in _ACTIVATION_REGISTRY:\n        raise ValueError(f\"Activation function {act_fn_name!r} is not supported.\")\n\n    act_fn = _ACTIVATION_REGISTRY[act_fn_name]\n    if quant_config is not None and act_fn_name in quant_config.get_scaled_act_names():\n        if intermediate_size is None:\n            raise ValueError(\n                \"intermediate_size must be specified for scaled \"\n                \"activation functions.\"\n            )\n        return ScaledActivation(\n            act_fn, intermediate_size, input_is_parallel, params_dtype\n        )\n    return act_fn\n\n\ndef get_cross_encoder_activation_function(config: PretrainedConfig):\n    if (\n        hasattr(config, \"sbert_ce_default_activation_function\")\n        and config.sbert_ce_default_activation_function is not None\n    ):\n\n        function_name = config.sbert_ce_default_activation_function\n        assert function_name.startswith(\"torch.nn.modules.\"), (\n            \"Loading of activation functions is restricted to \"","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/activation.py#L465-L501","documentation":"When a quant_config marks an activation as scaled (e.g. fp8 ScaledActivation), get_act_fn needs intermediate_size to allocate the per-channel scales tensor. Passing quant_config with a scaled activation but intermediate_size=None raises ValueError.","triggerScenarios":"Calling get_act_fn('gelu', quant_config=fp8_config) without intermediate_size, where fp8_config.get_scaled_act_names() includes 'gelu'. Typical when an MLP/GPU layer built before quantization config plumbing passed intermediate_size.","commonSituations":"Loading an fp8/int8 quantized checkpoint whose act scales are stored, with model code path (e.g. a custom MoE MLP) that forgot to forward intermediate_size into get_act_fn.","solutions":["Pass intermediate_size explicitly to get_act_fn wherever quant_config is non-None","If the activation should not be scaled, fix quant_config.get_scaled_act_names()/config so the name is excluded","Update the model implementation to plumb intermediate_size from its constructor into get_act_fn"],"exampleFix":"# before\nself.act_fn = get_act_fn(hidden_act, quant_config=self.quant_config)\n# after\nself.act_fn = get_act_fn(\n    hidden_act,\n    quant_config=self.quant_config,\n    intermediate_size=self.intermediate_size_per_partition,\n    input_is_parallel=True,\n)","handlingStrategy":"validation","validationCode":"from sglang.srt.layers.activation import get_act_fn\nscaled = quant_config is not None and hidden_act in quant_config.get_scaled_act_names()\nif scaled and intermediate_size is None:\n    intermediate_size = config.intermediate_size\nact = get_act_fn(hidden_act, quant_config=quant_config, intermediate_size=intermediate_size)","typeGuard":"def needs_intermediate_size(name: str, quant_config) -> bool:\n    return quant_config is not None and name in quant_config.get_scaled_act_names()","tryCatchPattern":null,"preventionTips":["Always pass intermediate_size when quant_config is not None","Audit custom MLP/MoE code to forward intermediate_size into get_act_fn"],"tags":["activation","quantization","fp8","config","valueerror"],"backgroundTag":"missing-required-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}