NOTE
Large Language Models (LLM)
Follow how large language models are built, from data preparation and architecture to training, inference, scaling, and optimization.
Large Language Models (LLM)
What Is an LLM?
- A language model trained at a significantly larger scale
- Size
- Training Data
- Parameter Count
- Training Compute
- Why Language Models Scale
- Other algorithms
- Object Detection
- Representative model: YOLO
- Topic Modeling
- Representative model: LDA
- Object Detection
- Self-Supervised Learning
- Does not require manually labeled data
- By contrast, supervised learning relies on labeled examples
- Other algorithms
- Size
How to Build an LLM
- Prepare Training Data
- Common Sources of LLM Pretraining Data
- Web Data
- │ ├── Common Crawl
- Custom-built web crawlers
- {\cHFFFFFF}{\cH00FF00} {\cHFFFFFF}{\cH00FFFF} {\cHFFFFFF}{\cH00FFFF} {\cHFFFFFF}{\cH00FFFF}{\cH00FFFF}
-
- Professional data
- Ideas - Academic Papers
- Books
- Code repositories
- Licensed Data
- │ Data obtained through authorization agreements
- Pirate
- Proven case: Anthropic / In 2025, the U.S. Federal Court of California heard the Bartz v. Anthropic case. / Court documents disclose that Anthropic obtained: / Source of data / Books 3 about 197,000 copies by 2021 Load / Library Genesis (LibGen) Load / Pirate Library Mirror (PiLiMi) Load
- Pirate
- │ Data obtained through authorization agreements
- Synthetic Data
- └ - Data generated by models or programs
- If there’s an AI-generated data, why is the data missing?
- Number
- AI can generate text on a continuous basis, theoretically close to infinite.
- Quality
- AI does not necessarily produce the correct content or have sufficient information value.
- Model collapse: The use of data generated by previous generations for training on re-entry indiscriminately may lead to the gradual loss of long tailings from the distribution of raw data.
- AI does not necessarily produce the correct content or have sufficient information value.
- Diversity
- Even if the generated content is correct, the lack of new knowledge and diversity may prevent the continued upgrading of modelling capabilities.
- Innovation?
- Just like humans: summarizing leads you to the pattern, backs up because you’re going to explain, you’re going to extrapolate a testable prediction, you’re going to test the hypothesis. / These three reasonings complement each other and constitute a more complete process of scientific research. / Stanford Philosophy Encyclopedia. / There is also a key distinction: the development of a hypothesis that others have not made is a potential innovation; it can be further recognized as an innovation only if it is validated and new value or knowledge is generated.
- https://chatgpt.com/c/example
- Innovation?
- Even if the generated content is correct, the lack of new knowledge and diversity may prevent the continued upgrading of modelling capabilities.
- Number
- Web Data
- Common Sources of LLM Pretraining Data
- Model Architecture
- Architecture
- Transformer
- Based on seq2seq
- What It Is
- It is a modelling method for converting input sequences into output sequences.
- Modules
- Encoder
- Encoding input sequences as internal expressions
- It’s kind of like compression.
- Enter token, output is the final hidden state of the input
- Process
- Step 1: Tokenizer, convert text to Token ID
- Step 2: Embeding, convert Token ID to vector
- Step 3: RNN Encoder calculates the hidden status in order
- Legend
- Enter Text / “I love cat” / ↓ / Tokenizer / [1, 2, 3] / ↓ / Embedding / x₁ = [1,0] / x₂ = [0,1] / x₃ = [1,1] / ↓ / RNN Encoder / h₁ = RNN(x₁,h₀) / h₂ = RNN(x₂,h₁) / h₃ = RNN(x₃,h₂) / ↓ / Output hidden status associated with context / h₃ = [0.828,0.881] / ↓ / Pass to Decoder
- Enter Text / “I love cat” / ↓ / Tokenizer / [1, 2, 3] / ↓ / Embedding / x₁ = [1,0] / x₂ = [0,1] / x₃ = [1,1] / ↓ / RNN Encoder / h₁ = RNN(x₁,h₀) / h₂ = RNN(x₂,h₁) / h₃ = RNN(x₃,h₂) / ↓ / Output hidden status associated with context / h₃ = [0.828,0.881] / ↓ / Pass to Decoder
- Encoding input sequences as internal expressions
- Codec
- Based on internal indications, the output sequence is gradually generated.
- Process
- (untitled topic)
- Just like the encoder, there’s a lot of steps to turn the hidden state into a probability.

