Search

Search papers and lessons

Qwen2.5 Technical Report

Qwen Team, An Yang, Baosong Yang et al. · 2024

Qwen2.5 trains dense and mixture-of-experts language models on 18 trillion tokens, then post-trains them with supervised tuning, DPO and GRPO.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Architectures
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

Qwen2.5 is a family of large language models, from 0.5 to 72 billion parameters, plus two hosted mixture-of-experts models. The authors raised the pre-training data from 7 to 18 trillion tokens, then post-trained the models with over one million supervised examples, a round of preference optimisation, and reinforcement learning with a reward model. The 72B instruction-tuned model is reported to surpass Llama-3.1-405B-Instruct on several benchmarks.

Builds on: Transformer, Grouped-Query Attention, Rotary Position Embedding, Mixture of Experts, Instruction Tuning, Reinforcement Learning from Human Feedback (RLHF) · Leads to: Direct Preference Optimization, Group Relative Policy Optimization (GRPO)

Why it mattered

Qwen2.5 is one of the largest open-weight model families released with full technical detail. Its weights, quantised versions and base and instruction models were published for common use, so researchers and developers could fine-tune and deploy them without access to a closed API. The report also shows the recipe in the open: how data were filtered and mixed, how hyperparameters were chosen with scaling laws, and how post-training was staged. Specialised models such as Qwen2.5-Math and Qwen2.5-Coder were trained from the same base.

The problem

Before this release, open models were often trained on less data and tuned with simpler recipes, so their gap to closed models was wide. The authors set out to improve three things at once: the knowledge and reasoning that come from pre-training data, the usefulness of answers that come from post-training, and the practical limits of use, such as output length, structured output and context length. Each of these needs a different trade-off in compute, so the design has to balance them across model sizes.

How it works

The report is a pipeline. Each stage feeds the next, so we follow it in order.

  1. Curate the pre-training data. A Qwen2-Instruct model scores each training sample on quality, and low-scoring samples are removed. Math and code data from Qwen2.5-Math and Qwen2.5-Coder are added, and synthetic data is generated and then filtered by reward models.
  2. Balance the domains. Web data over-represents e-commerce and entertainment and under-represents science and technology. The authors down-sample the first and up-sample the second, so the mixture favours high-value content.
  3. Pre-train on 18 trillion tokens. The total is about 2.6 times (18 divided by 7) the 7 trillion used for Qwen2, and it is trained in stages with different mixtures.
  4. Set hyperparameters with scaling laws. Small experiments fit the best learning rate and batch size as functions of model size and data size, and these fits are used for the full models, dense and mixture-of-experts alike.
  5. Extend the context. Pre-training first uses 4,096-token sequences. The final stage moves to 32,768 tokens and raises the RoPE base from 10,000 to 1,000,000. Inference-time methods then reach 131,072 tokens for most models, and Qwen2.5-Turbo reaches 1 million.
  6. Supervised fine-tuning. More than one million instruction examples cover long outputs, mathematics, coding, instruction following, structured data, logic and multilingual cases. The model trains for two epochs with a learning rate decreasing from 7×10−67\times 10^{-6} to 7×10−77\times 10^{-7}.
  7. Offline reinforcement learning with DPO. About 150,000 preference pairs are built from checked responses. Responses that pass quality checks are positive, and those that fail are negative, for objective tasks such as maths and code.
  8. Online reinforcement learning with GRPO. A reward model scores several responses to the same query, and the policy is updated relative to the average score of the group. Queries whose scores vary most are prioritised. Eight responses are sampled per query.
  9. Evaluate. Base models and instruction models are scored on a suite of benchmarks, after removing training samples that overlap test data by n-gram matching.
flowchart LR
  D[curated data 18T tokens] --> P[pre-training with scaling-law hyperparameters]
  P --> C[context extension to 32K then 128K+]
  C --> S[SFT: over 1M examples]
  S --> O[offline RL: DPO on about 150K pairs]
  O --> N[online RL: GRPO with reward model]
  N --> E[evaluation]

The math

Grouped-query attention ratio. The 72B model has 64 query heads and 8 key-value heads, so each key-value head serves a group of 64 / 8 = 8 query heads. The 7B model has 28 query heads and 4 key-value heads, so each key-value head serves 7 query heads.

Rotary embedding base. RoPE rotates pairs of coordinates of the query and key by an angle that depends on the position pp and a frequency. For a pair ii of a head of size dd, the frequency is θi=b−2i/d\theta_i = b^{-2i/d}, where bb is the base. A larger base makes the slowest frequencies change more slowly, so the model can tell positions apart over longer distances. Raising bb from 10410^4 to 10610^6 is the change used for long context.

