GradientTape: The operation must occur within the records
The automatic fraction requires a calculation path from the target back to the input.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Distinguishing the existence of variables from operations recorded
- Check the specific location of the gradient break
Suggested first
- Python Basic Syntax:
- Counting and training closed
Why are variables there? The gradient is still empty
The automatic fraction requires a calculation path from the target back to the input. Puting an already calculated load into the recorder does not add to the history that produced it. TensorFlow2 by default to be performed immediately, and GradientTape to observe the relevant calculations in the context; Trainingable variables are usually automatically monitored and the generic volume requires clear surveillance. The two rules answer, respectively, “to whom” and “to which part of the record is calculated”.
Sets the value variable x = 3, calculates the gradient of y = x x x in the range of records, and finally requests y for x. Multiplication has two input edges, each contributing another input, so the result is 3+3=6. If y has been obtained before entering the context, even if the value is still 9, it has not left a multiplier in this record and there is a clear reason for returning the air gradient, which does not equal the mathematical lead of zero.
Change the example to y = x x x, z = 2 y. If both steps are in context, z to x to 12; If step 2 is implemented after exit, the recorder does not automatically track the newly created target z. The error is made by moving the loss into the same range as all intermediate changes, then checking whether the variable is monitored and finally checking whether the calculation is minimal and not replacing the optimizer at the outset.
Track from mark to target
For one instalment, model forwards, sample-by-sample losses, and re-entry commitments are included in the recording area. The label itself does not normally require a gradient, but does not allow the prediction to be converted to a Python digitally reconstructed loss. Such a new constant retains the value and discards the computational relationship. The training log has no problem with using copies of values, and the back-to-back target must continue to use the original volume.
Actual debugging can first request the loss of a gradient to an intermediate output and then position the breakpoint forward on a layer. (b) The space value should be recorded when it is seen in the length name, shape and creation location; The replacement of all empty values with zero billings may allow training to continue, while concealing that a branch has never been involved in optimization.
This section is for the immediate mode of TensorFlow2 and the current GradientTape interface. There is still a need for the correct recording range in tf. function, and the execution of the map will not repair the disconnected reliance. The 6 and 12 here are manual calculations, and there are no claims of TensorFlow or equipment training.
Value recovery
x=3assert 2*x == 6assert 2*(2*x) == 12x = 3, range calculation x ²+2 x What's the gradient?
Two square paths contribute 6, linear items contribute 2, total 8. As long as both parts are within the range of the record, the gradient is added by the share input.
Rewrite y =9 outside range to rewrite the gradient of x2?
Can't. The value of the length cannot be determined only by the process of its creation. Square calculations need to be reset to the record, rather than simply copying results.
Sources and reconciliations
Definitions, methods and interfaces are available.
- TensorFlow — Introduction to gradients and automatic differentiation
- Keras 3 — Writing a training loop from scratch in TensorFlow
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.