- It’s called hiding. It means in the middle. / state := []float64{0, 0} / for _, token := range tokens { / state = RNN(token, state) / }
- Linear
- Linear: Convert hidden status to the fraction of each candidate word
- logit scores
- https://chatgpt.com/c/example
- Linear: Convert hidden status to the fraction of each candidate word
- Softmax
- Convert logit scores to probability
- Just like the encoder, there’s a lot of steps to turn the hidden state into a probability.
- (untitled topic)
- Legend
- Encoders and decoders use RNN.
- Circulatory neural network.
- Gradient
- Gradient is the attribute of the loss function to a variable and is used to measure how changes in the variable affect the loss.
- Problems
- Gradient Missing
- Gradient explosion
- Gradient is the attribute of the loss function to a variable and is used to measure how changes in the variable affect the loss.
- Gradient
- The cycle here means that the nerve network, when dealing with sequences, transmits the status of the previous step to the next.
- Circulatory neural network.
- Encoder
- Problems
- Solve
- Attention Mechanism
- It inherited the classic Seq2Seq encoder-coder idea, but replaced the traditional RNN loop calculation with Attention.
- Attention Mechanism
- Serial Calculation
- RNN Encoder must rely on the previous Token’s hidden state, making it difficult to calculate in parallel within the sequence.
- Information Bottleneck
- Classic Seq2Seq compresses the entire input sequence into a fixed-length vector from which Decoder can hardly recover all important information.
- no-loss compression by analogy
- A fixed-volume vector is unlikely to represent all input sequences of any length without loss.
- The traditional RNN Seq2Seq uses a fixed long vector, essentially a trade-off between information capacity and costing.
- Traditional RNN Seq2Seq / │ / Ideas - Fixed Length / Idea - Less cost to calculate and store / └ - Long series information bottlenecks / ↓ / RNN + Attention / │ / Ideas - Keep Hidden Multiple Locations / Ideas-Decoder Read Information on Needs / └ Increased costs of calculation and storage / ↓ / Transformer / │ / Ideas - Attention becomes the core computing mechanism / Ideas - no longer relying on RNN serial transmission / Ideas - Improved training parallel capabilities / └ - Face long-sequence costing problems
- no-loss compression by analogy
- Classic Seq2Seq compresses the entire input sequence into a fixed-length vector from which Decoder can hardly recover all important information.
- Solve
- Process
- Training process: how models learn to translate
- Encoder + Decoder + Los + Reverse
- Enter Sequence (English) Output Sequence (Chinese) / I love cats.
- Training data: x = 2, y = 10 / │ / ▼ / 1 Forward Dissemination / ŷ = ax²+b / a=1,b=1 / ŷ=5 / │ / ▼ / 2 Calculating Los / L=(5-10)²=25 / │ / ▼ / 3 Reverse transmission / ∂L/∂a=-40 / ∂L/∂b=-10 / │ / ▼ / 4 Optimizer update parameters / a = 1.4 / b = 1.1 / │ / ▼ / 5 Forward transmission again / ŷ=1.4×4+1.1=6.7 / │ / ▼ / 6 Calculating New Los / L=(6.7-10)²=10.89 / │ / ▼ / Repeated training
- https://chatgpt.com/c/example
- Worked Gradient-Descent Example:
ŷ=ax²+b. Treataandbas trainable parameters. This is a simple parameterized mathematical function—not a multilayer neural network—but the same training principles apply. / Define a training sample: inputx=2, targety=10, and initial parametersa=1,b=1. The predictionŷhas not yet been computed. / Step 1 — forward pass:ŷ=ax²+b=1×2²+1=5; the predicted value 5 differs from the target 10. / Step 2 — loss: use squared errorL=(ŷ−y)², appropriate for this regression example rather than token classification. ThusL=(5−10)²=25. Loss calculation alone neither differentiates nor updates parameters. / Step 3 — gradients via the chain rule: sinceL=(ax²+b−y)², the partial derivatives are∂L/∂a=2(ŷ−y)x²and∂L/∂b=2(ŷ−y). At the current values,∂L/∂a=2(5−10)×2²=−40and∂L/∂b=2(5−10)=−10. The other parameter is held constant for each partial derivative. These gradients indicate local changes in loss, not the final best parameter values. / Step 4 — optimizer: choose learning rateη=0.01and applyθ_new=θ_old−η∂L/∂θ. Thena_new=1−0.01×(−40)=1.4andb_new=1−0.01×(−10)=1.1. The model is nowŷ=1.4x²+1.1; its mathematical form has not changed, only its parameters. / Step 5 — evaluate the updated model on the same sample:ŷ=1.4×2²+1.1=6.7andL=(6.7−10)²=10.89. One update reduced loss from 25 to 10.89, but this is not guaranteed for every learning rate or update; excessively large steps can increase loss. / The essential sequence is forward pass → loss calculation → gradient computation → parameter update → new forward pass. For classification or next-token prediction, a different loss (commonly cross-entropy) is more appropriate.
- Worked Gradient-Descent Example:
- Seq2Seq Training: from Input Sequence to Output Sequence. / What it is: Sequence-to-sequence learning maps an input sequence to an output sequence. A classic implementation is an RNN encoder–decoder. Training adjusts parameters to increase the probability of the reference output; the loop is forward pass → loss → backpropagation → parameter update. / 1. Prepare data: source =
I love cat; target =我 爱 猫 <EOS>. During training, both source and target are provided by the dataset. / 2. Encode: tokenizeI love catinto IDs such as[1, 2, 3], then look up trainable embeddingsx₁,x₂,x₃. The RNN encoder computesh₁ = RNN(x₁,h₀),h₂ = RNN(x₂,h₁), andh₃ = RNN(x₃,h₂). The final stateh₃summarizes the source (with possible information loss) and initializes the decoder. / 3. Decode: start from<BOS>. At each step, the RNN uses the previous target token embedding and hidden state, a linear layer produces vocabulary logits, and softmax gives a distribution over candidate tokens. Example probabilities for the correct next tokens areP(我|X,BOS)=0.6,P(爱|X,我)=0.7,P(猫|X,我爱)=0.8, andP(EOS|X,我爱猫)=0.9, whereX=I love cat. / Teacher forcing: during training the decoder receives the previous ground-truth target token, even when the model predicted incorrectly; it does not need to pick the maximum-probability token. There is no rule requiring a prediction probability above 50%. / 4. Calculate loss: token prediction generally uses cross-entropy. Each position contributesLₜ = -ln P(correct token), so total example loss isL = -ln(0.6)-ln(0.7)-ln(0.8)-ln(0.9) ≈ 1.196; mean loss is about0.299. Every step predicts a full vocabulary distribution. Computing the loss measures error; it is not differentiation, and the loss stays positive when the correct token has probability below 1. / 5. Backpropagate: apply the chain rule backward through the computation graph. Gradients flow through decoder time steps, the encoder–decoder connection, and encoder time steps. For an RNN this is backpropagation through time (BPTT). Backpropagation computes gradients; it neither translates the sentence in reverse nor directly determines the optimal parameter values. / 6. Optimize: gradient descent and related optimizers update parameters usingnew = old − learning_rate × gradient. The gradient indicates local sensitivity; the learning rate controls the update size. Continue with the next training batch. / Toy mathematical example: takeŷ = ax²+b,x=2,y=10, initiala=b=1, and learning rateη=0.01. The first forward pass givesŷ=5. With squared-error lossL=(ŷ−y)², we getL=25andL(a,b)=(4a+b−10)². Partial derivatives are∂L/∂a=2(4a+b−10)×4=−40and∂L/∂b=2(4a+b−10)=−10. These are gradients, not new parameter values. / The optimizer updatesa=1−0.01×(−40)=1.4andb=1−0.01×(−10)=1.1. The new prediction isŷ=1.4×2²+1.1=6.7and the new loss is(6.7−10)²=10.89, down from 25. A large learning rate could instead increase loss. One training sample does not uniquely determine both parameters or guarantee generalization. / Analogy: the toy model inputx=2corresponds to the source sequence; targety=10corresponds to reference tokens. The predicted scalar corresponds to per-position token probability distributions;a,bcorrespond to trainable embeddings and encoder, decoder, and output-layer weightsθ. The toy model uses squared error; Seq2Seq typically uses cross-entropy. Both rely on gradients and an optimizer. / Training versus inference: training has source and reference target, uses teacher forcing, computes loss and gradients, and updates weights. Inference has only the source; decoding starts with<BOS>and feeds back generated tokens until<EOS>or another stop condition. Ordinary inference does not update weights. / Key principle: the forward pass computes predictions; loss measures error; backpropagation computes gradients; the optimizer updates parameters. Formally:ŷ=f(x;θ),L=Loss(ŷ,y),g=∂L/∂θ, andθ_new=θ_old−ηg. Training repeats until validation results, budget, or a stopping criterion warrant stopping.
- https://chatgpt.com/c/example
- Training data: x = 2, y = 10 / │ / ▼ / 1 Forward Dissemination / ŷ = ax²+b / a=1,b=1 / ŷ=5 / │ / ▼ / 2 Calculating Los / L=(5-10)²=25 / │ / ▼ / 3 Reverse transmission / ∂L/∂a=-40 / ∂L/∂b=-10 / │ / ▼ / 4 Optimizer update parameters / a = 1.4 / b = 1.1 / │ / ▼ / 5 Forward transmission again / ŷ=1.4×4+1.1=6.7 / │ / ▼ / 6 Calculating New Los / L=(6.7-10)²=10.89 / │ / ▼ / Repeated training
- Enter Sequence (English) Output Sequence (Chinese) / I love cats.
- Encoder + Decoder + Los + Reverse
- Inference: how the model translates a new input
- Encoder + Decoder Generation
- Encoder is exactly the same as the training.
- Input: “I love cat” / │ / ▼ / Tokenizer / │ / ▼ / [1, 2, 3] / │ / ▼ / Embedding / │ / ▼ / x₁ x₂ x₃ / │ / ▼ / RNN Encoder / h₁ = RNN(x₁, h₀) / h₂ = RNN(x₂, h₁) / h₃ = RNN(x₃, h₂) / │ / ▼ / Last hidden state h3
- decoder
- No loss.
- No reverse transmission.
- No teachers forced
- Inference / │ / ▼ / Input: I love cat / │ / ▼ / Tokenizer / │ / ▼ / Embedding / │ / ▼ / RNN Encoder / │ / ▼ / Last hidden state h3 / │ / ▼ / Initialize Decoder / │ / ▼ / Enter
/ │ / ▼ / RNN Decoder / │ / ▼ / Linear + Softmax / │ / ▼ / Next Token Probability Distribution / │ / ▼ / Select a Token / │ / ▼ / Is it EOS? / │ │ / No. Yes. / │ │ / ▼ ▼ / End of Token to be generated / Enter the next step / │ ▼ / Output: I love cats. / │ / └──→ RNN Decoder
- Encoder is exactly the same as the training.
- Encoder + Decoder Generation
- You can actually compare to Hashmap.
- Training process: how models learn to translate
- What It Is
- Original Transformer
- Modules
- encoder
- Self-attension: Multiple location information, which can be calculated in parallel
- Traditional
- Input: I love cat / ↓ / Tokenizer / ↓ / Embedding / ↓ / x₁ x₂ x₃ / I love cat / ↓ / RNN Encoder / h₁ = RNN(x₁, h₀) / ↓ / h₂ = RNN(x₂, h₁) / ↓ / h₃ = RNN(x₃, h₂) / ↓ / Last hidden state h3 / ↓ / Decoder
- Present
- Input: I love cat / ↓ / Tokenizer / ↓ / Embedding / ↓ / Organisation / ↓ / x₁ x₂ x₃ / I love cat / \ | / / \ | / / ↓ ↓ ↓ / Self-Attention / ↓ / FPN Front Feed Network / ↓ / z₁ z₂ z₃ / ↓ / Decoder
- Traditional
- Attention weights
- Why It Is Needed
- Because of the different information contributions that Token may make to the current Token, we need a mechanism to determine dynamically which Token should get.
- Evolution
- No weights
- Include weights
- QKY
- Evolution
- Because of the different information contributions that Token may make to the current Token, we need a mechanism to determine dynamically which Token should get.
- Why It Is Needed
- Self-attension: Multiple location information, which can be calculated in parallel
- decoder
- Masked Self-Attention。
- Traditional
- Encoder finally hidden state h3 / ↓ / Initialize Decoder / ↓ / Enter
RNN→Linear→Softmax / ↓ / “I” is predicted. / ↓ / Enter the real “I” / ↓ / RNN / ↓ / “Love.” / ↓ / Enter real “love” / ↓ / RNN / ↓ / Forecast cat.
- Encoder finally hidden state h3 / ↓ / Initialize Decoder / ↓ / Enter
- Present
- Target text: I love the cat / Decoder input: / I love cats. / │ │ │ │ / ▼ ▼ ▼ ▼ / Embedding / ↓ / Organisation / ↓ / Masked Self-Attention / ↓ / Cross-Attention-Encoder Output / ↓ / FFN / ↓ / Linear + Softmax / ↓ / I love cats.
- Traditional
- Masked Self-Attention。
- encoder
- Process
- Training
- Encoder + Decoder + Los + Reverse
- Inference
- Encoder Encoder Encoder + Decoder Autoregister
- Training
- Modules
- GT Class Transformer
- Process
- Inference
- Prefill
- Parallel processing input token
- Input: / “Translate I love cat into Chinese:” / │ / ▼ / Tokenizer / │ / ▼ / Embedding / │ / ▼ / Transformer Decoder / Parallel processing input Token / │ / Ideas - Create KV Cache / │ / ▼ / First forecast, Token. / │ / ▼ / I’m…
- Parallel processing input token
- Decoding
- Order output token
- Generated: I / │ / ▼ / Transformer Decoder / Using KV Cache / │ / ▼ / Forecast: Love / │ / ▼ / Transformer Decoder / Using KV Cache / │ / ▼ / Forecast: Cat / │ / ▼ / Transformer Decoder / │ / ▼ / Forecast: EOS / │ / ▼ / I love cats.
- Order output token
- Prefill
- Training
- Use cause and effect mask to predict multiple Tokens, calculate Los and update parameters
- Inference
- Modules
- Just decoder.
- Process
- Speech
- Based on seq2seq
- Transformer
- Architecture
- Training
- Process
- Pretraining
- Ideas - Self-supervised learning
- Forward
- Los
- Backward transmission
- Optimizer
- │–output: pre-training basic model
- Purpose
- Pre-training allows models to learn language, knowledge and a certain degree of reasoning
- Post-training
- Purpose
- Let models learn how to use these capabilities according to human requirements.
- Process
- Oversight fine-tuning
- Reliance manual labelling
- Tell the model to answer.
- Assume that users ask: / What’s the GMP schedule model for Go? / A person provides a high-quality answer: / GMP is a running-time scheduling model for Go, consisting of G (Goroutine), M (Machine) and P (Processor)… / The model adjusts the parameters by learning a lot of such question-and-answer data to make itself better at following instructions. / Nature: Show the model the right answer to imitate learning.
- Preference Optimization
- It’s better to teach model answers.
- The same question, the model produces two answers: / Answer A: / The GMP is a schedule model for Go. / Answer B: / The GMP consists of three core components, G, M and P, each with responsibilities for tasks, execution of threads and movement of resources … / The labeler thinks B is better. / The model adjusts the parameters to the preferred data to increase the probability of producing quality answers. / Nature: To make models learn more in line with human preferences by responding more differently.
- Techniques
- RLHF: Enhanced learning based on human feedback.
- There is often a need to train a reward model before optimizing LLM through enhanced learning
- LLM Generation Answers / ↓ / Rating of reward models / ↓ / PPO enhanced learning algorithm / ↓ / Update LLM arguments / ↓ / Make the model more inclined to generate high reward answers
- DPO: Direct preference for optimization.
- LLM was optimized by direct use of human preference data, and independent reward models and enhanced learning processes were omitted.
- Problem / Idea-A: Poor. / – Answer B: Better. / ↓ / DPO Loss / ↓ / Update LLM arguments
- RLHF: Enhanced learning based on human feedback.
- It’s better to teach model answers.
- Oversight fine-tuning
- Purpose
- Pretraining
- Size
- Three main elements
- Process
- (untitled topic)
- Model, what model do you learn from? Parameters, structure, parameter efficiency
- Data, what kind of data do you train? Quantity, quality, diversity
- How much computing resources do you train? GPU Number, Performance, Visibility, Training Duration, FLOPS
- (untitled topic)
- Scaling Law (the law of scale)(N)Training Token Number(D)Training calculations(C)。
- Number of tokens in training
- The data are three golden laws.
- Number
- 13B means 13 billion parameters.
- Quality
- Dataset A: contains a large number of advertisements, garbage pages, duplicate text and erroneous knowledge.
- Data set B: contains selected technical documents, teaching materials, papers and high-quality web pages.
- Diversity
- Number
- Indicates the amount of knowledge the model has learned
- The number of Tokens trained (Training Tokens) refers to the total number of Tokens actually processed by the model during the training, rather than the number of Tokens generated by the model after the training has been completed. / More precisely, it is the number of Tokens actually sent to model training after the original text has been pre-processed by Tokenizer, data cleansing, etc.
- The data are three golden laws.
- Model Parameters
- 13B means 13 billion parameters.
- Express the learning ability of the model
- FLOPs
- Calculated resources
- Units
- FLOP
- Total float-point operations required to complete a given task
- FLOP
- Units
- Reflects training costs
- Calculated resources
- Number of tokens in training
- Process
- Law of Size
- What It Is
- Model performance changes according to what pattern when model parameters, training data and calculations are increased.
- The law for calculating the optimal size and the size of the data set
- Formula
- Lulu.

