Recall & Review
beginner
What does the
requires_grad flag do in PyTorch?It tells PyTorch whether to track operations on a tensor for automatic differentiation. If
requires_grad=True, PyTorch records operations to compute gradients later.Click to reveal answer
beginner
How do you set a tensor to not track gradients in PyTorch?
You set
requires_grad=False when creating the tensor or use tensor.detach() to stop tracking gradients.Click to reveal answer
intermediate
Why might you want to set
requires_grad=False for some tensors?To save memory and computation when you don't need gradients, like for input data or fixed parameters.
Click to reveal answer
beginner
What happens if you perform operations on a tensor with
requires_grad=True?PyTorch builds a computation graph to track those operations, enabling gradient calculation during backpropagation.
Click to reveal answer
beginner
How can you check if a tensor is tracking gradients?
By accessing the tensor's
requires_grad attribute, which returns True or False.Click to reveal answer
What does setting
requires_grad=True on a tensor do?✗ Incorrect
Setting
requires_grad=True tells PyTorch to track operations on the tensor for automatic differentiation.How can you stop a tensor from tracking gradients after it was created with
requires_grad=True?✗ Incorrect
tensor.detach() creates a new tensor that does not track gradients.Why might you want to set
requires_grad=False for some tensors?✗ Incorrect
Not tracking gradients saves memory and computation when gradients are not needed.
Which attribute tells you if a tensor tracks gradients?
✗ Incorrect
tensor.requires_grad is a boolean indicating if gradients are tracked.If a tensor has
requires_grad=True, what does PyTorch build during operations?✗ Incorrect
PyTorch builds a computation graph to compute gradients during backpropagation.
Explain the purpose of the
requires_grad flag in PyTorch and how it affects tensor operations.Think about how PyTorch knows which tensors to compute gradients for.
You got /4 concepts.
Describe scenarios when you would set
requires_grad=False for a tensor in a machine learning model.Consider parts of the model that do not learn or update.
You got /4 concepts.