Leaf length: Why the middle result grad defaults not to leave
grad, which is viewed for an intermediate result during the training, obtained None, which is easily misconstrued as a branch that has not been involved in learning.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Distinguishing leaves from operating results
- Explain the range of observations for retain_grad
Suggested first
- Python Basic Syntax:
- Thick shape with Index
By going backwards, it doesn't mean it's saving all the mid-level gradients
grad, which is viewed for an intermediate result during the training, obtained None, which is easily misconstrued as a branch that has not been involved in learning. The automatic fraction requires that the guide be passed along the middle node, but it is not necessary to permanently save each gradient in that mass attribute. Whether the default reservation act is performed or not requires separate checks.
Take the mark x=2 created by the user and set requires_grad. Calculates y = 3 x and calculates L = y2. Forward to y=6, L=36; Reverse dL/ dy = 12, dL / dx = 36. x is a leaf that requires a gradient, usually read to 36 in x. grad; y is the result of the operation, and the default y. grad may be None, but this does not mean that dL/ dy has not been calculated.
If you do want to check the gradient of y, you can call retain_grad at the right time to keep this value. This may increase memory occupancy, particularly in the large activation or long sequence, and should not be used unconditionally for each intermediate. The other diagnostic entrance is grad_fn and the appropriate gradient hook, but they are not a substitute for confirming that the loss does depend on the node.
requires_grad and is_leaf are different properties. A normal length without a gradient requirement may also be considered a leaf; The result of an actual device or dtype conversion of a length that requires a gradient may be non-leaf. If the conversion is performed by the same object without change and the behaviour is judged by the specific return object, it cannot be asserted by writing only once at to.
The optimist usually manages a registered Parameter object, and cannot be assumed to be updated by the optimist because the intermediate result is also set by requires_grad. Non-leaf retain_grad is given primarily for observation and does not automatically turn it into model parameters, nor does it automatically change the list of parameters.
The scope of application is listed. PyTorch 2.14 The leaf curriculum is shared with the 2.15 Automated Microdiploma. eager semantics. This is a chain-based rule; The error first records the intermediate None with a non-zero gradient of leaves and avoids adding the wrong "repair" to normal memory management behaviour.
If the median is used only for a diagnostic score that is not added to the final loss, it may indeed not be on this reverse path. Retroactivity should be traced back to the actual target and it cannot be assumed that an estimate has been calculated as necessarily affecting optimization.
y. grad for None, x. grad for 36 conflict?
There is no contradiction, the number of guides is passed through y, but the value of the gradient of the non-leaf is not left in y. grad.
Does retain_grad automatically update y to the optimist?
No, it retains the observation value and does not amount to the registration of Parameter or the modification of the optimizer parameter group.
Sources and reconciliations
Definitions, methods and interfaces are available.
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.