0
0
PyTorchml~10 mins

Installation and GPU setup in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a GPU is available in PyTorch.

PyTorch
import torch
is_gpu = torch.cuda.[1]()
Drag options to blanks, or click blank then click option'
AisAvailable()
Bis_available
Cis_available()
Davailable()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses () after the function name.
Using incorrect function names like 'isAvailable' or 'available'.
2fill in blank
medium

Complete the code to move a tensor to GPU if available.

PyTorch
device = torch.device('cuda' if torch.cuda.[1]() else 'cpu')
tensor = torch.tensor([1, 2, 3]).to(device)
Drag options to blanks, or click blank then click option'
Ais_available()
Bavailable()
Cis_available
DisAvailable()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the function without parentheses.
Using wrong function names.
3fill in blank
hard

Fix the error in the code to print the name of the current GPU device.

PyTorch
if torch.cuda.is_available():
    print(torch.cuda.get_device_[1]())
Drag options to blanks, or click blank then click option'
Anames
Bname
Cdevice_name
Ddevice
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like 'get_device' or 'get_device_names'.
Missing parentheses after the function.
4fill in blank
hard

Fill both blanks to create a tensor on GPU and print its device.

PyTorch
tensor = torch.tensor([1, 2, 3], device=[1])
print(tensor.[2])
Drag options to blanks, or click blank then click option'
A'cuda'
Bdevice
D'cpu'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cpu' instead of 'cuda' for GPU device.
Trying to call device as a function instead of attribute.
5fill in blank
hard

Fill all three blanks to move a model to GPU and print its device of first parameter.

PyTorch
model = MyModel()
model.to([1])
first_param = next(model.parameters())
print(first_param.[2])
print(torch.cuda.[3]())
Drag options to blanks, or click blank then click option'
A'cuda'
Bdevice
Cis_available()
D'cpu'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cpu' instead of 'cuda' to move model.
Calling device as a function instead of attribute.
Forgetting parentheses in is_available function.