sgl-project/sglang · error · ValueError

Unsupported parallel style type {type(style)}, expected str

Error message

Unsupported parallel style type {type(style)}, expected str

What it means

replace_linear_class expects the parallel style as a string ('colwise','rowwise','replicate', variants); passing an enum or other object raises immediately.

Source

Thrown at python/sglang/srt/models/transformers.py:203

    try:
        nn.Module.register_parameter = register_empty_parameter
        yield
    finally:
        nn.Module.register_parameter = old_register_parameter


Style = Literal["colwise", "colwise_rep", "rowwise", "rowwise_rep", "replicate"]


def replace_linear_class(
    linear: nn.Linear,
    style: Style = "replicate",
    quant_config: Optional[QuantizationConfig] = None,
    *,
    prefix: str = "",
) -> Union[ColumnParallelLinear, RowParallelLinear, ReplicatedLinear]:
    if not isinstance(style, str):
        raise ValueError(f"Unsupported parallel style type {type(style)}, expected str")

    sglang_linear_cls, linear_kwargs = {
        "colwise": (ColumnParallelLinear, {}),
        "colwise_rep": (ColumnParallelLinear, {"gather_output": True}),
        "rowwise": (RowParallelLinear, {}),
        "rowwise_rep": (RowParallelLinear, {"input_is_parallel": False}),
        "replicate": (ReplicatedLinear, {}),
    }.get(style, (ReplicatedLinear, {}))

    class HFCompatibleLinear(sglang_linear_cls):
        @property
        def parent_cls(self) -> type:
            return sglang_linear_cls

        def forward(self, input: torch.Tensor) -> torch.Tensor:
            return super().forward(input)[0]

    return HFCompatibleLinear(

View on GitHub (pinned to 0132848349)

Solutions

  1. Convert the style to its string value before calling (style.value if enum)
  2. Pass one of the accepted strings: colwise, colwise_rep, rowwise, rowwise_rep, replicate
  3. Update caller code building the tp_plan to store plain strings

Example fix

// before
replace_linear_class(linear, style=TPStyle.COLWISE)
// after
replace_linear_class(linear, style=TPStyle.COLWISE.value)
Defensive patterns

Strategy: type-guard

Validate before calling

style = style.value if hasattr(style,'value') else style
assert isinstance(style, str)

Type guard

def is_valid_style(s) -> bool:
    return isinstance(s, str) and s in {'colwise','colwise_rep','rowwise','rowwise_rep','replicate'}

Prevention

When it happens

Trigger: Calling replace_linear_class with style=ParallelStyle.COLWISE (an enum) or another non-str object instead of a string.

Common situations: Passing HF's `torch.distributed.TensorParallelLayerStyle`-style enums or vLLM-style plan objects into the sglang Transformers backend replacer.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/f8138f39d2b99d40. Report an issue: GitHub.