Skip to main content

Universal Adapter LoRA for architecture-agnostic model adaptation

Project description

Universal Adapter LoRA (UAL)

A Python package for creating portable, architecture-agnostic LoRA adapters that can be transferred across different model families without retraining.

Features

  • Architecture-Agnostic Transfer: Train once, deploy everywhere across GPT-2, LLaMA, Pythia, Qwen, and more
  • Intelligent LoRA Dispatcher: Automatically routes queries to the most suitable domain adapter
  • Dimension-Adaptive Projection: Handles arbitrary dimension mismatches through SVD
  • Multi-Agent Support: Deploy heterogeneous models with shared expertise
  • Production-Ready: Clean, testable code with comprehensive error handling

Installation

pip install ual-adapter

Or install from source:

git clone https://github.com/hamehrabi/ual-adapter.git
cd ual-adapter
pip install -e .

Quick Start

from ual_adapter import UniversalAdapter, LoRADispatcher
from transformers import AutoModel, AutoTokenizer

# Load your base model
model = AutoModel.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")

# Create UAL adapter
ual = UniversalAdapter(model, tokenizer)

# Train a domain-specific LoRA
medical_texts = ["Medical text 1", "Medical text 2", ...]
ual.train_adapter("medical", medical_texts)

# Export to AIR format (portable)
ual.export_adapter("medical", "medical_adapter.air")

# Transfer to different model
target_model = AutoModel.from_pretrained("TinyLlama/TinyLlama-1.1B")
target_ual = UniversalAdapter(target_model)
target_ual.import_adapter("medical_adapter.air")

# Use with intelligent dispatcher
dispatcher = LoRADispatcher(target_ual)
response = dispatcher.generate("What are the symptoms of diabetes?")

Architecture

The package consists of several key components:

  1. AIR Format: Architecture-Agnostic Intermediate Representation for portable adapters
  2. Model Binders: Family-aware mappings for different architectures
  3. Dimension Projection: SVD-based adaptation for dimension mismatches
  4. LoRA Dispatcher: Intelligent routing based on query embeddings
  5. Training Pipeline: Efficient adapter training with automatic target detection

Documentation

Full documentation available at https://ual-adapter.readthedocs.io

License

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

ual_adapter-0.1.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

ual_adapter-0.1.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file ual_adapter-0.1.0.tar.gz.

File metadata

  • Download URL: ual_adapter-0.1.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ual_adapter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a0bae9b4c00fd34e364375f46d2e42da028edbcea0c32177accc93ce0ddd9d47
MD5 49be5c2d3fed895a4bdf26d65db0a265
BLAKE2b-256 27c468019bd17efd4de4cf49a12342c41693535b43b57f704d37f95b1f0651a0

See more details on using hashes here.

File details

Details for the file ual_adapter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ual_adapter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ual_adapter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fbb8606d9c4d03f6735d7121678dd5e26eaaad34b6d528342c6af820aeed955
MD5 4167ee163990b63723c3673bf21100eb
BLAKE2b-256 7c5a2c377120f4602b321e045494414c4cb1f33c04376799cb31a25fea3d4dfa

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