Skip to content

Conversation

@nschlaepfer
Copy link
Owner

Summary

  • add utilities to detect Apple M3 Max machines with 128GB memory and gate MPS usage to that configuration while still prioritizing CUDA
  • update the main pipeline to use the new select_device helper, logging the device choice
  • adjust base model loading to avoid forcing device_map="auto", keeping compatibility across CUDA, MPS, and CPU

Testing

  • python -m compileall deepseek_qwen2_5_integration_r1.py

https://chatgpt.com/codex/tasks/task_e_68c879619398832c81d48af0ee412241

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds intelligent device selection for PyTorch operations, prioritizing CUDA while restricting MPS (Metal Performance Shaders) usage to Apple M3 Max machines with 128GB memory to ensure optimal performance and compatibility.

  • Implements device detection utilities for Apple Silicon Macs including memory and chip identification
  • Adds a centralized select_device() function with CUDA priority and restricted MPS support
  • Updates model loading to be compatible across different device types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if platform.system() != "Darwin":
return None
try:
output = subprocess.check_output(["sysctl", "-n", name])
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

Using subprocess.check_output with user-controlled input could be vulnerable to command injection. Consider validating the name parameter against an allowlist of known sysctl keys before passing it to the subprocess call.

Copilot uses AI. Check for mistakes.
Comment on lines +125 to +129
print(
"Warning: MPS backend detected but restricted to Apple M3 Max systems "
"with 128GB memory. "
f"Detected chip '{chip_name}' with {mem_gb:.1f}GB. Falling back to CPU."
)
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using the logging module instead of print statements for warnings. This would allow better control over log levels and output formatting in production environments.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +134
print(
"Warning: MPS backend detected but unable to verify Apple M3 Max 128GB "
"requirement. Falling back to CPU."
)
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider using the logging module instead of print statements for warnings. This would allow better control over log levels and output formatting in production environments.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants