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 progressShort 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 by adding .
Analysis reveals that full parameter fine-tuning changes weight magnitude () and directional orientation () 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 as:
Where is a learnable magnitude vector and adapts the directional matrix .
Example
PyTorch conceptual DoRA weight decomposition:
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.TInterview tips
- Highlight that DoRA achieves superior fine-tuning accuracy over standard LoRA on complex tasks (coding, math) at identical rank sizes.
- Note that DoRA can also be merged into base model weights for zero-latency inference deployment.
Related Concepts
- [[What is weight merging in LoRA and why does it eliminate inference latency penalties?]] (
#145): What is weight merging in LoRA and why does it eliminate inference latency penalties? - [[How does ORPO perform SFT and alignment in a single step without reference models?]] (
#149): How does ORPO perform SFT and alignment in a single step without reference models? - [[How does DeepSpeed ZeRO stage 1, 2, and 3 partition optimizer states, gradients, and parameters?]] (
#150): How does DeepSpeed ZeRO stage 1, 2, and 3 partition optimizer states, gradients, and parameters?