Recall & Review
beginner
What does detaching a tensor from the computation graph mean in PyTorch?
Detaching a tensor means creating a new tensor that shares the same data but is not tracked for gradients. This stops PyTorch from calculating gradients for operations on this tensor.
Click to reveal answer
beginner
How do you detach a tensor from the computation graph in PyTorch?
You use the
.detach() method on a tensor. For example, detached_tensor = tensor.detach().Click to reveal answer
intermediate
Why would you want to detach a tensor during training?
Detaching is useful to stop gradient calculations for parts of the model or data you don't want to update. It saves memory and computation and avoids unwanted gradient flows.
Click to reveal answer
intermediate
What happens if you perform operations on a detached tensor?
Operations on a detached tensor are not tracked by PyTorch's autograd. So, gradients will not be computed for those operations during backpropagation.
Click to reveal answer
advanced
How is
tensor.detach() different from tensor.data in PyTorch?tensor.detach() returns a new tensor detached from the graph but keeps the original tensor intact. tensor.data gives a tensor that shares storage but can lead to unexpected side effects if modified.Click to reveal answer
What does
tensor.detach() do in PyTorch?✗ Incorrect
tensor.detach() creates a new tensor that shares data but is not tracked for gradients.
Why might you detach a tensor during model training?
✗ Incorrect
Detaching stops gradient tracking, saving memory and preventing unwanted updates.
Which method is the correct way to detach a tensor?
✗ Incorrect
tensor.detach() is the official PyTorch method to detach tensors.
What happens if you modify
tensor.data directly?✗ Incorrect
Modifying tensor.data can break autograd and cause bugs.
Operations on a detached tensor will:
✗ Incorrect
Detached tensors do not track operations for gradient calculation.
Explain in your own words what detaching a tensor from the computation graph means and why it is useful.
Think about when you want to stop PyTorch from remembering operations on a tensor.
You got /4 concepts.
Describe the difference between using
tensor.detach() and accessing tensor.data in PyTorch.Consider how each affects the computation graph and safety.
You got /4 concepts.