NumPy boundary: the value reserved is not equal to the gradient retained
In immediate execution, the load can be converted to a NumPy array for observation.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Positioning the breakpoint for leaving the volume operation
- numeric copy distinguishing diagnosis logs from training objectives
Suggested first
- Python Basic Syntax:
- Counting and training closed
A seemingly harmless conversion
In immediate execution, the load can be converted to a NumPy array for observation. But NumPy does not know the history of the TensorFlow recorder. If the projections are converted into arrays and calculated by NumPy, then the volume is returned and the latter part is obtained as a new constant. The values may be exactly the same, but the gradient to the original parameters is broken.
Set w=2, enter x=3, forecast p = wx = 6, target y = 1, loss of half-square error. The correct loss is 12.5, with a gradient of (p−y) x = 15. If p was first converted to a normal number 6 and then packaged into a mass calculated loss, 12.5, the recorder could not recover w from this new constant. Losses seem normal and the most difficult place to detect such errors.
Do not print loss when checking. loss can be requested to check the step from a value to an empty value for a gradient of p and w. If the predictions were to be severed from the model, adjusting the learning rate and the scale of the loss would not repair reliance. The relevant calculations need to be replaced with a volume operation or explicitly recognize that part as essential and use another method of optimization.
Logs can be converted. Targets cannot be replaced
A copy of the value of loss is usually reasonable for recording the log, provided that the original loss volume is still used in reverse. The number of Python float points returned from the log collection function is then referred to the gradient for query, which mistook the observation channel as a training channel. It is recommended that the name be distinguished between loss_tensor and loss_value to prevent later re-engineering.
tf . function Medium Python and NumPy There is another layer of risk: certain calculations are performed and become constant when tracked, and subsequent input changes are not repeated. Random numbers generated by np. random may be fixed in the same diagram if tracked. Different random quantities are required for each operation, a framework random calculation should be used and a clear agreement should be made between the seed and the recovery.
Access to external libraries is not always wrong. Data decoding, offline characterization and non-participating indicators can be performed externally at the right location, but the microboundary of the interface must be clear. If the external process requires training, it cannot simply be returned to the array to pretend that it has joined the chain law.
This section applies to interaction between TensorFlow2 and NumPy. 12.5 and 15 are composite metric calculations. Placing the unguided part of the data pre-processing phase in the explicit form would also facilitate consistency of training and services.
The loss values are correct. Why is it still not enough to justify the training chart?
The value describes the output of the function only at one point, and the gradient also requires the dependency on which the value is generated. The new constant is capable of copying the output, not the historical path.
Print loss. numpy() per se could destroy the original loss?
Usually not. The question is whether the converted values have replaced the subsequent reverse targets. A copy of the observation can be stored in parallel with the continued use of the original sheet.
Sources and reconciliations
Definitions, methods and interfaces are available.
- TensorFlow — Introduction to gradients and automatic differentiation
- TensorFlow — Better performance with tf.function
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.