Papers · Training · 2021

LoRA: Low-Rank Adaptation of Large Language Models

Edward Hu, Yelong Shen, Phillip Wallis and others

The notation of the LoRA paper, explained: its 6 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

LoRA: fine-tune a large model by learning a small low-rank change to each weight matrix, ΔW=BA\Delta W = BA, and leaving the original weights frozen.

The shapes carry the idea: W0∈Rd×kW_0 \in \mathbb{R}^{d \times k}, B∈Rd×rB \in \mathbb{R}^{d \times r} and A∈Rr×kA \in \mathbb{R}^{r \times k} with r≪min⁡(d,k)r \ll \min(d, k), so BABA has the shape of W0W_0 but far fewer parameters. Φ\Phi stands for all of the model's parameters and Θ\Theta for the small set LoRA trains; ∣y∣|y| is the length of a target sequence, not an absolute value.

Read from arXiv's HTML version: 6 displayed equations and 184 pieces of inline math. 35 symbols and constructs from the catalog.

The paper's displayed equations

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

  1. (1)
    max⁡Φ∑(x,y)∈Z∑t=1∣y∣log(PΦ(yt∣x,y<t))\max_{\Phi}\sum_{(x,y)\in\mathcal{Z}}\sum_{t=1}^{|y|}\text{log}\left(P_{\Phi}(y_{t}|x,y_{<t})\right)
    Decode →
  2. (2)
    max⁡Θ∑(x,y)∈Z∑t=1∣y∣log⁡(pΦ0+ΔΦ(Θ)(yt∣x,y<t))\max_{\Theta}\sum_{(x,y)\in\mathcal{Z}}\sum_{t=1}^{|y|}\log\left({p_{\Phi_{0}+\Delta\Phi(\Theta)}(y_{t}|x,y_{<t}})\right)
    Decode →
  3. (3)
    h=W0x+ΔWx=W0x+BAxh=W_{0}x+\Delta Wx=W_{0}x+BAx
    Decode →
  4. (4)
    ϕ(Ar=8,Ar=64,i,j)=∣∣UAr=8i⊤UAr=64j∣∣F2min⁡(i,j)∈[0,1]\phi(A_{r=8},A_{r=64},i,j)=\frac{||U_{A_{r=8}}^{i\top}U_{A_{r=64}}^{j}||_{F}^{2}}{\min(i,j)}\in[0,1]
    Decode →
  5. d(UAi,UBj)=p−∑i=1pσi2∈[0,p]d(U_{A}^{i},U_{B}^{j})=\sqrt{p-\sum_{i=1}^{p}\sigma_{i}^{2}}\in[0,\sqrt{p}]
    Decode →
  6. ϕ(A,B,i,j)=ψ(UAi,UBj)=∑i=1pσi2p=1p(1−d(UAi,UBj)2)\phi(A,B,i,j)=\psi(U_{A}^{i},U_{B}^{j})=\frac{\sum_{i=1}^{p}\sigma_{i}^{2}}{p}=\frac{1}{p}\left(1-d(U_{A}^{i},U_{B}^{j})^{2}\right)
    Decode →

Famous equations in this paper

Symbols, by category

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

Notation conventions

  1. yy, xx, hh

    Italic letters (variables) 547 uses

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

  2. PΦP_{\Phi}, yty_{t}, y<ty_{<t}

    Subscript (index or label) 322 uses

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

  3. UAr=8i⊤U_{A_{r=8}}^{i\top}, UAr=64jU_{A_{r=64}}^{j}, ∣∣F2||_{F}^{2}

    Superscript (power or label) 66 uses

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

  4. L^\hat{L}

    Hat (estimate) 6 uses

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

  5. Z\mathcal{Z}

    Calligraphic letters 3 uses

    A script capital usually names a set, a space, a distribution or a loss.

  6. ⋯\cdots

    Dots (ellipsis) 1 use

    “And so on”: continue the pattern.

Greek letters

  1. Δ\Delta

    Delta (capital) 70 uses

    A change or update: ΔW is the change to the weights W.

  2. Φ\Phi, ϕ\phi

    Phi 28 uses

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

  3. Θ\Theta

    Theta 13 uses

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

  4. α\alpha

    Alpha 9 uses

    Often a learning rate or step size; also attention weights αᵢⱼ or a mixing weight.

  5. σ\sigma

    Sigma (lowercase) 5 uses

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

  6. ψ\psi

    Psi 2 uses

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

