A package for managing LoRA adapters in language models ideal for hotswapping
Project description
Netra Adapters
Netra Adapter is a Python package designed to dynamically load and integrate Low-Rank Adaptation (LoRA) weights into transformer models, facilitating fine-tuned performance for various tasks.
Features
- Load LoRA adapter weights from local files or directly from the Hugging Face Hub.
- Dynamically integrate and remove adapter weights based on query content.
- Generate responses using integrated LoRA weights.
Installation
To install the netra_adapter package, clone this repository and install the dependencies:
pip install netra_adapter
Example Usage
Importing and Initializing
First, import the necessary modules and initialize the LoRAAdapterManager with the desired model:
from netra_adapter import LoRAAdapterManager
import torch
# Determine the device to use (GPU or CPU)
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# Instantiate the LoRAAdapterManager with a specified model
adapter_manager = LoRAAdapterManager(model_name='gpt2', device=device)
# Load LoRA weights from the Hugging Face Hub
adapter_manager.load_lora_weights(adapter_name='sales', filepath_or_repo='AdapterHub/gpt2_sales')
adapter_manager.load_lora_weights(adapter_name='support', filepath_or_repo='AdapterHub/gpt2_support')
# Function to generate a response based on query content
def generate_adaptive_response(query):
adapter_name = None
if 'sales' in query.lower():
adapter_name = 'sales'
elif 'support' in query.lower():
adapter_name = 'support'
else:
return "Query does not match any adapter criteria."
# Integrate the selected LoRA weights
adapter_manager.integrate_lora_weights(adapter_name)
# Generate the response with the integrated LoRA weights
response = adapter_manager.generate_response(query)
# Remove the integrated adapter hooks to reset the model
adapter_manager.remove_adapter_hooks(adapter_name)
return response
# Example queries
query_sales = "Can you provide me with the sales report for Q1?"
query_support = "I need help with my account, it doesn't login."
# Generate adaptive responses
response_sales = generate_adaptive_response(query_sales)
print("Sales query response:", response_sales)
print('#' * 100)
response_support = generate_adaptive_response(query_support)
print("Support query response:", response_support)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file netra_adapter-0.1.5.tar.gz.
File metadata
- Download URL: netra_adapter-0.1.5.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56a575ad300907248e6ff8ef84e119a39695598280ea9a182934494d28b4c708
|
|
| MD5 |
ef01ec6c2da52000c0e6f58e34696a08
|
|
| BLAKE2b-256 |
9756925676078ebbe1c95c6d39525addd7636c238de892114bfb6b3ebb8c4bb6
|
File details
Details for the file netra_adapter-0.1.5-py3-none-any.whl.
File metadata
- Download URL: netra_adapter-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b0116ab39a5580d6cc298163c04d536c33e25e8b24f294417c07384f1ab9ec7
|
|
| MD5 |
b2a879ffe91bcd7e3efc60025654c1a4
|
|
| BLAKE2b-256 |
ed4ed69a9afa7b592b7a8ccae11c073e0cc818b81323def9a1f25fb80a4e50ae
|