[Bug] PyTorch engine ignores use_rslora, so rsLoRA adapters run sqrt(r) times too weak

オープン 初心者向け
#5,111 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@Andreas-Hum がすでに取り組んでいます。

2026年11月8日 から。

  • #1 @LeonxLJX による — マージされずにクローズ
  • #2 @LeonxLJX による — マージされずにクローズ
  • #5112 @Andreas-Hum による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, pytorch
領域
backend

調査の方向性

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

InternLM/lmdeploy のほかの issue

InternLM/lmdeploy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。