M5-134M5: NLP & Large Language ModelsPEFT (LoRA / QLoRA / Prefix Tuning)Hard
⚡Flashcard Drill➔Mastery:

Systematic Decision Framework for Parameter-Efficient Fine-Tuning (PEFT) Selection

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M5-135 →
📐 Mathematical Definition
choose: f(memory,task distance,data,deploy)\text{choose}:\ f(\text{memory},\text{task distance},\text{data},\text{deploy})
⚡ One-Sentence Core Answer
A production PEFT decision framework navigates a four-dimensional trade-off matrix across hardware VRAM constraints, domain task distance, training dataset volume, and multi-tenant serving latency budgets.

📌 Key Takeaways

  • •
    Four-dimensional decision matrix: (1) Hardware VRAM budget, (2) Task semantic distance, (3) Training sample volume, and (4) Serving latency and tenancy architecture
  • •
    Default production hierarchy: LoRA (BF16) serves as the primary default; switch to QLoRA under single-GPU memory limits, and elevate to Full Fine-Tuning for deep domain shifts
  • •
    Golden engineering rule: scaling base model size with LoRA uniformly outperforms executing full parameter fine-tuning on a weaker base model

📐 Mathematical Derivations

Mathematical Mechanism: 1. The 4-Dimensional Decision Vector: Formalize PEFT selection as an optimization over decision tuple D=⟨V,Δ,N,S⟩\mathcal{D} = \langle V, \Delta, N, S \rangle: M∗=Select(VVRAM,  Δtask,  Ndata,  Sserving)\mathcal{M}^* = \text{Select}\big(V_{\text{VRAM}}, \; \Delta_{\text{task}}, \; N_{\text{data}}, \; S_{\text{serving}}\big) 2. Decision Boundaries: (a) Memory Constraint ($V$): Let required VRAM for 16-bit LoRA be VLoRA≈2×Mparams+VactsV_{\text{LoRA}} \approx 2 \times M_{\text{params}} + V_{\text{acts}}, and QLoRA be VQLoRA≈0.5×Mparams+VactsV_{\text{QLoRA}} \approx 0.5 \times M_{\text{params}} + V_{\text{acts}}. If VGPU<VLoRAV_{\text{GPU}} < V_{\text{LoRA}}, select QLoRA. (b) Task Semantic Distance ($\Delta$): Defined via Fisher information overlap or token perplexity gap Δ=E[−log⁡Pbase(xdomain)]−E[−log⁡Pbase(xgeneral)]\Delta = \mathbb{E}[-\log P_{\text{base}}(x_{\text{domain}})] - \mathbb{E}[-\log P_{\text{base}}(x_{\text{general}})]: Δ<τlow  ⟹  LoRA (r=8–16)[Style alignment, QA, tool use]\Delta < \tau_{\text{low}} \implies \text{LoRA } (r=8\text{--}16) \quad \text{[Style alignment, QA, tool use]} τlow≤Δ<τhigh  ⟹  LoRA (r=64–256) or DoRA[Complex domain reasoning]\tau_{\text{low}} \le \Delta < \tau_{\text{high}} \implies \text{LoRA } (r=64\text{--}256) \text{ or DoRA} \quad \text{[Complex domain reasoning]} Δ≥τhigh  ⟹  Full Fine-Tuning / Continual Pre-train[New language, molecular biology]\Delta \ge \tau_{\text{high}} \implies \text{Full Fine-Tuning / Continual Pre-train} \quad \text{[New language, molecular biology]} (c) Data Volume ($N$): If N<10KN < 10\text{K}, LoRA provides structural regularization; if N>1MN > 1\text{M} with high Δ\Delta, full fine-tuning reaches a higher performance ceiling. (d) Serving Tenancy ($S$): For single-tenant dedicated APIs →\to Merge LoRA; For multi-tenant heterogeneous APIs →\to Multi-LoRA dynamic adapter serving.

🏭 Production Trade-offs

Deep Dive & Engineering Trade-offs: ① The 'Bigger Model + LoRA' Maxim: When faced with a fixed compute/hardware budget, practitioners frequently debate between: (Option A) Full fine-tuning on an 8B model, versus (Option B) LoRA on a 70B model. In 95% of real-world scenarios, Option B achieves dramatically superior domain reasoning, factual accuracy, and instruction adherence. Base model capability represents the true performance ceiling. ② Empirical Task Distance Probing: Since semantic distance is difficult to measure a priori, standard engineering methodology deploys a rapid 'LoRA probe': train an r=16r=16 adapter on 5,000 samples for 1 epoch. If loss curve plateaus prematurely and downstream accuracy misses benchmarks significantly, the domain gap mandates increasing rank, adding target modules, or transitioning to continuous pre-training. ③ Storage and CI/CD Velocity: Saving 10 full-parameter checkpoints for a 70B model requires 1.4 TB1.4\,\text{TB} of storage, creates massive network transfer bottlenecks, and slows down automated deployment pipelines. LoRA checkpoints require <500 MB< 500\,\text{MB}, enabling rapid automated regression testing and instantaneous canary rollouts. ④ Quantization Loss in QLoRA: While QLoRA democratizes training, 4-bit base weights introduce slight quantization noise that can degrade complex mathematical reasoning performance compared to 16-bit LoRA. When VRAM is sufficient, 16-bit LoRA remains optimal. ⑤ Interview Strategy: Present the four-dimensional selection matrix (V,Δ,N,SV, \Delta, N, S), defend the 'larger base + LoRA' architecture, describe the rapid LoRA probing heuristic, and contrast single-tenant weight folding with multi-tenant dynamic serving.
⚠️ Common Interview Pitfalls
  • ✕
    Attempting full parameter fine-tuning on an underpowered model when budget permits serving a larger base model with LoRA
  • ✕
    Deploying QLoRA blindly when enterprise cluster VRAM is ample, paying unnecessary dequantization latency overheads
  • ✕
    Committing to extensive full fine-tuning runs without validating task difficulty via an initial lightweight LoRA baseline experiment
