Registry / ai-ml / loralib

loralib

JSON →
library0.1.2pypypiunverified

loralib provides a PyTorch implementation of Low-Rank Adaptation (LoRA), a parameter-efficient fine-tuning method for large deep learning models. It enables adapting models with performance comparable to full fine-tuning while significantly reducing trainable parameters and memory footprint. The library is currently at version 0.1.2 and appears to be actively maintained by Microsoft, though PyPI updates are infrequent, with core development often reflected in GitHub activities like checkpoint releases.

pip install loralib
INSTALL
IMPORT
SIG · LORALIB
L
loralib
ai-mlpythonv0.1.2
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

loralib
import loralib
import loralib as lora

This quickstart demonstrates how to integrate loralib into an existing PyTorch model. It involves replacing target `nn.Linear` (or `nn.Embedding`, `nn.Conv2d`) layers with their `lora.Linear` counterparts, then marking only the newly introduced LoRA parameters as trainable, and finally, saving only these LoRA-specific weights for efficient deployment.

import torch import torch.nn as nn import loralib as lora class MyModel(nn.Module): def __init__(self): super().__init__() self.linear1 = nn.Linear(10, 20) self.linear2 = nn.Linear(20, 5) def forward(self, x): return self.linear2(self.linear1(x)) # 1. Instantiate the base model base_model = MyModel() # 2. Convert a layer to its LoRA equivalent # Replace nn.Linear with lora.Linear, specifying rank 'r' # Here, we convert linear1 to a LoRA-enabled layer base_model.linear1 = lora.Linear(base_model.linear1.in_features, base_model.linear1.out_features, r=4) # (Optional: Convert more layers) # base_model.linear2 = lora.Linear(base_model.linear2.in_features, base_model.linear2.out_features, r=4) # 3. Mark only LoRA parameters as trainable lora.mark_only_lora_as_trainable(base_model) # Verify trainable parameters print("Trainable parameters after LoRA conversion:") for name, param in base_model.named_parameters(): if param.requires_grad: print(f" {name}: {param.shape}") # Example usage (forward pass) input_tensor = torch.randn(1, 10) output_tensor = base_model(input_tensor) print(f"Output shape: {output_tensor.shape}") # 4. Save only the LoRA-specific state_dict lora_weights = lora.lora_state_dict(base_model) # torch.save(lora_weights, 'my_model_lora.pt')
Debug
Known issues
gotchaThe `loralib` Python package should not be confused with `LoRaLib`, which is an Arduino library for LoRa radio modules. They serve entirely different purposes, and searching broadly for 'LoRa library' can yield irrelevant results.
fix
Ensure you are searching specifically for 'loralib python' or 'loralib pytorch' for deep learning applications.
affects: All
gotchaloralib directly supports `nn.Linear`, `nn.Embedding`, and `nn.Conv2d` layers for adaptation. If your model contains other types of layers that you wish to apply LoRA to, you might need to implement custom wrappers or manual adaptation, or consider using other PEFT libraries like Hugging Face's PEFT which may offer broader layer support.
fix
For unsupported layer types, either manually implement LoRA adaptation, contribute to loralib, or evaluate alternative PEFT libraries.
affects: All
gotchaWhen using `loralib`, you still require the original pre-trained model checkpoint to perform inference or further training, as `loralib` only adds low-rank update matrices and does not store the original model weights.
fix
Always keep the original pre-trained model weights. LoRA checkpoints are typically small and are 'added' to the base model.
affects: All
deprecatedHugging Face's `PEFT` (Parameter-Efficient Fine-Tuning) library now offers robust LoRA implementations and is often recommended for integrating LoRA with Hugging Face Transformers models, potentially providing more comprehensive features and broader model compatibility than the original `loralib` package.
fix
Consider migrating to or starting new projects with Hugging Face's `PEFT` library for enhanced features, broader model support, and active development, especially when working with Transformer models.
affects: All
Upgrade
Version history
0.1.2latest on PyPI · released Aug 27, 2023
Audit
Dependencies
torchrequiredCore deep learning framework for LoRA implementation.
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources
loralib — pip install loralib · libregistry