[Bugfix][Ray] Set the cuda context eagerly in the ray worker (#19583)

This commit is contained in:
kourosh hakhamaneshi
2025-06-19 22:01:16 -07:00
committed by GitHub
parent e3a3e4db46
commit 5e666f72cd
4 changed files with 107 additions and 0 deletions
+11
View File
@@ -71,6 +71,17 @@ class CudaPlatformBase(Platform):
# though vLLM doesn't support these GPUs.
return [torch.float32]
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
super().set_device(device)
# With this trick we can force the device to be set eagerly
# see https://github.com/pytorch/pytorch/issues/155668
# for why and when it is needed
_ = torch.zeros(1, device=device)
@classmethod
def get_device_capability(cls,
device_id: int = 0
+7
View File
@@ -298,6 +298,13 @@ class Platform:
np.random.seed(seed)
torch.manual_seed(seed)
@classmethod
def set_device(cls, device: torch.device) -> None:
"""
Set the device for the current platform.
"""
torch.cuda.set_device(device)
@classmethod
def pre_register_and_update(cls,
parser: Optional[FlexibleArgumentParser] = None