Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(phase-00/03): add mps check script#271

Open
Devikrishna545 wants to merge 2 commits into
rohitg00:main from
Devikrishna545:my-progress
Open

feat(phase-00/03): add mps check script #271
Devikrishna545 wants to merge 2 commits into
rohitg00:main from
Devikrishna545:my-progress

Conversation

@Devikrishna545

@Devikrishna545 Devikrishna545 commented Jun 8, 2026

Copy link
Copy Markdown

What this PR does

Adds an MPS check script for Phase 00 Lesson 03 and fixes PyTorch MPS API usage so the script runs cleanly on Apple Silicon environments with MPS support.

Kind of change

  • New lesson
  • Fix to an existing lesson
  • Translation
  • New output (prompt, skill, agent, MCP server)
  • Docs / website / tooling

Checklist

  • [x ] Code runs without errors with the listed dependencies
  • No comments in code files (docs explain, code is self-explanatory)
  • Built from scratch first, then shown with a framework (for new lessons)
  • Lesson folder matches LESSON_TEMPLATE.md structure
  • ROADMAP.md row for the lesson is a markdown link ([Name](phases/...)), not bare text
  • One lesson per commit (atomic per-lesson rule)
  • Tested locally / code output matches what docs/en.md claims

Phase / lesson

Phase 00 · 03-gpu-setup-and-cloud

Notes for reviewer

  • Added [mps_check.py](as a practical environment check for Apple MPS.
  • Replaced non-portable/invalid MPS calls with compatible ones:
  • removed use of torch.version.mps
  • replaced backend synchronize usage with torch.mps.synchronize()
  • used platform-based device info output
  • Scope is intentionally minimal: one lesson, one commit, no ROADMAP/README structure changes.

coderabbitai Bot commented Jun 8, 2026
edited
Loading

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

i️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1e6d3c88-7ecd-4a8e-9803-aaa635dc1049

📥 Commits

Reviewing files that changed from the base of the PR and between 280afbf and 89a9864.

📒 Files selected for processing (1)
  • phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py

📝 Walkthrough

Walkthrough

This PR adds mps_check.py, a script that verifies PyTorch MPS availability, prints device/version info, runs CPU and conditional MPS matrix-multiplication benchmarks with proper MPS synchronization, computes speedup, estimates FP16 model capacity from system RAM via os.sysconf, and runs check_mps() under __main__.

Changes

MPS Availability and Benchmarking

Layer / File(s) Summary
Imports and MPS availability check
phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py
Adds imports and defines check_mps() which prints torch version, checks torch.backends.mps.is_available(), prints device info, and returns early with guidance if MPS is unavailable.
Benchmarking, reporting, and entry point
phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py
Implements CPU matmul timing and conditional MPS matmul timing with explicit torch.mps.synchronize() surrounding timed sections, prints CPU vs MPS times and speedup, estimates FP16 max model size using total RAM from os.sysconf, and adds if __name__ == "__main__": check_mps().

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat(phase-00/03): add mps check script' clearly and concisely describes the main change—adding an MPS check script for Phase 00 Lesson 03.
Description check ✅ Passed The PR description is well-related to the changeset, detailing what MPS check script was added and which PyTorch MPS API calls were fixed for Apple Silicon compatibility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py (1)

9-11: ⚡ Quick win

Cache MPS availability once to reduce repeated backend checks.

You call torch.backends.mps.is_available() multiple times. Store it once (mps_available) and reuse for output/branching to keep the control flow cleaner.

Also applies to: 30-30

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py` around
lines 9 - 11, Cache the result of torch.backends.mps.is_available() in a local
variable (e.g., mps_available) and reuse it for both the print and the
subsequent if-check instead of calling torch.backends.mps.is_available() twice;
update the print call and the if statement to reference mps_available to
simplify control flow and avoid repeated backend queries (apply same change in
the similar occurrence around lines 30-30).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py`:
- Line 3: Remove the psutil import and any psutil-based RAM probes in this file
and replace them with a stdlib solution using os.sysconf; specifically, delete
the "import psutil" and modify the RAM-check logic (wherever
psutil.virtual_memory() or psutil.total is used) to call
os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') (or os.sysconf_names
variant) to compute total RAM, keeping the same variable names and checks so
functions like the module-level RAM check or any function that references the
previous psutil-derived value continue to work without changing external
behavior.
---
Nitpick comments:
In `@phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py`:
- Around line 9-11: Cache the result of torch.backends.mps.is_available() in a
local variable (e.g., mps_available) and reuse it for both the print and the
subsequent if-check instead of calling torch.backends.mps.is_available() twice;
update the print call and the if statement to reference mps_available to
simplify control flow and avoid repeated backend queries (apply same change in
the similar occurrence around lines 30-30).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

i️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f097dd9a-f8a3-41b1-88dc-96eb1b128478

📥 Commits

Reviewing files that changed from the base of the PR and between 0b2b729 and 280afbf.

📒 Files selected for processing (1)
  • phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py

Comment thread phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /