CPU vs. GPU vs. MPS: Gerät auswählen
CUDA oder Apple MPS erkennen oder auf die CPU zurückfallen.
CPU vs. GPU vs. MPS: Gerät auswählen ist eine kostenlose Deep Learning Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Deep Learning Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🚀
Häufig gestellte Fragen
Ist die Lektion „CPU vs. GPU vs. MPS: Gerät auswählen“ kostenlos?
Ja — der vollständige Text von „CPU vs. GPU vs. MPS: Gerät auswählen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Deep Learning Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „CPU vs. GPU vs. MPS: Gerät auswählen“?
CUDA oder Apple MPS erkennen oder auf die CPU zurückfallen. Du übst Deep Learning Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Deep Learning Academy zu starten?
Keine Vorkenntnisse erforderlich. Deep Learning Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „CPU vs. GPU vs. MPS: Gerät auswählen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Deep Learning Academy-Lektion Code schreiben und ausführen?
Ja. Jede Deep Learning Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- PyTorch installieren und den Import überprüfen
- CPU vs. GPU vs. MPS: Gerät auswählen
- Notebooks, Skripte und reproduzierbare Seeds
- Ihr erstes torch.tensor