{"record":{"id":"c29ad950cbc37961","repo":"sgl-project/sglang","slug":"cannot-create-empty-tensor-bucket","errorCode":null,"errorMessage":"Cannot create empty tensor bucket","messagePattern":"Cannot create empty tensor bucket","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"python/sglang/srt/weight_sync/tensor_bucket.py","lineNumber":47,"sourceCode":"        self,\n        named_tensors: List[Tuple[str, torch.Tensor]] = None,\n        flattened_tensor: torch.Tensor = None,\n        metadata: List[FlattenedTensorMetadata] = None,\n    ):\n        \"\"\"\n        Initialize a tensor bucket from a list of named tensors OR from pre-flattened data.\n        Args:\n            named_tensors: List of (name, tensor) tuples (for creating new bucket)\n            flattened_tensor: Pre-flattened tensor (for reconstruction)\n            metadata: Pre-computed metadata (for reconstruction)\n        \"\"\"\n        if named_tensors is not None:\n            # Create bucket from named tensors\n            self.metadata: List[FlattenedTensorMetadata] = [None] * len(named_tensors)\n            self.flattened_tensor: torch.Tensor = None\n\n            if not named_tensors:\n                raise ValueError(\"Cannot create empty tensor bucket\")\n\n            # Collect metadata and flatten tensors\n            current_idx = 0\n            flattened_tensors: List[torch.Tensor] = [None] * len(named_tensors)\n\n            for i, (name, tensor) in enumerate(named_tensors):\n                flattened = tensor.flatten().view(torch.uint8)\n                flattened_tensors[i] = flattened\n\n                # Store metadata\n\n                numel = flattened.numel()\n                metadata_obj = FlattenedTensorMetadata(\n                    name=name,\n                    shape=tensor.shape,\n                    dtype=tensor.dtype,\n                    start_idx=current_idx,\n                    end_idx=current_idx + numel,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/weight_sync/tensor_bucket.py#L29-L65","documentation":"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.","triggerScenarios":"Constructing TensorBucket(named_tensors=[]) when syncing zero selected weights; upstream filter produced an empty list.","commonSituations":"Weight sync prefix matching nothing; empty layer/parameter selection in broadcast logic.","solutions":["Skip bucket creation/sync when the tensor list is empty (guard upstream)","Fix the selection filter that produced zero tensors"],"exampleFix":"# before\nbucket = TensorBucket(named_tensors=tensors)\n# after\nbucket = TensorBucket(named_tensors=tensors) if tensors else None","handlingStrategy":"validation","validationCode":"if not named_tensors:\n    return None  # skip bucket creation","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard empty selections before constructing buckets","Log when weight selection filters match nothing"],"tags":["validation","weight-sync","empty-input"],"backgroundTag":"empty-collection-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}