seniorPyTorch
What is gradient detachment and why is it important?
Updated May 17, 2026
Short answer
detach() stops gradient flow by removing tensor from computation graph.
Deep explanation
detach() creates a new tensor sharing storage but not connected to autograd graph. This prevents gradients from flowing backward through that tensor, useful in reinforcement learning and target networks.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro