Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move the model to the GPU device.
PyTorch
model = MyModel() model = model.[1]('cuda')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cpu' instead of 'cuda' moves the model to the CPU, not GPU.
Trying to use a non-existent method like 'cuda_device' or 'device'.
✗ Incorrect
Use model.to('cuda') to move the model to the GPU device.
2fill in blank
mediumComplete the code to wrap the model for multi-GPU training.
PyTorch
model = MyModel().to('cuda') model = torch.nn.[1](model)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
DistributedDataParallel without setting up distributed environment.Using made-up wrappers like 'MultiGPUWrapper'.
✗ Incorrect
Use torch.nn.DataParallel to wrap the model for multi-GPU training easily.
3fill in blank
hardFix the error in the code to correctly move input data to the GPU.
PyTorch
inputs = inputs.[1]('cuda')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use non-existent methods like 'cuda_device' or 'move'.
Forgetting to move inputs to the same device as the model.
✗ Incorrect
Use inputs.to('cuda') to move the input tensor to the GPU device.
4fill in blank
hardFill both blanks to create a dictionary comprehension that stores squared values for even numbers only.
PyTorch
squares = {x: x[1]2 for x in range(1, 11) if x [2] 2 == 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
// instead of % for checking even numbers.Using
+ instead of ** for squaring.✗ Incorrect
The operator ** is used for power, and % is the modulo operator to check even numbers.
5fill in blank
hardFill all three blanks to create a filtered dictionary with uppercase keys and values greater than zero.
PyTorch
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
k.lower() instead of k.upper().Using
< instead of > for filtering.✗ Incorrect
Use k.upper() to uppercase keys, keep values as v, and filter with v > 0.