{"record":{"id":"f8138f39d2b99d40","repo":"sgl-project/sglang","slug":"unsupported-parallel-style-type-type-style-exp","errorCode":null,"errorMessage":"Unsupported parallel style type {type(style)}, expected str","messagePattern":"Unsupported parallel style type (.+?), expected str","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/transformers.py","lineNumber":203,"sourceCode":"    try:\n        nn.Module.register_parameter = register_empty_parameter\n        yield\n    finally:\n        nn.Module.register_parameter = old_register_parameter\n\n\nStyle = Literal[\"colwise\", \"colwise_rep\", \"rowwise\", \"rowwise_rep\", \"replicate\"]\n\n\ndef replace_linear_class(\n    linear: nn.Linear,\n    style: Style = \"replicate\",\n    quant_config: Optional[QuantizationConfig] = None,\n    *,\n    prefix: str = \"\",\n) -> Union[ColumnParallelLinear, RowParallelLinear, ReplicatedLinear]:\n    if not isinstance(style, str):\n        raise ValueError(f\"Unsupported parallel style type {type(style)}, expected str\")\n\n    sglang_linear_cls, linear_kwargs = {\n        \"colwise\": (ColumnParallelLinear, {}),\n        \"colwise_rep\": (ColumnParallelLinear, {\"gather_output\": True}),\n        \"rowwise\": (RowParallelLinear, {}),\n        \"rowwise_rep\": (RowParallelLinear, {\"input_is_parallel\": False}),\n        \"replicate\": (ReplicatedLinear, {}),\n    }.get(style, (ReplicatedLinear, {}))\n\n    class HFCompatibleLinear(sglang_linear_cls):\n        @property\n        def parent_cls(self) -> type:\n            return sglang_linear_cls\n\n        def forward(self, input: torch.Tensor) -> torch.Tensor:\n            return super().forward(input)[0]\n\n    return HFCompatibleLinear(","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/transformers.py#L185-L221","documentation":"replace_linear_class expects the parallel style as a string ('colwise','rowwise','replicate', variants); passing an enum or other object raises immediately.","triggerScenarios":"Calling replace_linear_class with style=ParallelStyle.COLWISE (an enum) or another non-str object instead of a string.","commonSituations":"Passing HF's `torch.distributed.TensorParallelLayerStyle`-style enums or vLLM-style plan objects into the sglang Transformers backend replacer.","solutions":["Convert the style to its string value before calling (style.value if enum)","Pass one of the accepted strings: colwise, colwise_rep, rowwise, rowwise_rep, replicate","Update caller code building the tp_plan to store plain strings"],"exampleFix":"// before\nreplace_linear_class(linear, style=TPStyle.COLWISE)\n// after\nreplace_linear_class(linear, style=TPStyle.COLWISE.value)","handlingStrategy":"type-guard","validationCode":"style = style.value if hasattr(style,'value') else style\nassert isinstance(style, str)","typeGuard":"def is_valid_style(s) -> bool:\n    return isinstance(s, str) and s in {'colwise','colwise_rep','rowwise','rowwise_rep','replicate'}","tryCatchPattern":null,"preventionTips":["Store tp_plan styles as plain strings","Normalize enums at the boundary"],"tags":["type-validation","tensor-parallel","transformers-backend"],"backgroundTag":"invalid-argument-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}