Offline stage, DPO. For a prompt xx, a preferred response ywy_w and a rejected response yly_l, the DPO loss with reference model πref\pi_{\text{ref}} and scale β\beta is L=−log⁡σ(β[log⁡π(yw∣x)πref(yw∣x)−log⁡π(yl∣x)πref(yl∣x)])\mathcal{L} = -\log \sigma\big(\beta[\log \frac{\pi(y_w \mid x)}{\pi_{\text{ref}}(y_w \mid x)} - \log \frac{\pi(y_l \mid x)}{\pi_{\text{ref}}(y_l \mid x)}]\big), where σ\sigma is the logistic function. The loss grows when the model prefers the rejected answer more than the reference does.

Online stage, GRPO advantage. For a group of GG responses to one query with rewards r1,…,rGr_1, \dots, r_G, each response gets advantage Ai=(ri−mean(r))/std(r)A_i = (r_i - \text{mean}(r)) / \text{std}(r). The advantage is relative to the group, so no separate value model is needed.

Working the numbers

Use the GQA ratio for a cache estimate. For one token, one layer, the key and value cache holds 2⋅nkv⋅dhead2 \cdot n_{kv} \cdot d_{head} numbers. Take an illustrative head size of 128 and compare 64 key-value heads with 8.

  1. With 64 key-value heads, one token in one layer stores 2⋅64⋅128=16,3842 \cdot 64 \cdot 128 = 16{,}384 numbers.
  2. With 8 key-value heads, it stores 2⋅8⋅128=2,0482 \cdot 8 \cdot 128 = 2{,}048 numbers.
  3. The cache is 8 times smaller, because 64 / 8 = 8 query heads share each key-value head.

The GRPO advantage for a group with rewards 1, 0, 0, 1 has mean 0.5 and standard deviation 0.5, so the advantages are +1,−1,−1,+1+1, -1, -1, +1. Responses that beat their group are reinforced and the rest are discouraged.

Try it: a query gets eight responses with rewards 1, 1, 1, 1, 0, 0, 0, 0. What are the advantages of a response with reward 1? Answer: the mean is 0.5 and the standard deviation is 0.5, so each reward-1 response has advantage (1−0.5)/0.5=1(1 - 0.5) / 0.5 = 1.

Results

  • Base models. The 72B base model scores 86.1 on MMLU against 85.2 for Llama-3-405B, and 62.1 on MATH against 50.9 for its predecessor Qwen2-72B. Its GSM8K score is 91.5 against 89.0 for Qwen2-72B.
  • Limits in the same table. Llama-3-405B is ahead on HumanEval (61.0 against 59.1) and on WinoGrande (86.7 against 83.9). The base 72B model is not best on every task.
  • Instruction models. The 72B instruction model is reported to surpass Llama-3.1-405B-Instruct on several benchmarks, including MMLU-redux, MATH and MBPP, although the 405B model has 405 billion parameters against 72 billion. The hosted Turbo model is compared with GPT-4o-mini and Plus with GPT-4o, and the paper reports both as competitive.
  • Long context. Qwen2.5-Turbo handles up to 1 million tokens after the progressive extension and the inference-time methods YARN and DCA. The paper reports that these methods keep short-sequence quality.
  • What the numbers mean. The results are the authors' own evaluations, mostly automatic, with n-gram decontamination against test sets. They show the recipe works across a wide benchmark set, not that the models are best on each task. Independent evaluation is needed for any single claim.

Reading guide

Check yourself

QuestionWhy does the 72B model store less key-value cache per token than a model with one key-value head per query head?Show answer
It has 8 key-value heads shared by 64 query heads, so each token stores keys and values for 8 heads instead of 64. The key-value cache is therefore 8 times smaller for the same head size, which is the point of grouped-query attention.
QuestionA query gets four responses with rewards 1, 0, 0, 0. What is the GRPO advantage of the response with reward 1?Show answer
The mean is 0.25. The population standard deviation is 0.25⋅0.75=0.1875≈0.433\sqrt{0.25 \cdot 0.75} = \sqrt{0.1875} \approx 0.433. The advantage is (1−0.25)/0.433≈1.73(1 - 0.25) / 0.433 \approx 1.73.
QuestionWhy does the paper raise the RoPE base from 10,000 to 1,000,000 when extending to 32,768 tokens?Show answer
A larger base makes the slow rotary frequencies change more slowly, so positions far apart stay distinguishable. Keeping the base at 10,000 would make the longer positions look alike to the model, which is why the base is raised along with the sequence length.
QuestionWhy does the paper use offline DPO for maths and code before online GRPO with a reward model?Show answer
For objective tasks, answers can be checked by execution or answer matching, so preference pairs can be built ahead of time without a reward model. The reward model is used later for subjective qualities such as helpfulness and style, where automatic checks are weaker.

Sources

Read the full paper

Qwen Team, An Yang, Baosong Yang et al., 2024. arXiv:2412.15115