[Bug] PyTorch engine ignores use_rslora, so rsLoRA adapters run sqrt(r) times too weak
メンテナーはふだん 2 日以内に返信
@Andreas-Hum がすでに取り組んでいます。
2026年11月8日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
lmdeploy/pytorch/adapter/adapter.py の get_ranks_and_scalings から始め、そのスケーリング計算を issue に記載されている use_rslora の動作と比較してください。再現スクリプトを使うと、rank 16、32、64 について PEFT とスケールを比較できます。issue によると、rsLoRA が有効な場合に期待されるスケールは lora_alpha / sqrt(r) です。
索引モデルが issue の本文から書いたものです。
説明
Checklist
- 1. I have searched related issues but cannot get the expected help.
- 2. The bug has not been fixed in the latest version.
- 3. Environment info and a minimal reproducible demo are included below.
Describe the bug
The PyTorch engine ignores use_rslora in PEFT adapter configs. PEFT scales a rank-stabilized LoRA adapter (arXiv:2312.03732) by lora_alpha / sqrt(r), but get_ranks_and_scalings in lmdeploy/pytorch/adapter/adapter.py always uses lora_alpha / r. The adapter loads without any error or warning, and its update is sqrt(r) times too weak: 25% of the intended strength at r = 16, 18% at r = 32 and 12.5% at r = 64.
How common is it and what effect does it have
I sampled 756 LoRA adapters on the Hugging Face Hub for popular base models (Llama-3.1/3.2, Qwen2.5/3, Mistral-7B, Gemma-2 and their unsloth 4-bit versions; the top by downloads and the most recent). 85 of them (11%) have use_rslora: true, most with r = 32.
To test the effect I fine-tuned SmolLM2-135M-Instruct with rsLoRA (lora_alpha 16, all linear projections, Alpaca, 200 steps, 3 seeds) and evaluated it in PEFT with the correct scale and with lora_alpha / r. Held-out loss, base model 1.903:
| r | lora_alpha / sqrt(r) |
lora_alpha / r |
share of the fine-tune's improvement lost |
|---|---|---|---|
| 16 | 1.543 | 1.719 | 49% |
| 64 | 1.539 | 1.801 | 72% |
(33% is lost at r = 8.)
Possible fix
Use lora_alpha / sqrt(r) when cfg.use_rslora is set. I have a PR with a test ready.
Reproduction
import torch
from peft import LoraConfig, get_peft_model
from lmdeploy.pytorch.adapter.adapter import get_ranks_and_scalings
class Tiny(torch.nn.Module):
def __init__(self):
super().__init__()
self.q_proj = torch.nn.Linear(8, 8)
for r in [16, 32, 64]:
cfg = LoraConfig(r=r, lora_alpha=16, target_modules=['q_proj'], use_rslora=True)
peft_scale = get_peft_model(Tiny(), cfg).base_model.model.q_proj.scaling['default']
_, scalings = get_ranks_and_scalings('q_proj', [cfg])
print(f'r = {r}: LMDeploy scale = {scalings[0].item():.4f}, PEFT scale = {peft_scale:.4f}')
Output:
r = 16: LMDeploy scale = 1.0000, PEFT scale = 4.0000
r = 32: LMDeploy scale = 0.5000, PEFT scale = 2.8284
r = 64: LMDeploy scale = 0.2500, PEFT scale = 2.0000
Environment
lmdeploy main at a0102d4 (2026-11-06), PyTorch engine
Python 3.13.13, peft 0.21.2, torch 2.15.0+cpu, Linux
A full install needs nvcc, which this machine doesn't have, so I loaded lmdeploy/pytorch/adapter/adapter.py without running the package __init__. The function only depends on torch.
Error traceback
No error: the adapter loads and silently runs too weak.
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 797
- 平均マージ
- 3日 15時間
- マージ済み PR(30日)
- 52
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
InternLM/lmdeploy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 2 日以内に返信
-
[Bug] apply_rotary_pos_emb: leaves output tails unwritten with partial rotation対応中かも @shotsan が 15 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
[Feature] Expose `max_model_len` (session_len) in `/v1/models` model card対応中かも @FOWEPJF255 が 37 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
InternLM/lmdeploy の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
Techiebutler/freeframe#687 ·
メンテナーはふだん 1 日以内に返信
-
bug verbose GC
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
IBM/javacore-analyser#677 ·
メンテナーはふだん 1 日以内に返信
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
NousResearch/hermes-agent#163932 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's file対応中かも @Beehtrix が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#907 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
external
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
langchain-ai/docs#8386 ·
メンテナーはふだん 1 日以内に返信