Skip to main content

LoRA-Pro gradient-corrected AdamW optimizer for PyTorch and PEFT

Project description

LoRA-Pro AdamW

A lightweight Python package that ships a standalone implementation of the LoRA-Pro gradient correction for low-rank adapters together with an AdamW optimizer wrapper. The implementation is a clean-room port of the original LoRA-Pro DeepSpeed integration and is compatible with both plain PyTorch modules and PEFT LoRA layers.

Features

  • Detects LoRA pairs (lora_A, lora_B) on vanilla modules or PEFT ModuleDict layouts automatically.
  • Applies the exact LoRA-Pro closed-form gradient correction before taking an AdamW step.
  • Matches the upstream DeepSpeed implementation bit-for-bit in the provided regression tests.
  • Ships with pytest-based guards, including an integration test that cross-checks against the DeepSpeed implementation on PEFT adapters.

Installation

pip install lora-pro-adamw

Quick Start

import torch
from peft import LoraConfig, TaskType, get_peft_model
from lora_pro import LoRAProAdamW


class Toy(torch.nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.linear = torch.nn.Linear(32, 24, bias=False)

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return self.linear(x)


config = LoraConfig(
    task_type=TaskType.FEATURE_EXTRACTION,
    target_modules=["linear"],
    r=8,
    lora_alpha=16,
    lora_dropout=0.0,
    bias="none",
)
model = get_peft_model(Toy(), config)
# LoRAProAdamW wraps AdamW and performs the LoRA-Pro gradient correction internally.
# Unlike a vanilla torch.optim optimizer, instantiate it with the *model*, not parameter groups.
optimizer = LoRAProAdamW(model, lr=1e-3, weight_decay=0.0)

inputs = torch.randn(4, 32)
target = torch.randn(4, 24)
loss = torch.nn.functional.mse_loss(model(inputs), target)
loss.backward()
optimizer.step()
optimizer.zero_grad()

The optimizer automatically discovers LoRA parameters on the PEFT-wrapped modules and applies the LoRA-Pro gradient correction before delegating to AdamW.

Acknowledgements & Citation

This package reuses the LoRA-Pro mathematics introduced in:

  • Original implementation: mrflogs/LoRA-Pro
  • Paper: Zhengbo Wang, Jian Liang, Ran He, Zilei Wang, Tieniu Tan. LoRA-Pro: Are Low-Rank Adapters Properly Optimized? ICLR 2025. [OpenReview]

Please cite the paper above when using this optimizer in your research.

License

Released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lora_pro_adamw-0.2.0.tar.gz (80.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lora_pro_adamw-0.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file lora_pro_adamw-0.2.0.tar.gz.

File metadata

  • Download URL: lora_pro_adamw-0.2.0.tar.gz
  • Upload date:
  • Size: 80.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for lora_pro_adamw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cdd1905a602a2eafa417b746a946e06bcb30e7d7d7a4b26981ff46ec6a348dec
MD5 4660db19f22fe0877d2820ef11457205
BLAKE2b-256 ea8476cc8ce763613c9cba204b77bf43325b2b82c4f63f8c6832c4c56942ff20

See more details on using hashes here.

File details

Details for the file lora_pro_adamw-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lora_pro_adamw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75067ff57528f8255c2ddd2f5f2873a157aa4a80fc4d9646e1e8b337f948b596
MD5 cd2fafcb93829c4be553461e4bde665e
BLAKE2b-256 1dde076d96e8160c43e6422b666716f41cf7647a0b1eb2d523c1cc872b6e0c60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page