0
0
PyTorchml~20 mins

PyTorch ecosystem overview - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PyTorch Ecosystem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding PyTorch's Core Components
Which of the following is NOT a core component of the PyTorch ecosystem?
ANumPy for tensor operations within PyTorch
BTensorBoard for visualization and debugging
CTorchScript for model serialization and optimization
DTorchVision for computer vision datasets and models
Attempts:
2 left
💡 Hint
Think about which library is external and not part of PyTorch itself.
Predict Output
intermediate
2:00remaining
Output of PyTorch Model Training Loop
What will be the printed output after running this PyTorch training loop snippet?
PyTorch
import torch
import torch.nn as nn

model = nn.Linear(2, 1)
criterion = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)

inputs = torch.tensor([[1.0, 2.0]])
targets = torch.tensor([[1.0]])

optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()

print(round(loss.item(), 4))
A0.75
B0.5
C0.25
D0.0
Attempts:
2 left
💡 Hint
The loss is the mean squared error between model output and target before the optimizer step.
Model Choice
advanced
2:00remaining
Choosing the Right PyTorch Ecosystem Library
You want to train a natural language processing model using pre-built datasets and tokenizers. Which PyTorch ecosystem library should you use?
ATorchServe
BTorchAudio
CTorchText
DTorchVision
Attempts:
2 left
💡 Hint
Think about which library focuses on text data.
Hyperparameter
advanced
2:00remaining
Effect of Learning Rate in PyTorch Optimizer
If you increase the learning rate in a PyTorch optimizer too much, what is the most likely effect on training?
ATraining will always reach a better minimum
BTraining will ignore the learning rate and behave the same
CTraining will converge faster and more smoothly
DTraining may become unstable and loss may oscillate or diverge
Attempts:
2 left
💡 Hint
Think about what happens if steps are too large when trying to find a minimum.
Metrics
expert
2:00remaining
Calculating Accuracy from PyTorch Model Outputs
Given a batch of model outputs as logits and true labels, which code snippet correctly computes the classification accuracy in PyTorch?
PyTorch
outputs = torch.tensor([[2.0, 1.0, 0.1], [0.5, 2.5, 0.3], [1.2, 0.7, 2.1]])
labels = torch.tensor([0, 1, 2])
A
preds = outputs.argmax(dim=1)
accuracy = (preds == labels).float().mean().item()
B
preds = outputs.max(dim=0)[1]
accuracy = (preds == labels).float().mean().item()
C
preds = outputs.argmax(dim=1)
accuracy = (preds == labels).sum().item()
D
preds = outputs.max(dim=1)[0]
accuracy = (preds == labels).float().mean().item()
Attempts:
2 left
💡 Hint
Check how to get predicted class indices and how to compute mean accuracy.