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

Aperta Adatta ai principianti
#5,111 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@Andreas-Hum ci sta già lavorando.

Dal 8/11/2026.

  • #1 di @LeonxLJX — chiusa senza merge
  • #2 di @LeonxLJX — chiusa senza merge
  • #5112 di @Andreas-Hum — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch
Ambito
backend

Direzione di ricerca

Inizia da get_ranks_and_scalings in lmdeploy/pytorch/adapter/adapter.py e confronta il suo calcolo del fattore di scala con il comportamento di use_rslora descritto nell’issue. Lo script di riproduzione permette di verificare il fattore di scala rispetto a PEFT per i rank 16, 32 e 64; l’issue afferma che il fattore di scala atteso è lora_alpha / sqrt(r) quando rsLoRA è abilitato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
8.2k
Fork
797
Merge medio
3g 15h
PR unite (30g)
52

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di InternLM/lmdeploy

Tutte le issue di InternLM/lmdeploy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.