Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Apple silicon GPU(mps) support to ray #38464

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/ray/_private/accelerators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from ray._private.accelerators.amd_gpu import AMDGPUAcceleratorManager
from ray._private.accelerators.tpu import TPUAcceleratorManager
from ray._private.accelerators.neuron import NeuronAcceleratorManager
from ray._private.accelerators.apple_gpu import AppleGPUAcceleratorManager
from ray._private.accelerators.hpu import HPUAcceleratorManager
from ray._private.accelerators.npu import NPUAcceleratorManager



def get_all_accelerator_managers() -> Set[AcceleratorManager]:
"""Get all accelerator managers supported by Ray."""
return {
Expand All @@ -18,6 +20,7 @@ def get_all_accelerator_managers() -> Set[AcceleratorManager]:
AMDGPUAcceleratorManager,
TPUAcceleratorManager,
NeuronAcceleratorManager,
AppleGPUAcceleratorManager,
HPUAcceleratorManager,
NPUAcceleratorManager,
}
Expand Down Expand Up @@ -69,6 +72,7 @@ def get_accelerator_manager_for_resource(
"AMDGPUAcceleratorManager",
"TPUAcceleratorManager",
"NeuronAcceleratorManager",
"AppleGPUAcceleratorManager",
"HPUAcceleratorManager",
"NPUAcceleratorManager",
"get_all_accelerator_managers",
Expand Down
51 changes: 51 additions & 0 deletions python/ray/_private/accelerators/apple_gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import logging
from typing import Optional, List, Tuple

from ray._private.accelerators.accelerator import AcceleratorManager

logger = logging.getLogger(__name__)

class AppleGPUAcceleratorManager(AcceleratorManager):
"""Apple GPU accelerators manager."""

@staticmethod
def get_resource_name() -> str:
return "GPU"

@staticmethod
def get_visible_accelerator_ids_env_var() -> str:
# There isn't a direct equivalent to CUDA_VISIBLE_DEVICES for Apple Silicon GPUs.
# However, the USE_MPS environment variable can be used for enabling MPS support in PyTorch.
return "USE_MPS"

@staticmethod
def get_current_node_num_accelerators() -> int:
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the currently node doesn't have apple accelerators, we shouldn't return 1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
quick question. All Apple silicon laptops have mps accelerator support.
So shouldn't it always be 1?


@staticmethod
def get_current_node_accelerator_type() -> Optional[str]:
return "Apple GPU" # Generic name, as there isn't a specific model like Nvidia's H100

@staticmethod
def validate_resource_request_quantity(quantity: float) -> Tuple[bool, Optional[str]]:
if quantity >= 0:
return True, None
else:
return False, "Quantity cannot be negative."

@staticmethod
def get_current_process_visible_accelerator_ids() -> Optional[List[str]]:
return None

@staticmethod
def set_current_process_visible_accelerator_ids(ids: List[str]) -> None:
pass

@staticmethod
def get_ec2_instance_num_accelerators(instance_type: str, instances: dict) -> Optional[int]:
return None

@staticmethod
def get_ec2_instance_accelerator_type(instance_type: str, instances: dict) -> Optional[str]:
return None