Skip to content

How does DoRA (Weight-Decomposed Low-Rank Adaptation) improve directional weight updates over LoRA?

Intermediate · 2 min read · Fine-Tuning & Adaptation

Open in study mode to save this question and track progress

Short answer: DoRA (Weight-Decomposed Low-Rank Adaptation) decomposes model weight updates into magnitude (norm) and direction components, applying LoRA updates exclusively to the directional component; this decouples magnitude scaling from direction tuning, matching full-parameter fine-tuning capability closer than standard LoRA.

Detail

Standard LoRA updates weight matrix WW by adding ΔW=BA\Delta W = B A.

Analysis reveals that full parameter fine-tuning changes weight magnitude (m=∥W∥m = \|W\|) and directional orientation (V=W/∥W∥V = W / \|W\|) with distinct subtle correlation patterns, whereas standard LoRA forces magnitude and direction to scale proportionally.

Weight Vector Matrix W = m * (V / ||V||)
  ├── Magnitude m (Scalar norm) ──► Trained independently
  └── Direction V (Matrix)      ──► Adapted via LoRA low-rank decomposition (B * A)

Mathematical Formulation

DoRA formulates weight matrix WW as:

W=m⋅W0+BA∥W0+BA∥FW = m \cdot \frac{W_0 + B A}{\|W_0 + B A\|_F}

Where m∈R1×km \in \mathbb{R}^{1 \times k} is a learnable magnitude vector and BAB A adapts the directional matrix VV.

Example

PyTorch conceptual DoRA weight decomposition:

python
import torch
import torch.nn as nn

class DoRALayer(nn.Module):
    def __init__(self, W_base: torch.Tensor, r: int = 8):
        super().__init__()
        self.out_dim, self.in_dim = W_base.shape
        self.W0 = W_base # Frozen base weights

        # Trainable magnitude scalar norm
        self.m = nn.Parameter(torch.norm(W_base, dim=0, keepdim=True))

        # LoRA directional adapters
        self.lora_A = nn.Parameter(torch.randn(r, self.in_dim) * 0.01)
        self.lora_B = nn.Parameter(torch.zeros(self.out_dim, r))

    def forward(self, x):
        # Calculate adapted directional matrix V
        V = self.W0 + self.lora_B @ self.lora_A
        # Normalize direction and scale by magnitude m
        V_norm = V / torch.norm(V, dim=0, keepdim=True)
        W_dora = self.m * V_norm
        return x @ W_dora.T

Interview tips

  • Highlight that DoRA achieves superior fine-tuning accuracy over standard LoRA on complex tasks (coding, math) at identical rank rr sizes.
  • Note that DoRA can also be merged into base model weights for zero-latency inference deployment.

Related Concepts


⬅ Back to Fine-Tuning and Adaptation · All topics