PyTorch
From scalding to auto-divideing to recoverable training code.
- Readable articles
- 25
- System Chapters
- 2
Linking concepts with system chapters.
Read the whole thing first
- Complete a training loop
Align data, patterns, losses, gradients, parameter updates and statistical calibres to check training codes using a small, measurable PyTorch example.
- PyTorch: Where the gradient goes, what the model keeps
Checks the calculation chart, gradient add-up, parameter registration and training status, starting with leaf lengths and shared parameters.
Start with definitions, symbols and minimum examples.
Introduction
- Threshold stride: How the multidimensional index finds a dimension of storage
Thrusts are usually stored in one dimension to accompany shape, stride and starting deviation description of multi-dimensional data.
- Inverse of broadcast: how to retrieve the gradient from the bias used for replication
We'll add one sample to the same sample. bias ♪ When it looks like a front ♪ bias Copy to each line.
- 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.
- collate_fn: convert the sample collection into a clear batch protocol
Dataset returns a single sample, and DataLoader also requires multiple sample formation models to be entered.
See the difference between reasoning, realization and methodology.
Step
- view and reshape: The shape is not compatible with the layout
In order to change the matrix to a vector, it is necessary to retain the sequence of logical elements as defined.
- Conversion and continuity: exchange semantic and arrange memory
Sequence data are commonly used [B], T, D], and some calculations are expected [B], D, T].
- expand and repeat: Storage and writing boundaries behind the same values
Expanding a vector to multiple lines allows the same values to be obtained mathematically, while using different memory strategies.
- Index reading and writing: different compacts between basic slices and advanced indexes
The length index also involves selecting which elements are stored in relation to the return.
- gather: Which axis the index follows, where the gradient returns
In batch tasks, each sample may need to select a number of values based on its own index, such as extracting certain candidate scores.
- scatter_add: Repeated target location must be highlighted
Multiple sources may point to the same target, for example, multiple sides of the map send messages to a node, or samples are assigned to the same statistical barrel.
- detach and clone: Guidance and memory copying are two axes
When it is necessary to keep intermediate results for logs, teacher targets or reprocessing, there are regular encounters with detach and clone.
- In situ modification and version check: who overwrites old values needed in reverse
Some calculations require the use of forward saved input or output.
- grad for None and Zero: Optimizer may take different actions
A clear gradient can set grad as None or the existing gradient can be kept to zero.
- no_grad and inference_mode: The reduction of records does not equal to the change of model behaviour
model. eval changes the forward behaviour of certain modules, such as Dropout and BatchNorm; no_grad controls whether to record the gradient of the current operation.
- buffer: Non-training status also requires model contracts
Models may need to be estimated during the training period with a unimodal mean value, fixed mask or a constant location.
- Parameter registration: Why could the layers in list be missing
Placing several layers into normal list, forward caller one by one is likely to succeed.
- Parameter group: How different layers of step are used
Relocation learning may lead to lower learning rates for the base and faster updates of new tasks; It may also apply only a partial decay of weight.
- Gradient hook: Observation and modification must be named separately
The gradient hook can be viewed in reverse to a volume of guidance received.
- PackedSequence: How to restore identity after pressing the sequence
When recycling the network processes the long sequence, you can skip the position by packing it.
- state_dict snapshot: Saving references does not freeze optimal weight
When the best validation indicator is seen in the training, model. state_dict is assigned to best_state, which looks like a saved model.
- Autocast: Low Precision Range, Calculator Selection and Gradient Scale
Autocast selects the appropriate computational accuracy by sub- and context; The parameters store, optimizer state and conclusion may also use higher accuracy.
- torch. compile: calculate which input conditions are binding for the recovery of the map
torch. compile tries to capture and optimize the compiled volume calculation.
Discuss assumptions, expiry conditions and systemic trade-offs.
Deep
- Customized autograd: Correct forwards do not replace reverse contracts
Customally defined automatic fractional functions are used to encapsulate special calculations or clear reverse rules.