sgl-project/sglang · error · ValueError
Invalid {tp_size=}. Expected tp_size >= 1.
Error message
Invalid {tp_size=}. Expected tp_size >= 1. What it means
LTX2Attention derives local head/inner-dim splits from the tensor-parallel world size and sanity-checks that it is a positive integer. tp_size <= 0 indicates a broken/uninitialized parallel group (get_tp_world_size() returned 0 or negative), which would corrupt all sharding math.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/dits/ltx_2.py:758
) -> None:
super().__init__()
is_cross_attention = context_dim is not None
self.query_dim = int(query_dim)
self.context_dim = int(query_dim if context_dim is None else context_dim)
self.heads = int(heads)
self.dim_head = int(dim_head)
self.inner_dim = self.heads * self.dim_head
self.norm_eps = float(norm_eps)
self.qk_norm = bool(qk_norm)
self.use_local_attention = bool(use_local_attention)
self.apply_gated_attention = bool(apply_gated_attention)
self.enable_packed_qkv_input_a2a = bool(enable_packed_qkv_input_a2a)
self.prefix = prefix
tp_size = get_tp_world_size()
if tp_size <= 0:
raise ValueError(f"Invalid {tp_size=}. Expected tp_size >= 1.")
if self.heads % tp_size != 0:
raise ValueError(
f"LTX2Attention requires heads divisible by tp_size, got "
f"{self.heads=} {tp_size=}."
)
if self.inner_dim % tp_size != 0:
# This should follow from heads % tp_size, but keep explicit for clarity.
raise ValueError(
f"LTX2Attention requires inner_dim divisible by tp_size, got "
f"{self.inner_dim=} {tp_size=}."
)
self.local_heads = self.heads // tp_size
self.to_q = ColumnParallelLinear(
self.query_dim,
self.inner_dim,
bias=True,
gather_output=False,View on GitHub (pinned to 0132848349)
Solutions
- Initialize the distributed/TP groups before building the model (use the standard launcher)
- In tests, mock get_tp_world_size to return 1 after initializing a single-process group
- If it persists in serving, check worker startup logs for failed group initialization
Example fix
# before (test)
layer = LTX2Attention(...) # TP group never initialized -> tp_size=0
# after (test)
import torch.distributed as dist
dist.init_process_group("nccl", rank=0, world_size=1)
layer = LTX2Attention(...) Defensive patterns
Strategy: validation
Validate before calling
tp = get_tp_world_size()\nassert tp >= 1, f'distributed groups not initialized (tp_size={tp}); init process group first' Prevention
- Always init process groups before building TP modules
- In tests, use a 1-rank init_process_group
- Check worker startup logs for group init failures
When it happens
Trigger: Constructing LTX2Attention before TP groups are initialized (e.g. in a unit test or offline script without initializing the distributed backend), where get_tp_world_size() returns 0.
Common situations: Importing/instantiating the model outside the server launch flow; a worker where the TP group init failed silently; mocking distributed helpers with wrong defaults.
Related errors
- LTX2Attention requires heads divisible by tp_size, got {self
- LTX2Attention requires inner_dim divisible by tp_size, got {
- world_size ({world_size}) is less than tensor_parallel_degre
- Rank-local TP shard produced for DTensor parameter {target_p
- The size of ({name}) is ({self.name_to_size[name]}), but you
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2abc3e43af242ad6.
Report an issue: GitHub.