PyTorch is a popular open-source library for machine learning and deep learning. It helps you build and train neural networks easily.
Click to reveal answer
beginner
Why do we need a GPU for deep learning?
GPUs can do many calculations at the same time, making training deep learning models much faster than using a CPU alone.
Click to reveal answer
beginner
How do you check if PyTorch can use your GPU?
You can run the code: <code>import torch; torch.cuda.is_available()</code>. It returns True if PyTorch detects a GPU.
Click to reveal answer
intermediate
What command installs PyTorch with GPU support?
Use the command from the official site, for example: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 to install PyTorch with CUDA 11.8 support.
Click to reveal answer
beginner
What is CUDA in the context of PyTorch?
CUDA is a technology by NVIDIA that allows programs to use the GPU for fast computing. PyTorch uses CUDA to speed up training on NVIDIA GPUs.
Click to reveal answer
Which command checks if PyTorch can use the GPU?
Atorch.cuda.is_available()
Btorch.gpu.check()
Ctorch.device('cpu')
Dtorch.check_gpu()
✗ Incorrect
The correct command is torch.cuda.is_available(), which returns True if a GPU is available.
What does CUDA stand for in PyTorch GPU setup?
AComputer User Data Application
BCentral Unit Data Access
CCompute Unified Device Architecture
DCore Unified Device Algorithm
✗ Incorrect
CUDA stands for Compute Unified Device Architecture, a platform by NVIDIA for GPU computing.
Why is a GPU preferred over a CPU for training deep learning models?
AGPUs can perform many calculations at once
BGPUs use less electricity
CCPUs are slower at basic math
DCPUs cannot run Python code
✗ Incorrect
GPUs are designed to do many calculations in parallel, speeding up training.
Which PyTorch package is NOT typically installed for GPU support?
Atorchvision
Btensorflow
Ctorchtext
Dtorchaudio
✗ Incorrect
TensorFlow is a different library, not part of PyTorch packages.
What should you do if torch.cuda.is_available() returns False but you have a GPU?
AUse CPU only
BRestart your computer
CUninstall PyTorch
DCheck if CUDA drivers are installed correctly
✗ Incorrect
If PyTorch can't detect the GPU, check that CUDA drivers and toolkit are installed properly.
Explain the steps to install PyTorch with GPU support on your computer.
Think about how you find the right command and check if GPU works.
You got /4 concepts.
Describe why GPUs are important for training machine learning models and how PyTorch uses them.
Consider the difference between CPU and GPU computing.
You got /4 concepts.
Practice
(1/5)
1. What is the correct command to install PyTorch using pip?
easy
A. pip install torch-gpu-support
B. pip install pytorch-gpu
C. pip install torch-cuda
D. pip install torch torchvision torchaudio
Solution
Step 1: Understand PyTorch installation command
The official PyTorch installation command is pip install torch torchvision torchaudio.
Step 2: Check other options
Other options like pytorch-gpu or torch-cuda are not valid package names for PyTorch installation.
Final Answer:
pip install torch torchvision torchaudio -> Option D
This function returns a boolean: True if a GPU is available, otherwise False.
Step 2: Given GPU is available
The code prints the result of torch.cuda.is_available(), so it will print True.
Final Answer:
True -> Option A
Quick Check:
GPU available? = True [OK]
Hint: If GPU exists, torch.cuda.is_available() returns True [OK]
Common Mistakes:
Expecting string output instead of boolean
Confusing True/False values
Assuming function raises error if no GPU
4. Identify the error in this code snippet for checking GPU availability:
import torch
if torch.cuda.is_available:
print("GPU is ready")
else:
print("GPU not found")
medium
A. Missing parentheses after is_available
B. Incorrect import statement
C. Wrong print syntax
D. No error, code is correct
Solution
Step 1: Check function call syntax
torch.cuda.is_available is a function and must be called with parentheses: torch.cuda.is_available().
Step 2: Verify other parts of code
Import and print statements are correct. The only error is missing parentheses.
Final Answer:
Missing parentheses after is_available -> Option A
Quick Check:
Function call needs () = Missing parentheses [OK]
Hint: Remember to add () when calling functions like is_available [OK]
Common Mistakes:
Forgetting parentheses on function calls
Assuming is_available is a property, not a method
Misreading indentation or print syntax
5. You want to run your PyTorch model on GPU if available, otherwise on CPU. Which code snippet correctly sets the device?
hard
A. device = torch.device('cuda:0' if torch.cuda.is_available else 'cpu:0')
B. device = torch.device('gpu' if torch.cuda.is_available() else 'cpu')
C. device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
D. device = torch.device('cuda:1' if torch.cuda.is_available() else 'cpu')
Solution
Step 1: Understand device selection syntax
PyTorch uses torch.device('cuda') for GPU and torch.device('cpu') for CPU.
Step 2: Check conditional device assignment
The correct way is to use 'cuda' if GPU is available, else 'cpu'. device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') uses this correctly.
Step 3: Analyze other options
device = torch.device('cuda:0' if torch.cuda.is_available else 'cpu:0') omits parentheses after torch.cuda.is_available, so the function is not called (function object is truthy), always selecting GPU even if unavailable at runtime. device = torch.device('gpu' if torch.cuda.is_available() else 'cpu') uses invalid 'gpu' string. device = torch.device('cuda:1' if torch.cuda.is_available() else 'cpu') forces 'cuda:1' which may not exist.
Final Answer:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') -> Option C
Quick Check:
Use 'cuda' or 'cpu' strings correctly for device [OK]
Hint: Use 'cuda' string, not 'gpu', for device selection [OK]
Common Mistakes:
Forgetting parentheses after torch.cuda.is_available()
Using 'gpu' instead of 'cuda' in device string
Hardcoding GPU index without checking availability
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.