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

Abierto Apto para principiantes
#5,111 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@Andreas-Hum ya está trabajando en esto.

Desde el 8/11/2026.

  • #1 de @LeonxLJX — cerrado sin fusionar
  • #2 de @LeonxLJX — cerrado sin fusionar
  • #5112 de @Andreas-Hum — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch
Área
backend

Línea de trabajo

Empieza con get_ranks_and_scalings en lmdeploy/pytorch/adapter/adapter.py y compara su cálculo de escalado con el comportamiento de use_rslora descrito en el issue. El script de reproducción permite comprobar el escalado frente a PEFT para los rangos 16, 32 y 64; el issue indica que el escalado esperado es lora_alpha / sqrt(r) cuando rsLoRA está activado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
8.2k
Forks
797
Merge medio
3 d 15 h
PR fusionados (30 d)
52

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de InternLM/lmdeploy

Todos los issues de InternLM/lmdeploy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.