後悔のないLoRA
John Schulmanらによる、LoRA(Low-Rank Adaptation)の効率的な適応手法についての研究。従来の微調整よりも計算コストを抑えつつ、モデル性能を維持する方法を提案。
キーポイント
LoRAは大規模言語モデルの効率的なファインチューニング手法で、元の重み行列WをW+γBAに置き換える低ランク適応技術
LoRAはマルチテナント推論、学習レイアウトの小型化、アダプターの容易な転送という3つの運用上の利点を持つ
LoRAは完全ファインチューニング(FullFT)に比べて学習リソースを大幅に削減できるが、事前学習に近い設定では性能が劣る可能性がある
PunicaやvLLM、SGLangなどの推論エンジンがマルチテナントLoRAサービングを実装し、実用化が進んでいる
影響分析・編集コメントを表示
影響分析
LoRA技術の普及は大規模言語モデルのファインチューニングの民主化を促進し、より多くの組織が限られたリソースでカスタマイズしたモデルを開発・運用できる環境を整備する。特にマルチテナント推論の実現は、クラウドサービスにおける効率的なモデル配備とコスト削減に貢献し、AIサービスの実用展開を加速させる可能性がある。
編集コメント
LoRAの実用メリットが明確に整理されており、研究段階から実運用段階への移行を示唆する重要な分析記事。運用コスト削減とアクセシビリティ向上の両面で業界に影響を与える可能性が高い。
現在の最先端言語モデルは、1兆を超えるパラメータを持ち、数十兆トークンで事前学習されています。この巨大な規模は、人類の知識を学習・表現するために必要であり、モデルの基本性能はスケールに応じて向上し続けています。
一方で、事後学習(ファインチューニング)はより小規模なデータセットを用い、通常、より狭い知識領域や振る舞いに焦点を当てます。ギガビットやメガビット規模の学習データによる更新を、テラビット規模の重みパラメータ全体で表現するのは非効率という考えが、パラメータ効率的ファインチューニング(PEFT)の動機となっています。PEFTは、大規模ネットワークのうち、はるかに少ないパラメータ群のみを更新して調整する手法です。
その主要な方法がLoRA(Low-Rank Adaptation)です。LoRAは、元のモデルの重み行列Wを、$W' = W + \gamma BA$という修正版に置き換えます。ここでBとAは行列であり、両者を合わせたパラメータ数はWよりもはるかに少なく、$\gamma$はスケーリング定数です。つまり、LoRAはファインチューニングによる更新を低次元で表現します。
LoRAは事後学習のコストと速度で利点を持つほか、フルファインチューニング(FullFT)よりも好まれる運用上の理由がいくつかあります:
第一に、マルチテナント推論です。LoRAは元の重みを変更せずにアダプタ(A、B行列)を学習するため、単一の推論サーバーがメモリ内に多数のアダプタ(異なるモデルバージョン)を保持し、バッチ処理で同時に利用できます。vLLMやSGLangなどの現代的な推論エンジンはこの機能を実装しています。
第二に、学習時のリソース構成です。モデル全体をファインチューニングする場合、元の重みに加えてオプティマイザの状態を、多くの場合より高精度で保存する必要があります。そのため、FullFTは同じモデルを推論する時よりも一桁多い計算資源を必要とし、異なるリソース構成が求められます。一方、LoRAは学習するパラメータがはるかに少なくメモリ使用量も小さいため、推論時とほぼ同様のリソース構成で学習でき、学習のアクセス性と効率性を高めます。
第三に、読み込みと転送の容易さです。保存する重みが少ないため、LoRAアダプタのセットアップやマシン間での転送が迅速かつ容易です。
これらの理由から、2021年のLoRA論文発表以来、その人気は高まっています。しかし、LoRAの性能がFullFTに対してどの程度であるかについては、研究文献上は明確ではありません。事前学習に近い設定ではLoRAの性能は劣るとの見解がある一方で、特定の条件下では同等の性能を達成できるという報告もあります。性能比較は、タスクの性質、データ量、モデル規模、ハイパーパラメータなど多くの要因に依存するため、一概に結論づけることは難しい状況です。
原文を表示
LoRA Without Regret - Thinking Machines Lab LoRA Without Regret
Today’s leading language models contain upwards of a trillion parameters, pretrained on tens of trillions of tokens. Base model performance keeps improving with scale, as these trillions are necessary for learning and representing all the patterns in written-down human knowledge.
In contrast, post-training involves smaller datasets and generally focuses on narrower domains of knowledge and ranges of behavior. It seems wasteful to use a terabit of weights to represent updates from a gigabit or megabit of training data. This intuition has motivated parameter efficient fine-tuning (PEFT), which adjusts a large network by updating a much smaller set of parameters.
The leading PEFT method is low-rank adaptation, or LoRA. LoRA replaces each weight matrix W from the original model with a modified version $W' = W + \gamma BA$, where B and A are matrices that together have far fewer parameters than W, and $\gamma$ is a constant scaling factor. In effect, LoRA creates a low-dimensional representation of the updates imparted by fine-tuning.
LoRA may offer advantages in the cost and speed of post-training, and there are also a few operational reasons to prefer it to full fine-tuning (henceforth, FullFT):
Multi-tenant serving. Since LoRA trains an adapter (i.e., the A and B matrices) while keeping the original weights unchanged, a single inference server can keep many adapters (different model versions) in memory and sample from them simultaneously in a batched way.Punica: Multi-Tenant LoRA Serving (Chen, Ye, et al, 2023) Modern inference engines such as vLLM and SGLang implement this feature.
Layout size for training. When fine-tuning the whole model, the optimizer state needs to be stored along with the original weights, often at higher precision. As a result, FullFT usually requires an order of magnitude more accelerators than sampling from the same model does, and thus a different layout.For training, besides storing the weights, we typically need to store gradients and optimizer moments for all of the weights; moreover, these variables are often stored in higher precision (float32) than what’s used to store the weights for inference (bfloat16 or lower). Since LoRA trains far fewer weights and uses far less memory, it can be trained on a layout only slightly larger than what is used for sampling. This makes training more accessible, and often more efficient.
Ease of loading and transfer. With fewer weights to store, LoRA adapters are fast and easy to set up or transfer between machines.
These reasons are sufficient to explain the growing popularity of LoRA since the publication of the original LoRA paper in 2021.LoRA: Low-Rank Adaptation of Large Language Models (Hu et al, 2021) However, the literature is unclear on how well LoRA performs relative to FullFT.
There is agreement that LoRA underperforms in settings that resemble pre-training,LoRA Learns Less and Forgets Less (Biderman et al, 2024) namely those with very large datasets that exceed the storage limits of LoRA parameters. But for dataset sizes that are typical in post-training, LoRA has sufficient capacity to store the essential information. However, this fact makes no guarantees regarding sample efficiency and compute efficiency. The question is: can LoRA match the performance of full fine-tuning, and if so, under which conditions?
In our experiments, we find that indeed, when we get a few key details right, LoRA learns with the same sample efficiency as FullFT and achieves the same ultimate performance.
This article covers a series of supervised fine-tuning and reinforcement learning experiments we conducted to determine the conditions under which LoRA matches FullFT efficiency. To this end, we did a few things differently from previous experiments on LoRA:
We investigated the general relationship between training set size and number of LoRA parameters, rather than focusing on specific datasets and tasks.
In supervised learning, we measured log loss rather than employing sampling-based evals, with the same goal of generality in mind. Log loss measurement gives clean results and scaling laws over ranges of training steps and training parameters.
For supervised fine-tuning on small-to-medium-sized instruction-tuning and reasoning datasets, LoRA performs the same as full fine-tuning.
For datasets that exceed LoRA capacity, LoRA underperforms FullFT. Rather than the loss reaching a distinct floor that it can’t go below, LoRA results in worse training efficiency that depends on the relationship between model capacity to dataset size.
In some scenarios, LoRA is less tolerant of large batch sizes than full fine-tuning — it pays a larger penalty in loss as batch size increases beyond some point. This penalty is not mitigated by increasing the LoRA rank; it is a property of the product-of-matrices parametrization, which has different training dynamics than optimizing
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み