🎯 Interviewer Follow-up Inquiries
  • ?
    How do you quantitatively determine whether a target domain's task distance necessitates full fine-tuning versus high-rank LoRA?
  • ?
    Under what specific circumstances does 16-bit LoRA demonstrate noticeable accuracy advantages over 4-bit QLoRA?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM5-133: Mechanisms and Architectural Differences: Prefix/Prompt Tuning vs. LoRA📋 Back to BankNext →M5-135: Interaction of PEFT with Catastrophic Forgetting and Model Merging
中文速览与面试要点

解释 PEFT 方法的选择依据。

按'显存约束、任务距离、数据量、部署要求(延迟/多任务)'四维选择:LoRA 为默认,QLoRA 省显存,全参用于远域。

核心要点

  • 数学机理: 决策框架(四维) 。 (1) 显存约束 ——(a) 单卡、模型大 → QLoRA (4-bit 基座 + LoRA);(b) 显存充足 → LoRA(BF16) 或全参;(c) 多卡、资源充裕 → 全参可行。 (2) 任务距离(task distance) ——目标能力与基座能力的'距离':(a) 近 (风格、格式、特定任务微调)→ LoRA 足够;(b) 中等 (领域适配,如医疗/法律)→ LoRA(较大 r + 所有线性层)或'继续预训练 + LoRA';(c) 远 (新语言、新模态、大幅改变行为)→ 全参微调 或 继续预训练 (LoRA 容量不足)。 如何判断距离 ——(a) 领域语料的词汇/风格差异;(b) 小规模实验(LoRA 能否达标);(c) 直观判断(同语言同领域=近)。 (3) 数据量 ——(a) 少 ( 多 (>100k)→ 全参可行(容量利用充分);(c) 极多 → 全参或继续预训练。 (4) 部署要求 ——(a) 多任务/多租户 → LoRA(适配器切换/合并);(b) 极致推理延迟 → LoRA + 合并(无额外开销);(c) 需保留原模型能力 → LoRA(基座冻结,无遗忘)。 (5) 其他 ——(a) 参数极致受限 (如端侧)→ Prompt Tuning / IA³;(b) 需要最强效果且不计成本 → 全参 + 多轮迭代;(c) 需要快速实验 → LoRA(训练快、易切换)。 实践默认流程 ——(1) 先用 LoRA (r=8~64,所有线性层)建立基线;(2) 若效果不足 → 增大 r、增加应用位置;(3) 仍不足 → 试 QLoRA 更大模型 (用小模型全参 vs 大模型 LoRA,后者常更优);(4) 仍不足 → 全参微调或继续预训练。 关键洞察 —— '用大模型 + LoRA'常优于'用小模型 + 全参' (因为大模型的基座能力更强,LoRA 足以适配);故'先考虑换更大模型 + LoRA'是常见的更优路径。 与'对齐/RLHF'的关系 ——PEFT 也用于 RLHF(如 LoRA 作为 Actor,省显存);故选择依据同样适用。
  • 深度剖析与工程权衡:① '用大模型 + LoRA 优于小模型 + 全参'是重要实践洞察 ——因为基座能力是上限;故应 优先扩大基座 而非'把全参微调用在弱模型上'。② '任务距离'是最难判断的维度 ——常用'小规模实验'(用 LoRA 试一下能否达标)来判断;若 LoRA 明显不足,说明距离远。③ 'LoRA 的默认地位' ——综合工程优势与效果,LoRA 是 默认选择 ;只有明确不足时才升级到全参。④ '数据量与方法的交互' ——数据少时 LoRA 的正则优势明显(可能优于全参);数据多时全参的容量优势显现。⑤ '多任务场景 LoRA 独有优势' ——一套基座 + N 个适配器(可切换、可合并)是 LoRA 的独特能力;全参微调做不到。⑥ 面试要点 ——被问'PEFT 怎么选',应给出' 四维框架(显存/任务距离/数据量/部署)+ 默认 LoRA + 不足时升级 + 大模型 LoRA 优于小模型全参 ';能指出'任务距离用实验判断'与'优先扩大基座'是深度理解的标志。
  • 显存受限 → QLoRA;充足 → LoRA / 全参
  • 任务近/数据少 → LoRA;任务远/数据多 → 全参或继续预训练
  • 部署要求:多任务 → LoRA(可切换);极致延迟 → 合并
  • 其他:参数极致受限 → Prompt/IA³;需要最强 → 全参

常见陷阱

  • 在弱模型上做全参微调(不如大模型 + LoRA)
  • 不先试 LoRA 就直接全参(错失工程优势)