From 280afbf6167c2b676f4aba525a432d997943f901 Mon Sep 17 00:00:00 2001 From: Devi Krishna Date: Mon, 8 Jun 2026 12:34:59 +0400 Subject: [PATCH 1/2] feat(phase-00/03): add mps check script --- .../03-gpu-setup-and-cloud/code/mps_check.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py diff --git a/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py b/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py new file mode 100644 index 0000000000..acc7af93b3 --- /dev/null +++ b/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py @@ -0,0 +1,50 @@ +import torch +import time +import psutil +import platform + +def check_mps(): + print("====MPS Check====\n") + print(f"pytorch_version: {torch.__version__}") + print(f"mps_available: {torch.backends.mps.is_available()}") + + if not torch.backends.mps.is_available(): + print("\nNo MPS detected. That's fine for most lessons.") + print("For GPU-heavy lessons, use Google Colab (free).") + return + + print(f"MPS device: Apple {platform.processor()} (MPS backend)") + + + print("\n=== CPU vs MPS Benchmark ===\n") + size = 4000 + a = torch.randn(size, size) + b = torch.randn(size, size) + + + start = time.time() + _ = a @ b + cpu_time = time.time() - start + print(f"CPU matrix multiply ({size}x{size}): {cpu_time:.3f}s") + + if torch.backends.mps.is_available(): + a_mps = a.to("mps") + b_mps = b.to("mps") + torch.mps.synchronize() + + start = time.time() + _ = a_mps @ b_mps + torch.mps.synchronize() + mps_time = time.time() - start + print(f"MPS matrix multiply ({size}x{size}): {mps_time:.3f}s") + print(f"Speedup: {cpu_time / mps_time:.0f}x") + + total_ram = psutil.virtual_memory().total + vram_gb = total_ram / 1e9 + params_fp16 = vram_gb * 1e9 / 2 + params_billions = params_fp16 / 1e9 + print(f"\nEstimated max model size (fp16): ~{params_billions:.0f}B parameters") + + +if __name__ == "__main__": + check_mps() \ No newline at end of file From 89a9864f42615f8b5c9adaacea98ee60bb4d31fb Mon Sep 17 00:00:00 2001 From: Devi Krishna Date: Mon, 8 Jun 2026 13:20:10 +0400 Subject: [PATCH 2/2] ix(phase-00/03): replace psutil with stdlib RAM probe --- .../03-gpu-setup-and-cloud/code/mps_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py b/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py index acc7af93b3..632f79d7c0 100644 --- a/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py +++ b/phases/00-setup-and-tooling/03-gpu-setup-and-cloud/code/mps_check.py @@ -1,7 +1,7 @@ import torch import time -import psutil import platform +import os def check_mps(): print("====MPS Check====\n") @@ -39,7 +39,7 @@ def check_mps(): print(f"MPS matrix multiply ({size}x{size}): {mps_time:.3f}s") print(f"Speedup: {cpu_time / mps_time:.0f}x") - total_ram = psutil.virtual_memory().total + total_ram = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES") vram_gb = total_ram / 1e9 params_fp16 = vram_gb * 1e9 / 2 params_billions = params_fp16 / 1e9