sgl-project/sglang · warning · ValueError

Cannot create empty tensor bucket

Error message

Cannot create empty tensor bucket

What it means

TensorBucket.__init__ was given named_tensors as an empty sequence. A bucket with no tensors has no flattened buffer or metadata, so it is rejected.

Source

Thrown at python/sglang/srt/weight_sync/tensor_bucket.py:47

        self,
        named_tensors: List[Tuple[str, torch.Tensor]] = None,
        flattened_tensor: torch.Tensor = None,
        metadata: List[FlattenedTensorMetadata] = None,
    ):
        """
        Initialize a tensor bucket from a list of named tensors OR from pre-flattened data.
        Args:
            named_tensors: List of (name, tensor) tuples (for creating new bucket)
            flattened_tensor: Pre-flattened tensor (for reconstruction)
            metadata: Pre-computed metadata (for reconstruction)
        """
        if named_tensors is not None:
            # Create bucket from named tensors
            self.metadata: List[FlattenedTensorMetadata] = [None] * len(named_tensors)
            self.flattened_tensor: torch.Tensor = None

            if not named_tensors:
                raise ValueError("Cannot create empty tensor bucket")

            # Collect metadata and flatten tensors
            current_idx = 0
            flattened_tensors: List[torch.Tensor] = [None] * len(named_tensors)

            for i, (name, tensor) in enumerate(named_tensors):
                flattened = tensor.flatten().view(torch.uint8)
                flattened_tensors[i] = flattened

                # Store metadata

                numel = flattened.numel()
                metadata_obj = FlattenedTensorMetadata(
                    name=name,
                    shape=tensor.shape,
                    dtype=tensor.dtype,
                    start_idx=current_idx,
                    end_idx=current_idx + numel,

View on GitHub (pinned to 0132848349)

Solutions

  1. Skip bucket creation/sync when the tensor list is empty (guard upstream)
  2. Fix the selection filter that produced zero tensors

Example fix

# before
bucket = TensorBucket(named_tensors=tensors)
# after
bucket = TensorBucket(named_tensors=tensors) if tensors else None
Defensive patterns

Strategy: validation

Validate before calling

if not named_tensors:
    return None  # skip bucket creation

Prevention

When it happens

Trigger: Constructing TensorBucket(named_tensors=[]) when syncing zero selected weights; upstream filter produced an empty list.

Common situations: Weight sync prefix matching nothing; empty layer/parameter selection in broadcast logic.

Related errors


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