AI Hero Club

Reasoning and Reinforcement Learning · Lesson 5

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 8 subsections
Course Contents 8 lessons
Full course plan.
Reasoning and Reinforcement Learning / Learning Plan ↗

LESSON 05 / 8Suggested study 135 minutes

Connect Complete Trajectories to a Real Transformer

How do two numerical actions map to causal positions in a full Transformer and define one trajectory probability?

3 Questions for This Lesson
  • From input number, response position and causal matrix to complete path
  • Reconciling 2768 parameter ledgers and 10-digit support to one.
  • Achieve a uniform interface for sampling, re-scoring, listing and freezing references
Course Project ZIP ↓

From Finite Policies to a Shared Parameter Network

The first four chapters are derived from a limited probability and are now using the real single layer of Transformer. The project ' s decoder.py contains a complete word mosaic, position mosaic, four head of attention, two layers of reclassification, GELU pre-dip, residual and output header from a teaching decoding device that has been achieved by the course package itself, copying the source and extracting it in a dependency-provenance.json. It is not a pre-training model to download, nor is it a stand-alone probability table for each task; Each input is shared through the same set of parameters, and the gradient updates the full length of the parameter.

Sets a fixed scale of 14 words, top eight in context, hide the width 16, focus four, block one, pre-broadcast 32, dropout zero. The numbering volume for batch B is an integer matrix, embedded into the shape B times T 16; each head is wide 4. The attention score is obtained by root four from the query and the inner build-up of the key, and it is forbidden to look at future positions as negative and negative and to be re-blended. The emphasis in this chapter is not on reproven matrix calculus but on probabilities models of how these outputs correspond to the course, as the import boundary of Transformer.

Parameter Counts Must Match the Actual Tensors

Enter 14 times 16 and the output 14 times 16, both of which are not tied together at 448. The position is embedded at 8 times 16 together at 128. The four non-prejudiced attention projections are 16 times 16 each, totalling 1024; the two pre-bidding matrices are combined at 1024 plus prior feedback deviations by 32 and 16; the two layers are singled with gains and biases by 64; the last of the two levels are consolidated at 32.

“Training for all parameters” refers to the fact that all the weights are true, handed to the optimist, that each of the actual RLs has limited non-zero gradients and non-zero variations, and not every step of the scale coordinates. For example, the position embedded in the seventh line is not visited in the current input length and might not have been updated; some precise symmetrical points in the attention matrix may also be very small. The report retains both the range of gradients and the maximum absolute difference before and after the RL, so that learning is not claimed by looking only at the trainable count.

N=2Vd+Cd+(4d2+2df+f+5d)+2d=2768N=2Vd+Cd+(4d^2+2df+f+5d)+2d=2768
V=14, d=16, C=8, f=32, layer 1 and input output embedded unbound.

Example 1: Aligning Two Response Positions

The complete sequence of task two plus two is [BOS,2,PLUS,2,EQ,4,8,EOS]. From the return of model position four, i.e. the output of equals, the first response four; and the fifth, the output of four, the second response eight. Project Path_logps entered seven numbers to the second number, selecting the output slice four: 6, which corresponds precisely to these two predictions; the final position six output is not necessary because EOS is made by protocol and does not sample from 14 categories.

Many training errors occurred in "Dial the sequence and the same location number directly": that taught the model to copy the current input instead of predicting the next action. Another error was to account for the response loss in all five locations of the entire reminder, optimizing that it blended into the reminder re-establishment task. It was clear here that only two log probabilities responding to the forecast location were collected, and the correct number was added to the match. Test the two independent forwards of the length five and six, checking the same sum, checking the causal alignment, rather than just measuring the function to produce a single metric.

Sampling and Scoring Must Use the Same Constrained Distribution