- The index, alpha, determines the rate of change.
- Input expands 10 times, output changes 10 ^ alpha times
- Subtopic 2
- Lulu.
- Outsize Push
- Hyperparameter Migration
- There are 10 super-parameters, and we need a two-dimensional set.
- What It Is
- Use of patterns detected in small-model experiments to predict the performance of larger models.
- Hyperparameter Migration
- Bottleneck
- Data bottlenecks
- High-quality, legally available data that meet training needs are limited, and the marginal cost of continuing to expand data may increase.
- Electricity bottlenecks
- Larger Model + More Training Data / ↓ / More FLOPS / ↓ / More GPU Calculating Time / ↓ / Higher demand for electricity and heat dispersion / ↓ / Limitations on grid capacity, room heat dispersion, equipment cost, etc.
- Decline in proceeds
- Suppose you increase the calculation budget tenfold. / Model performance may be improved, but usually not 10 times. / For example, as the scale expands, Loss may continue to decline, but the improvement is gradually decreasing.
- Data bottlenecks
- Value
- Reduced trial error costs for large-scale training programmes.
- It’s very expensive to practice once. It’s impossible to try all the parameters and data combinations.
- Reduced trial error costs for large-scale training programmes.
- What It Is
- Three main elements
- Process
-
- Inference
- Generation and Output Control
- Sampling
- Problems
- Inconsistency
- Same input, different output
- Cache
- Random Feeds
- Enter a little bit the same. The output is completely different.
- Phrasing
- Memory system
- Same input, different output
- Imagination.
- Reasons
- Self-deception.
- Self-supervising how to hallucinate.
- Pointer
- Overseeing how things are hallucinating.
- Self-deception.
- Reasons
- Inconsistency
- What It Is
- The language model calculates the probability distribution for the next Token and selects one from the candidate Token according to a strategy.
- Token Logit (example) Probability / Cats. 2.30 60%. / Dogs 1.61 30% / Bird 0.51 10%
- The language model calculates the probability distribution for the next Token and selects one from the candidate Token according to a strategy.
- Why It Is Needed
- The model only gives the probability of the next token, but it’s not decided, so it needs a strategy.
- What’s the strategy?
- Greedy.
- Every time you choose the most likely.
- Random
- Choose a random one.
- Greedy.
- Parameters to influence policy
- Temperature
- Reduce the probability of common tokens and increase the probability of unusual ones
- Temperature actually works in Logits, then goes through Softmax, instead of changing probabilities at will.
- topk
- Pick the top k, other alignment. The rest will continue to be unified.
- topp
- The value of k is dynamic.
- Temperature
- Subtopic 7
- Problems
- Generate Control
- Max New Tokens
- EOS (concluded Token)
- Stop Series
- Structure Output
- What It Is
- Output data in the format desired by users
- Methodology
- prompt
- Before deduction, tell the model to output according to the specified format
- Reprocessing
- After deduction, parse, repair or validate the results
- Compute More at Inference Time
- Increase the correctness of the format through additional calculations, retesting, candidate validation etc. during or after the reasoning process
- Binding sampling
- Token generation blocking candidates that do not match syntax or Schema
- Align
- Training phase to make models learn to follow specific output formats
- prompt
- What It Is
- Sampling
- Inference Workflow
- Prefill (prefill)
- The model is a one-time process of known input Token, which calculates the context and prepares the phase of the cache for subsequent generation.
- First token
- Prefill (prefill) / I love cat / │ │ │ / ▼ ▼ ▼ / x₁ x₂ x₃ / │ │ │ / └────────┼─────────┘ / ▼ / Transformer. / │ / ▼ / h₁ h₂ h₃ / │ / Ideas - Save KV Cache / │ / ▼ / First new forecast Token
- The model is a one-time process of known input Token, which calculates the context and prepares the phase of the cache for subsequent generation.
- Decode
- Gradually calculates the next Token process using known context and previously generated Token.
- Follow-up token
- Decode / Round 1: / Context: I love cat / ↓ / Transformer / ↓ / Logits / ↓ / Sampling / ↓ / Yeah. / Round 2: / Context: I love cat / ↓ / Transformer / ↓ / Logits / ↓ / Sampling / ↓ / Cat. / Round 3: / Context: I love cat I like cat / ↓ / Transformer / ↓ / Logits / ↓ / Sampling / ↓ / End Tag
- Gradually calculates the next Token process using known context and previously generated Token.
- Prefill (prefill)
Challenges of Building an LLM
-
- Question of expression: What mathematical functions can express reality? / 2. Optimization: How can the appropriate parameters for this function be found efficiently? / 3. Generalization: How can it be ensured that it applies not only to training data but also to unknown data? / Transformer, among other things, offers a very successful solution to the first problem, while its structural characteristics also facilitate large-scale training in the second. / Thus, the basic training algorithm of the nervous network is not difficult to understand, and it is difficult to get this algorithm to really learn the patterns that can be generalized with complex models, big data and limited computing resources.
How to Optimize It
- Model Distillation
- What It Is
- It’s also known as knowledge distillation.
- Training of student models using monitoring signals provided by teacher models to enable students models to learn about their knowledge or behaviour
- Core Components
- Teacher Model (Teacher Model)
- Provide target behaviour or monitor signals
- It’s usually a more powerful model.
- Stuart Model (student model)
- Knowledge or behaviour in teacher models
- It’s usually a smaller model.
- Teacher Model (Teacher Model)
- Why It Is Needed
- No model distillation
- Higher inference costs for direct deployment of large models
- Small models may not meet mission requirements.
- Higher cost of manual construction of quality training data
- Include model distillation
- Using the skills of teacher models to guide student model training
- Bringing student models close to teacher models for targeted tasks
- Reduced cost of inference and consumption of deployed resources
- No model distillation
- How to Implement It
- Overall Workflow
- Sets the target capacity, selects the teacher-student model, gets the teacher-supervised signal, trains the student model, evaluates distillation effects.
- Main methodology
- Respond to distillation
- Teacher model to generate target impact Response
- Verify Generating Data
- Using data for student models
- Logit distillation
- Output probability distribution for accessing teacher models
- The training of students model corresponds to the output distribution of the teacher model
- Respond to distillation
- Training methods
- Train students from scratch
- Fine-tuning based on pre-training models
- Overall Workflow
- How to Evaluate
- Target mission performance
- Performance gap with teacher models
- Inference Latency
- Inference Costs
- Panoramic capacity and long tailings performance
- Limitations
- Not ensuring that the student model reaches the full capacity of the teacher model
- Could be a teacher’s error.
- Teachers monitor the quality of signals and influence distillation
- Need to comply with license for model output data
- Relationship to Synthetic Data
- Data synthesis
- Responsible for generating training data
- Model distillation
- Responsible for moving the skills of the teacher model to the student model
- The two can be combined.
- Teacher model generation data, validation data, student training model.
- Not all training using synthetic data is distillation.
- Data synthesis
- What It Is
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.





Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub