Add comprehensive Apple Silicon (MPS) and non-CUDA environment support #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements comprehensive support for Apple Silicon (MPS) and non-CUDA environments, enabling HRM to run seamlessly across all hardware configurations without requiring CUDA or FlashAttention dependencies.
Key Changes
Device Detection and Management
utils/device.py
module with automatic device detection:get_device()
: Auto-detects MPS → CUDA → CPU with proper prioritydevice_str()
: Returns clean device string representationchoose_dist_backend()
: Selects appropriate distributed backend (nccl
for CUDA,gloo
otherwise)Training Pipeline Updates
pretrain.py
:.cuda()
calls with.to(DEVICE)
torch.device("cuda")
to use detected deviceEvaluation Pipeline Updates
evaluate.py
:map_location="cuda"
tomap_location=str(DEVICE)
for device-agnostic checkpoint loadingFlashAttention Fallback System
models/layers.py
:run_flash_attn()
function with PyTorchscaled_dot_product_attention
fallbackDocumentation
Benefits
Testing
The implementation has been thoroughly tested with:
Usage
Users can now run HRM on any hardware with the same commands:
# Works on Apple Silicon, CUDA, or CPU OMP_NUM_THREADS=4 python pretrain.py epochs=1 global_batch_size=32
The system automatically detects available hardware and configures accordingly, making HRM truly cross-platform while maintaining optimal performance on each target environment.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.