sgl-project/sglang · error · ValueError

Source and destination groups must have the same length

Error message

Source and destination groups must have the same length

What it means

GroupedIndexPlan.from_groups builds a compact (start,count) transfer plan from paired source/destination index groups; unequal group counts mean the pairing is malformed and it refuses with ValueError.

Source

Thrown at python/sglang/srt/disaggregation/mori/conn.py:261

    bytes_per_token_src: int
    bytes_per_token_dst: int
    src_head_slice_offset: int
    dst_head_slice_offset: int
    heads_bytes_per_token_to_send: int


@dataclasses.dataclass(frozen=True)
class GroupedIndexPlan:
    src_starts: List[int]
    dst_starts: List[int]
    counts: List[int]

    @classmethod
    def from_groups(
        cls, src_groups: List[List[int]], dst_groups: List[List[int]]
    ) -> GroupedIndexPlan:
        if len(src_groups) != len(dst_groups):
            raise ValueError("Source and destination groups must have the same length")
        return cls(
            src_starts=[int(group[0]) for group in src_groups],
            dst_starts=[int(group[0]) for group in dst_groups],
            counts=[len(group) for group in src_groups],
        )

    def materialize(self, item_len: int) -> BatchTransferPlan:
        return BatchTransferPlan(
            local_offsets=[start * item_len for start in self.src_starts],
            remote_offsets=[start * item_len for start in self.dst_starts],
            sizes=[count * item_len for count in self.counts],
        )


@dataclasses.dataclass(frozen=True)
class BatchTransferPlan:
    local_offsets: List[int]
    remote_offsets: List[int]

View on GitHub (pinned to 0132848349)

Solutions

  1. Log and compare len(src_groups) vs len(dst_groups) before building the plan
  2. Check layer-range config (prefill_start_layer / pp slicing) produces symmetric groups on both sides
  3. Fix upstream slicing that produced the asymmetry

Example fix

assert len(src_groups) == len(dst_groups), (len(src_groups), len(dst_groups))
plan = GroupedIndexPlan.from_groups(src_groups, dst_groups)
Defensive patterns

Strategy: validation

Validate before calling

if len(src_groups) != len(dst_groups):
    raise ValueError(f"group mismatch: {len(src_groups)} vs {len(dst_groups)}")
plan = GroupedIndexPlan.from_groups(src_groups, dst_groups)

Try / catch

catch ValueError from from_groups; log both group lists' lengths per layer to find the asymmetric slice

Prevention

When it happens

Trigger: Calling from_groups with len(src_groups) != len(dst_groups) — e.g. when slicing SWA/DSA state groups or building kv transfer plans where one side yielded fewer groups.

Common situations: Layer or rank slicing bugs that drop groups on one side; mismatched layer counts between PD configurations.

Related errors


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