Sampler does softmax from the top 10 logits at the end of the current position, and then classifies the sample, which is drawn to the numbering of the prefix, and then produces the next step. Scorer re-routed in the training, also using log_softmax for the first ten dimensions, and then takes values based on the sample results. Top-k or temperature scaling when sampling is not possible, the original softmax is still used without correction, because the trajectory comes from another distribution and the on-policy gradient is no longer applicable. The project does not have Top-k, refuses to resampling or is screened on the basis of incentives, and remembers what is taken.

The temperature is also fixed at one; if changed to T, the action score should be used for sampling and rating at the same time as T. Greed is used only for evaluation, which is a definitive choice for the maximum score, and cannot be used as an independent sample training from the current probabilities strategy. It is also clear that EOS enforcement is environmental syntax action, probabilities one, and not random sampling. The course is about strategic learning on restricted trajectories, rather than hiding formats and pretending free text completion rates are high.

log⁡pθ(y∣x)=∑t=01[zt,yt−log⁡∑k=09ezt,k]\log p_\theta(y\mid x)=\sum_{t=0}^{1}\left[z_{t,y_t}-\log\sum_{k=0}^{9}e^{z_{t,k}}\right]
z_t is the original logits corresponding to the predicted location; EOS is a mandatory event.

Example 2: Exhaustive Path Enumeration Checks Probabilities

The fixed input lists the first zero to nine, and the second zero to nine calculus, for a total of 100. For each call, a path_logps is called, indexing is close to one. The first step is the sum of the probability, and the second step is the sum of each first prefix, with a limited amount of peace. This gives an independent mathematical proof that it is unified; the actual list provides a check, which is not the same evidence.

The current project’s float32 network calculates the probability of logs and then turns to the double indexes and search for peace, so the error does not magically turn into pure float64 accuracy. Tests allow small-volume rounding deviations, reporting on the actual probabilities of the subject matter. There is only one strict success path, with a list of expected rewards being the probabilities of that route; the full KL is weighted by 100. It allows each input to produce the highest complete path of response to greed and probabilities, which need not be the same: the desire to select the highest local first step, without necessarily maximizing the full probabilities of the collage.

Reference Copies, Modes, and Gradients

The reference model reproduces the current monitoring weight with Deepcopy and sets each parameter requires_grad as False; the event mode itself controls only module behaviour such as dropout, does not close automatic fractions or prevent the optimist from modifying parameters. Instead, torch.no_gradi only does not record the calculation of maps in a given calculation area and does not permanently freeze the parameters. Full freezing requires clear rights of ownership of the parameters, optimizer parameters pool and gradient paths; the project uses these conditions simultaneously and checks summaries.

When model training is done, dropout zero, so the tradein is the same as the eval's forward profile; then the sample is re-rated to match the sampling distribution. If non-zero dropout is used, sampling and re-scoring see different random masks, these randomities need to be incorporated into a strategy or fixed process, otherwise the probability of the same trajectory cannot be explained by the simple function here. Instead of dropot zero, this course uses it as a modelling condition, which must be re-tested when readers modify the configuration.

The Boundaries Tests Most Often Miss

The test contains future number disturbance: changes in the final response figure to be equal to all previous locations by element, confirming that causal mask is actually valid. Samples are re-used with the seed Generator, and both results must be consistent; responses are also examined article by article for total length three, first two less than ten, and last EOS. Different CPU or PyTorch versions do not commit bitwise to replay, thus freezing the version of evidence records, seeds and single-line settings; offline reporting can only be responsible for the recording environment.

When loading a check point, verify the data summaries and then use the saved configuration to exemplify two models, load the strategy and reference. Totch.load uses the weights_only mode to read the item and the basic packaging to avoid using the counter-sequences of any object as a normal educational material interface; this does not mean that any strange document can be trusted unconditionally. The course provides only the weight of its own generation, without downloading the model or configuration from an external site. If the data contract changes, loading must fail and cannot be interpreted in silence.

What This Lesson Delivers and What Remains