Vectors and matrices

  1. ×\times

    Times (cross) 21 uses

    Usually the “by” in a shape (n × d); also plain multiplication or a cross product.

  2. ⊤\top, U⊤U^{\top}, V⊤V^{\top}

    Transpose 17 uses

    Swap rows and columns. xᵀy is a dot product; xyᵀ is an outer product.

  3. ∣y∣|y|, ∣ΔΦ∣|\Delta\Phi|, ∣Φ0∣|\Phi_{0}|

    Absolute value (bars) 15 uses

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

  4. VV, KK

    Q, K, V (query, key, value) 14 uses

    In attention: queries Q, keys K and values V, each a matrix with one row per token.

  5. †\dagger

    Dagger / pseudo-inverse 13 uses

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

  6. ∥U⊤WV⊤∥F\|U^{\top}WV^{\top}\|_{F}, ∥W∥F\|W\|_{F}, ∥UAi⊤UB∥F2\|U_{A}^{i\top}U_{B}\|_{F}^{2}

    Frobenius norm 6 uses

    The size of a matrix: the square root of the sum of the squares of all its entries.

  7. (⋅)(\cdot)

    Centre dot 1 use

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

Calculus and gradients

  1. B′B^{\prime}, A′A^{\prime}

    Prime 2 uses

    Either a derivative, f′(x), or simply "another one": x′ is a second sample, s′ the next state.

Probability and statistics

  1. PP, pp, qq

    Probability p(x) 106 uses

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

  2. H\text{H}, H\textbf{H}

    Entropy and cross-entropy 14 uses

    H(p) is the entropy of a distribution: its average surprise. H(p, q) is the cross-entropy.

  3. ∣∣||

    KL divergence 10 uses

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

  4. ∣|

    Given (conditional bar) 4 uses

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

  5. log\text{log}, log⁡\log

    Logarithm 2 uses

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

Functions and operators

  1. ±\pm

    Plus or minus 140 uses

    Both signs at once: a ± b means a + b and a − b. In results tables, a mean and its spread.

  2. max⁡Φ\max_{\Phi}, max⁡Θ\max_{\Theta}, min⁡\min

    Max and min 6 uses

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

  3. ∑(x,y)∈Z\sum_{(x,y)\in\mathcal{Z}}, ∑t=1∣y∣\sum_{t=1}^{|y|}, ∑i=1p\sum_{i=1}^{p}

    Summation 6 uses

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

  4. ∑i=1pσi2p\frac{\sum_{i=1}^{p}\sigma_{i}^{2}}{p}, 1p\frac{1}{p}, αr\frac{\alpha}{r}

    Fraction 6 uses

    Division: the top divided by the bottom.

  5. p−∑i=1pσi2\sqrt{p-\sum_{i=1}^{p}\sigma_{i}^{2}}, p\sqrt{p}

    Square root 2 uses

    The square root. In attention, dividing by √d_k keeps dot products at a sensible scale.

Sets, shapes and definitions

  1. <<, ≪\ll, ≤\leq

    Inequalities 11 uses

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

  2. ∈\in

    Element of 10 uses

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

  3. {(xi,yi)}\{(x_{i},y_{i})\}, {Wq,Wv}\{W_{q},W_{v}\}, {Wq,Wk,Wv,Wc}\{W_{q},W_{k},W_{v},W_{c}\}

    Set braces 9 uses

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

  4. Rd×k\mathbb{R}^{d\times k}, Rd×r\mathbb{R}^{d\times r}, Rr×k\mathbb{R}^{r\times k}

    Tensor shapes 6 uses

    ℝ with a superscript of sizes joined by × declares an array’s shape: ℝ^{B×T×d} is a 3-axis tensor.

  5. ≈\approx

    Approximately equal 4 uses

    Approximately equal: often a Monte Carlo estimate or a Taylor approximation.

2 things the catalog has no entry for yet
  • ↑\uparrow \uparrow 4
  • ↓\downarrow \downarrow 2

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 training papers