Metadata-Version: 2.4
Name: ual-adapter
Version: 0.1.0
Summary: Universal Adapter LoRA for architecture-agnostic model adaptation
Author: UAL Adapter Contributors
Maintainer: UAL Adapter Contributors
License: MIT
Project-URL: Homepage, https://github.com/hamehrabi/ual-adapter
Project-URL: Documentation, https://ual-adapter.readthedocs.io
Project-URL: Repository, https://github.com/hamehrabi/ual-adapter.git
Project-URL: Issues, https://github.com/hamehrabi/ual-adapter/issues
Project-URL: Changelog, https://github.com/hamehrabi/ual-adapter/blob/main/CHANGELOG.md
Keywords: deep-learning,pytorch,transformers,lora,adapter,fine-tuning,transfer-learning,nlp,multi-agent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: torch>=2.0.0
Requires-Dist: transformers>=4.30.0
Requires-Dist: peft>=0.4.0
Requires-Dist: numpy>=1.21.0
Requires-Dist: safetensors>=0.3.0
Requires-Dist: sentence-transformers>=2.2.0
Requires-Dist: scikit-learn>=1.0.0
Requires-Dist: datasets>=2.10.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: tqdm>=4.64.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: jsonschema>=4.0.0
Requires-Dist: loguru>=0.6.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: pytest-xdist>=3.0; extra == "dev"
Requires-Dist: black>=22.0; extra == "dev"
Requires-Dist: isort>=5.10; extra == "dev"
Requires-Dist: flake8>=4.0; extra == "dev"
Requires-Dist: mypy>=0.990; extra == "dev"
Requires-Dist: pre-commit>=2.20; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=4.5; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "docs"
Requires-Dist: sphinxcontrib-napoleon>=0.7; extra == "docs"
Requires-Dist: myst-parser>=0.18; extra == "docs"
Provides-Extra: all
Requires-Dist: ual-adapter[dev]; extra == "all"
Requires-Dist: ual-adapter[docs]; extra == "all"
Requires-Dist: accelerate>=0.20.0; extra == "all"
Requires-Dist: bitsandbytes>=0.40.0; extra == "all"

# 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

```bash
pip install ual-adapter
```

Or install from source:

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

## Quick Start

```python
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](https://ual-adapter.readthedocs.io)

## License

MIT License
