0
0
PyTorchml~5 mins

requires_grad flag in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AConverts the tensor to a numpy array
BPrevents the tensor from being used in calculations
CDeletes the tensor after use
DTracks operations for gradient computation
How can you stop a tensor from tracking gradients after it was created with requires_grad=True?
ACall <code>tensor.backward()</code>
BSet <code>requires_grad=True</code> again
CUse <code>tensor.detach()</code>
DConvert it to a list
Why might you want to set requires_grad=False for some tensors?
ATo increase the tensor size
BTo save memory and speed up computation
CTo make the tensor immutable
DTo convert the tensor to CPU
Which attribute tells you if a tensor tracks gradients?
Atensor.requires_grad
Btensor.grad
Ctensor.shape
Dtensor.dtype
If a tensor has requires_grad=True, what does PyTorch build during operations?
AA computation graph
BA list of numbers
CA new tensor on CPU
DA random tensor
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.