Skip to main content

SingLoRA: Single Low-Rank Adaptation for PEFT

Project description

PEFT-SingLoRA

PyPI version License Python 3.8+

SingLoRA (Single Low-Rank Adaptation) is an efficient alternative to traditional LoRA that uses a single low-rank matrix instead of two, reducing parameters while maintaining performance. This package provides a PEFT-compatible implementation of SingLoRA.

Key Features

  • 🚀 50% fewer parameters than standard LoRA
  • 🔧 Fully compatible with PEFT ecosystem
  • 📊 Mathematically equivalent adaptation capability
  • 🎯 Easy integration with existing PEFT workflows

Installation

pip install peft-singlora

Quick Start

from transformers import AutoModelForCausalLM
from peft import LoraConfig, get_peft_model
from peft_singlora import setup_singlora

# Load your model
model = AutoModelForCausalLM.from_pretrained("your-model-name")

# Setup SingLoRA (this registers it with PEFT)
setup_singlora()

# Configure LoRA as usual - it will use SingLoRA under the hood
config = LoraConfig(
    r=8,
    lora_alpha=32,
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.1,
)

# Create PEFT model - will automatically use SingLoRA for linear layers
peft_model = get_peft_model(model, config)

# Train as usual!

How It Works

Traditional LoRA uses two matrices (A and B) for the low-rank decomposition:

W = W_0 + BA

SingLoRA uses a single matrix A with a symmetric decomposition:

W = W_0 + α/r * A @ A^T

This reduces trainable parameters from 2 * d * r to d * r while maintaining the same expressive power.

Advanced Usage

Custom Configuration

from peft_singlora import SingLoRAConfig

config = SingLoRAConfig(
    r=16,
    lora_alpha=32,
    target_modules=["q_proj", "v_proj", "k_proj"],
    lora_dropout=0.1,
    ramp_up_steps=1000,  # Gradually increase adaptation strength
)

Manual Integration

import torch.nn as nn
from peft_singlora import Linear as SingLoRALinear

# Register custom module mapping
custom_module_mapping = {nn.Linear: SingLoRALinear}
config._register_custom_module(custom_module_mapping)

Examples

Check out the examples/ directory for:

  • Basic usage with different model architectures
  • Fine-tuning examples with real datasets
  • Performance comparisons with standard LoRA

Citation

If you use SingLoRA in your research, please cite:

@article{singlora2024,
  title={SingLoRA: Rethinking Low-Rank Adaptation for Parameter-Efficient Fine-Tuning},
  author={...},
  year={2024}
}

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

License

This project is licensed under the BSD 2-Clause License - see the LICENSE file for details.

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

peft_singlora-0.1.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

peft_singlora-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file peft_singlora-0.1.1.tar.gz.

File metadata

  • Download URL: peft_singlora-0.1.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for peft_singlora-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f22888575489dfd3f39744d507d71b65fc3d19b50eecb994145bdd1f0a6cdedf
MD5 3f40ce3b1fe8e0089fe873744c4d72ea
BLAKE2b-256 e17a8a0cd8930e59896bd4f270cdca07629ef08521e5d7928768016967b42ee1

See more details on using hashes here.

File details

Details for the file peft_singlora-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: peft_singlora-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for peft_singlora-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d95962079c30a5318afc908e14905757d27c32e0f730fc392288992488dfac7
MD5 b5d333593f1b93948fb97d25c797e348
BLAKE2b-256 972a3ca4d754ba65f63c6b3215deee41352c341455d72134b8c453500637ffa0

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