[TPU] Skip creating empty tensor (#7630)

This commit is contained in:
Woosuk Kwon 2024-08-17 14:22:46 -07:00 committed by GitHub
parent bbf55c4805
commit ce143353c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -271,7 +271,10 @@ def _make_src_to_dst(
mapping: List[Tuple[int, int]],
src_device: Union[torch.device, str],
dst_device: Union[torch.device, str],
) -> Tuple[torch.Tensor, torch.Tensor]:
) -> Optional[Tuple[torch.Tensor, torch.Tensor]]:
if not mapping:
return None
src_indices = [i for i, _ in mapping]
dst_indices = [i for _, i in mapping]
src_indices = torch.tensor(src_indices,