0Pricing
Deep Learning Academy · درس

CPU مقابل GPU مقابل MPS: اختر جهازًا

اكتشف CUDA أو Apple MPS، أو ارجع إلى CPU

CPU مقابل GPU مقابل MPS: اختر جهازًا درس مجاني في Deep Learning Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Deep Learning Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Where Math Happens

Every tensor lives on a device: the CPU, a GPU, or Apple's MPS. The device decides how fast your model trains. ⚡

The CPU Always Works

Your CPU is the safe default. It runs every PyTorch operation, just more slowly on the heavy matrix math that big networks demand.

The GPU Goes Fast

A GPU does thousands of multiplications in parallel, making it far faster for deep learning. PyTorch reaches NVIDIA GPUs through CUDA.

Apple Silicon Has MPS

On a Mac with Apple Silicon, MPS taps the built-in GPU. It is the fast path for M-series chips without any NVIDIA hardware.

Detect CUDA

Ask PyTorch whether an NVIDIA GPU is available before you use one. cuda.is_available returns True or False so you never assume.

torch.cuda.is_available()

Detect MPS

On a Mac, check the Apple backend the same way. mps.is_available tells you if the M-series GPU is ready to use.

torch.backends.mps.is_available()

Pick the Best Device

A clean pattern tries CUDA first, then MPS, then falls back to CPU. This device string adapts to whatever machine runs your code.

device = 'cuda' if torch.cuda.is_available() else 'cpu'

Move a Tensor

Send data to the chosen device with .to(device). The tensor's numbers are unchanged, but its math now runs there.

x = torch.tensor([1.0, 2.0]).to(device)

Keep Everything Together

Your model and your data must share one device. Mixing CPU and GPU tensors throws a device mismatch error during the forward pass.

Check Where a Tensor Lives

Not sure where data sits? Read the .device attribute. It prints cpu, cuda, or mps so you can confirm placement at a glance.

print(x.device)

When to Use Which

Use the GPU for real training, and the CPU for quick tests or tiny data. The fastest device is the one your hardware actually has.

Quick Check

Pick the right call for a Mac with Apple Silicon.

Recap

You learned to detect CUDA, MPS, or CPU, pick the best one, and move tensors there. Same code, fastest hardware available. 🚀

الأسئلة الشائعة

هل درس «CPU مقابل GPU مقابل MPS: اختر جهازًا» مجاني؟

نعم — نص درس «CPU مقابل GPU مقابل MPS: اختر جهازًا» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Deep Learning Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Deep Learning Academy 4 دروس في المجموع.

ماذا ستتعلم في «CPU مقابل GPU مقابل MPS: اختر جهازًا»؟

اكتشف CUDA أو Apple MPS، أو ارجع إلى CPU تتمرن على Deep Learning Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Deep Learning Academy؟

لا تُشترط خبرة سابقة. Deep Learning Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «CPU مقابل GPU مقابل MPS: اختر جهازًا»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Deep Learning Academy هذا؟

نعم. كل درس في Deep Learning Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تثبيت PyTorch والتحقق من استيراده
  2. CPU مقابل GPU مقابل MPS: اختر جهازًا
  3. دفاتر الملاحظات والبرامج والبذور القابلة لإعادة الإنتاج
  4. أول torch.tensor لك
← العودة إلى Deep Learning Academy