Papers · Reinforcement learning and alignment · 2024

DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models

Zhihong Shao, Peiyi Wang, Qihao Zhu and others

The notation of the GRPO paper, explained: its 21 displayed equations, then every symbol it uses, grouped by category and shown the way the paper writes it.

Read the paper on arXiv

Reading this paper

DeepSeekMath introduced GRPO, a variant of PPO that needs no value network: it samples a group of GG answers to each question and scores each against the group.

oio_i is the ii-th sampled output and oi,to_{i,t} its tt-th token. The advantage A^i,t\hat{A}_{i,t} is the answer's reward minus the group's mean, divided by the group's standard deviation. πθold\pi_{\theta_{\text{old}}} is the policy that sampled the group, πref\pi_{\text{ref}} the reference model for the KL penalty weighted by β\beta, and ε\varepsilon the clipping range, as in PPO.

Read from arXiv's HTML version: 21 displayed equations and 62 pieces of inline math. 47 symbols and constructs from the catalog, read as reinforcement learning.

The paper's displayed equations

Open any of them in the decoder for a symbol-by-symbol reading.

  1. (1)
    JPPO(θ)=E[q∼P(Q),o∼πθold(O∣q)]1∣o∣∑t=1∣o∣min⁡[πθ(ot∣q,o<t)πθold(ot∣q,o<t)At,clip(πθ(ot∣q,o<t)πθold(ot∣q,o<t),1−ε,1+ε)At],\footnotesize\mathcal{J}_{PPO}(\theta)=\mathbb{E}{[q\sim P(Q),o\sim\pi_{\theta_{old}}(O|q)]}\frac{1}{|o|}\sum_{t=1}^{|o|}\min\left[\frac{\pi_{\theta}(o_{t}|q,o_{<t})}{\pi_{\theta_{old}}(o_{t}|q,o_{<t})}A_{t},\text{clip}\left(\frac{\pi_{\theta}(o_{t}|q,o_{<t})}{\pi_{\theta_{old}}(o_{t}|q,o_{<t})},1-\varepsilon,1+\varepsilon\right)A_{t}\right],
    Decode →
  2. (2)
    rt=rφ(q,o≤t)−βlog⁡πθ(ot∣q,o<t)πref(ot∣q,o<t),r_{t}=r_{\varphi}(q,o_{\leq t})-\beta\log\frac{\pi_{\theta}(o_{t}|q,o_{<t})}{\pi_{ref}(o_{t}|q,o_{<t})},
    Decode →
  3. (3)
    JGRPO(θ)=E[q∼P(Q),{oi}i=1G∼πθold(O∣q)]1G∑i=1G1∣oi∣∑t=1∣oi∣{min⁡[πθ(oi,t∣q,oi,<t)πθold(oi,t∣q,oi,<t)A^i,t,clip(πθ(oi,t∣q,oi,<t)πθold(oi,t∣q,oi,<t),1−ε,1+ε)A^i,t]−βDKL[πθ∣∣πref]},\footnotesize\begin{split}\mathcal{J}_{GRPO}(\theta)&=\mathbb{E}{[q\sim P(Q),\{o_{i}\}_{i=1}^{G}\sim\pi_{\theta_{old}}(O|q)]}\\ &\frac{1}{G}\sum_{i=1}^{G}\frac{1}{|o_{i}|}\sum_{t=1}^{|o_{i}|}\left\{\min\left[\frac{\pi_{\theta}(o_{i,t}|q,o_{i,<t})}{\pi_{\theta_{old}}(o_{i,t}|q,o_{i,<t})}\hat{A}_{i,t},\text{clip}\left(\frac{\pi_{\theta}(o_{i,t}|q,o_{i,<t})}{\pi_{\theta_{old}}(o_{i,t}|q,o_{i,<t})},1-\varepsilon,1+\varepsilon\right)\hat{A}_{i,t}\right]-\beta\mathbb{D}_{KL}\left[\pi_{\theta}||\pi_{ref}\right]\right\},\end{split}
    Decode →
  4. (4)
    DKL[πθ∣∣πref]=πref(oi,t∣q,oi,<t)πθ(oi,t∣q,oi,<t)−log⁡πref(oi,t∣q,oi,<t)πθ(oi,t∣q,oi,<t)−1,\small\mathbb{D}_{KL}\left[\pi_{\theta}||\pi_{ref}\right]=\frac{\pi_{ref}(o_{i,t}|q,o_{i,<t})}{\pi_{\theta}(o_{i,t}|q,o_{i,<t})}-\log\frac{\pi_{ref}(o_{i,t}|q,o_{i,<t})}{\pi_{\theta}(o_{i,t}|q,o_{i,<t})}-1,
    Decode →
  5. (5)
    ∇θJA(θ)=E[(q,o)∼D⏟Data Source](1∣o∣∑t=1∣o∣GCA(q,o,t,πrf)⏟Gradient Coefficient∇θlog⁡πθ(ot∣q,o<t)).\nabla_{\theta}\mathcal{J}_{{\mathcal{A}}}(\theta)=\mathbb{E}[\underbrace{(q,o)\sim{\mathcal{D}}}_{Data\ Source}]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}\underbrace{GC_{{\mathcal{A}}}(q,o,t,{\pi_{{rf}}})}_{Gradient\ Coefficient}\nabla_{\theta}\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  6. (6)
    JSFT(θ)=E[q,o∼Psft(Q,O)](1∣o∣∑t=1∣o∣log⁡πθ(ot∣q,o<t)).\mathcal{J}_{SFT}(\theta)=\mathbb{E}[q,o\sim P_{sft}(Q,O)]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  7. (7)
    ∇θJSFT=E[q,o∼Psft(Q,O)](1∣o∣∑t=1∣o∣∇θlog⁡πθ(ot∣q,o<t)).\nabla_{\theta}\mathcal{J}_{SFT}=\mathbb{E}[q,o\sim P_{sft}(Q,O)]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}\nabla_{\theta}\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  8. (8)
    JRFT(θ)=E[q∼Psft(Q),o∼πsft(O∣q)](1∣o∣∑t=1∣o∣I(o)log⁡πθ(ot∣q,o<t)).\mathcal{J}_{RFT}(\theta)=\mathbb{E}[q\sim P_{sft}(Q),o\sim\pi_{sft}(O|q)]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}\mathbb{I}(o)\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  9. (9)
    ∇θJRFT(θ)=E[q∼Psft(Q),o∼πsft(O∣q)](1∣o∣∑t=1∣o∣I(o)∇θlog⁡πθ(ot∣q,o<t)).\nabla_{\theta}\mathcal{J}_{RFT}(\theta)=\mathbb{E}[{q\sim P_{sft}(Q),o\sim\pi_{sft}(O|q)}]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}{\mathbb{I}(o)}\nabla_{\theta}\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  10. (10)
    GCRFT(q,o,t)=I(o)={1the answer of o is correct0the answer of o is incorrectGC_{RFT}(q,o,t)=\mathbb{I}(o)=\left\{\begin{aligned} 1&&{\rm the\ answer\ of\ o\ is\ correct}\\ 0&&{\rm the\ answer\ of\ o\ is\ incorrect}\\ \end{aligned}\right.
    Decode →
  11. (11)
    ∇θJOnRFT(θ)=E[q∼Psft(Q),o∼πθ(O∣q)](1∣o∣∑t=1∣o∣I(o)∇θlog⁡πθ(ot∣q,o<t)).\nabla_{\theta}\mathcal{J}_{OnRFT}(\theta)=\mathbb{E}[{q\sim P_{sft}(Q),o\sim\pi_{\theta}(O|q)}]\left(\frac{1}{|o|}\sum_{t=1}^{|o|}{\mathbb{I}(o)}\nabla_{\theta}\log\pi_{\theta}(o_{t}|q,o_{<t})\right).
    Decode →
  12. (12)
    JDPO(θ)=E[q∼Psft(Q),o+,o−∼πsft(O∣q)]log⁡σ(β1∣o+∣∑t=1∣o+∣log⁡πθ(ot+∣q,o<t+)πref(ot+∣q,o<t+)−β1∣o−∣∑t=1∣o−∣log⁡πθ(o<t−∣q,o<t−)πref(o<t−∣q,o<t−))\footnotesize\begin{split}\mathcal{J}_{DPO}(\theta)=\mathbb{E}{[q\sim P_{sft}(Q),o^{+},o^{-}\sim\pi_{sft}(O|q)]}\log\sigma\left(\beta\frac{1}{|o^{+}|}\sum_{t=1}^{|o^{+}|}\log\frac{\pi_{\theta}(o^{+}_{t}|q,o^{+}_{<t})}{\pi_{\text{ref}}(o^{+}_{t}|q,o^{+}_{<t})}-\beta\frac{1}{|o^{-}|}\sum_{t=1}^{|o^{-}|}\log\frac{\pi_{\theta}(o^{-}_{<t}|q,o^{-}_{<t})}{\pi_{\text{ref}}(o^{-}_{<t}|q,o^{-}_{<t})}\right)\end{split}
    Decode →

Famous equations in this paper

Symbols, by category

Most used first. The examples are written as the paper writes them.

Notation conventions

  1. JPPO\mathcal{J}_{PPO}, πθold\pi_{\theta_{old}}, θold\theta_{old}

    Subscript (index or label) 351 uses

    A subscript picks an element (xᵢ), a time step (h_t), a named copy (W_q), or the parameters (p_θ).

  2. oo, OO, CC

    Italic letters (variables) 280 uses

    A plain italic letter is a variable; conventions say what kind (x input, y target, W weights…).

  3. {oi}i=1G\{o_{i}\}_{i=1}^{G}, o−o^{-}, o<t−o^{-}_{<t}

    Superscript (power or label) 30 uses

    Usually a power (x² = x·x), but a capital or a word up there is often just a label (W^Q).

  4. A^\hat{A}

    Hat (estimate) 12 uses

    A hat marks an estimate or prediction: ŷ is the model’s guess for y.

  5. ⋯\cdots

    Dots (ellipsis) 7 uses

    “And so on”: continue the pattern.

  6. D\mathcal{D}

    Dataset (𝒟) 6 uses

    The dataset: usually N input-label pairs.

  7. meanmean, stdstd

    Multi-letter names 4 uses

    A run of italic letters like pos or model is usually one name, not a product of single letters.

  8. r~\widetilde{r}

    Tilde accent 3 uses

    A modified version of the variable: noisy, corrupted, proposed or intermediate.

  9. Underbrace and overbrace 2 uses

    A horizontal brace under or over part of a formula labels that part. It adds no math.

Greek letters

  1. θ\theta

    Theta 109 uses

    The model’s parameters: all of its weights and biases, as one collection.

  2. π\pi

    Pi 97 uses

    A policy π(a | s) in reinforcement learning, or the constant 3.14159…

  3. β\beta

    Beta 14 uses

    Usually a decay rate (Adam’s β₁, β₂), a shift parameter in normalization, or a weight on a loss term.

  4. ε\varepsilon

    Epsilon 9 uses

    A tiny constant for numerical safety (10⁻⁸ in Adam), or noise ε ~ 𝒩(0, I).

  5. φ\varphi

    Phi 5 uses

    The parameters of a second model (often the encoder q_φ), or a feature map φ(x).

  6. σ\sigma

    Sigma (lowercase) 2 uses

    Either the sigmoid function σ(z) = 1/(1+e⁻ᶻ) or a standard deviation. The context decides.

  7. ψ\psi

    Psi 2 uses

    The parameters of a third network (after θ and φ), a feature map, or the digamma function ψ(x).

  8. μ\mu

    Mu 2 uses

    A mean: the average of a distribution, a batch, or a layer’s features.

Vectors and matrices

  1. ∣o∣|o|, ∣oi∣|o_{i}|, ∣o+∣|o^{+}|

    Absolute value (bars) 34 uses

    Absolute value of a number; for a set, its size; for a matrix, sometimes its determinant.

  2. o+o^{+}, ot+o^{+}_{t}, o<t+o^{+}_{<t}

    Dagger / pseudo-inverse 19 uses

    The Moore–Penrose pseudo-inverse A⁺ (written A† in many ML papers); in physics, the conjugate transpose.

  3. r\mathbf{r}

    Bold lowercase (vector) 3 uses

    A bold lowercase letter is a vector: a list of numbers.

  4. R\mathbf{R}

    Bold uppercase (matrix) 3 uses

    A bold capital letter is a matrix (or a higher-order tensor).

  5. ⋅\cdot

    Centre dot 1 use

    A dot product between vectors, plain multiplication between numbers, or an empty slot f(·).

Calculus and gradients

  1. ∇θ\nabla_{\theta}

    Nabla (gradient) 15 uses

    The gradient: the vector of partial derivatives. ∇_θ L is how the loss changes with each parameter.

Probability and statistics

  1. PP, qq

    Probability p(x) 140 uses

    A probability or probability density; p is usually the true or model distribution, q an approximation.

  2. ∣|, ∣\mid

    Given (conditional bar) 66 uses

    “Given”: p(y | x) is the probability of y given that x is known.

  3. ∼\sim

    Distributed as (tilde) 39 uses

    “Is drawn from” or “is distributed as”: x ~ p means x is a sample from the distribution p.

  4. log⁡\log

    Logarithm 18 uses

    A logarithm, almost always the natural log (base e) in ML papers.

  5. E\mathbb{E}

    Expectation 15 uses

    The expected value: the average of what is inside, weighted by the probabilities in the subscript.

  6. I\mathbb{I}

    Indicator function 4 uses

    1 when the condition inside is true, 0 when it is false.

  7. ∣∣||

    KL divergence 2 uses

    How different distribution q is from p. Zero when they match; not symmetric.

Functions and operators

  1. 1∣o∣\frac{1}{|o|}, 1G\frac{1}{G}, 1∣oi∣\frac{1}{|o_{i}|}

    Fraction 41 uses

    Division: the top divided by the bottom.

  2. ∑t=1∣o∣\sum_{t=1}^{|o|}, ∑i=1G\sum_{i=1}^{G}, ∑t=1∣oi∣\sum_{t=1}^{|o_{i}|}

    Summation 21 uses

    Add up the expression for every value of the index, from the bottom limit to the top.

  3. →\rightarrow

    Arrow (maps to) 5 uses

    Maps to (f: X → Y), tends to (x → 0), or implies (⇒).

  4. min⁡\min

    Max and min 4 uses

    The largest (or smallest) value, over the arguments or over the range in the subscript.

  5. clip\text{clip}, clipclip

    Clip 4 uses

    Limit a value to a range: clip(x, a, b) is a if x < a, b if x > b, else x.

  6. ←\leftarrow

    Assignment arrow 3 uses

    Assignment in an algorithm: replace the variable on the left with the value on the right.

Reinforcement learning

  1. GG

    Return G 36 uses

    Gₜ is the return: the total discounted reward from step t onward. The agent maximizes its expectation.

  2. aa, ss

    State s and action a 36 uses

    sₜ is the state at step t, aₜ the action taken there; s′ is the next state.

  3. rr

    Reward r 27 uses

    rₜ is the reward received at step t; R(s, a) is the reward function that hands it out.

  4. AA

    Advantage A 21 uses

    A(s, a) = Q − V: how much better action a is than the policy’s average action in state s.

  5. J\mathcal{J}

    Objective J 20 uses

    J(θ) is the objective: the quantity to maximize, such as the expected return of a policy.

  6. QQ

    Action-value function Q 20 uses

    Q(s, a) is the expected total reward from taking action a in state s, then following the policy.

  7. A\mathcal{A}

    State and action spaces 3 uses

    𝒮 is the set of all states and 𝒜 the set of all actions in a Markov decision process.

  8. VV

    Value function V 2 uses

    V(s) is how much total discounted reward to expect from state s onward.

Sets, shapes and definitions

  1. <<, ≤\leq, ≥\geq

    Inequalities 54 uses

    Less than / greater than (or equal). ≪ means “much smaller than”.

  2. {oi}\{o_{i}\}, {r≥t}\{r_{\geq t}\}, {o1,o2,⋯ ,oG}\{o_{1},o_{2},\cdots,o_{G}\}

    Set braces 17 uses

    A set: a collection of items. {x | condition} is every x that satisfies the condition.

  3. ∈\in

    Element of 1 use

    “Is in” or “belongs to”: x ∈ S says x is a member of the set S.

5 things the catalog has no entry for yet
  • \footnotesize \footnotesize 11
  • \rm \rm 7
  • D\mathbb{D} D 2
  • \small \small 1
  • weight_decay\mathrm{weight\_decay} weight\_decay 1

Formulas from arXiv's HTML version of the paper, © their authors; the explanations are this site's. Title and authors as arXiv lists them.

More reinforcement learning and alignment papers