This chapter completes a closed circle of probability from task to log, and contains actual networks, sampling, re-scoring, enumeration, parameter books and reference freezes. It does not train large language models, with 14 numbers in the vocabulary, responding to only two random actions; even if it solves all twenty-five questions, the model cannot be called a generic mathematical reasoning model. We choose this size to allow the full probability and KL to really be accounted for by readers, rather than to use large libraries to cover the most important definitions.

The next chapter starts with 40 steps of monitoring heat and starts with 100 steps of intensive learning on the same network. The heating start itself changes the model, so it must be frozen as a comparable starting point before RL, and the evaluation of the same subject is maintained. Full training projects include gradients, differentials per volume and reference to Hashi; interfaces and probabilities checks in this chapter are prerequisites for these measurements. Any performance conclusions appear in Chapter VII and cannot be stolen from the chapter interface to the goal of training.

Run in the Project DirectoryDirectly Run Check
import torch
from run import setup,Config,TransformerLM,enumerate_paths
setup();m=TransformerLM(Config(vocab_size=14,block_size=8,d_model=16,n_heads=4,n_layers=1,d_ff=32))
assert m.parameter_count()==2768
r=enumerate_paths(m,m,(2,2))
assert abs(r["probability_sum"]-1)<1e-6
assert abs(r["exact_trajectory_kl"])<1e-8
print(r)

TRY IT YOURSELF

Practice one: Position alignment

Enter [BOS,2,PLUS,2,EQ,4,8], which two output locations are used to respond approximably?

Hint 1
Lists each input location from zero, and the next token that is responsible for forecasting.
Hint 2
Only two randomly responded network distributions are maintained; EOS is made subject to protocol probabilities, and the reconstruction of prompt is not included.
Compare with the Solution
From zero number: EQ output projection 4, for position 4, and for position 5, 4 output forecast 8, the output [:,4:6,:10]. The location 6 forecast compels EOS to give probabilities one without using its network softmax. Nor does the reminder mean a response.

TRY IT YOURSELF

Practice II: Arguments Change Configuration

Replace d16 with d32, f64, and the remaining V14, C8, N1 remain unchanged. What are the parameters?

Hint 1
Inserts/head, position table, block, finalLN four sets of accounts first.
Hint 2
At the same time, rewordd and f to replace each item with a focus on d2 items, with the headlines legally removed by no additional additions to the overall parameters.
Compare with the Solution
Embedded Head 2×14 × 32=896 Location 8×32 = 256 blocks 4×32 ²+ 2×32 × 64+64+5 × 32=8416; eventually unicoded 64. Total 9632. The headlines still need to be divided by d, changing the headlines without changing the total number of projector matrix parameters.

TRY IT YOURSELF

Practice 3: Greed is not always the highest.

Step 1 p(A) = 0.6, p(B) = 0.4; best followed by 0. 5 under A and 0. 9 under B. How is greed different from the highest complete path?

Hint 1
The first step is to maximize greed, with the maximum path being two steps in the way.
Hint 2
The probability of optimal completeness is calculated for branches A and B, respectively, without directly extrapolating the entire path from the first steps.
Compare with the Solution
Greed selects A first, and then the best path probability 0.6×0.5 = 0.3. The maximum complete path for branch B is 0.4×0.9 = 0.36, and is even higher. The items record greedy and list best_path, respectively, and cannot be considered automatically identical.

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

Does the 1.val mode freeze parameters?

Show ExplanationThe eval itself does not close the gradient, subject to conditions such as requires_grad and the title of the optimist.
2. Use top-k only during sampling, and what happens if the score is still softmax?

Show ExplanationThe trajectories are derived from cut-off distributions, and the original distribution scores no longer appear to be correct.
What does 3. 2768 full-scale training mean?

Show ExplanationThe unvisited location line can be maintained; the volume of evidence differs from the statement of magnitude.
4. How can you list all KLs?

Show ExplanationThe number of paths increases with the number of actions and length indexes and cannot be extrapolated to a long text.

Manual completion records your progress; it does not certify your project.