Submitted by cccntu t3_1182fqd in MachineLearning

Hey r/MachineLearning! I wanted to share a new PyTorch library I've been working on that I think could be really useful for anyone looking to fine-tune large models with LoRA.

https://github.com/cccntu/minlora

The library is based on the LoRA technique (Low-Rank Adaptation). "which freezes the pre-trained model weights and injects trainable rank decomposition matrices into each layer." (- quote from the paper)

With this library, you can easily apply LoRA to any PyTorch model with just a few lines of code.

One of the benefits of this library is that it's really small - just 100 lines of code. Despite its size, it's quite powerful and has been tested on a variety of different models, including nanoGPT by Karpathy, and stable diffusion.

It also features an easy-to-use interface that allows you to serve multiple LoRA models at the same time!

103

Comments

You must log in or register to comment.

pyepyepie t1_j9fj0uf wrote

WOW - what a cool idea (the paper), I was not aware it exists! Thank you so much for the simple implementation and the info.

8

brucebay t1_j9g8al3 wrote

Thank you for this. I never used lora except part of stable diffusion training. You linked MS lora lib too. What are the differences between yours and theirs?

3

cccntu OP t1_j9hsouu wrote

Theirs requires you to rewrite the whole model and replace every layer you want to apply LoRA to with the LoRA counterpart, or use monky-patching.Mine utilizes PyTorch parametrizations to inject the LoRA logic to existing models. If your model has nn.Linear, you can call add_lora(model) to add LoRA to all the linear layers. And it's not limited to Linear, you can see how I extended it to Embedding, Conv2d in a couple lines of code. https://github.com/cccntu/minLoRA/blob/main/minlora/model.py

9

brucebay t1_j9i2kd6 wrote

Thank you for this clear explanation.

2

thecuteturtle t1_j9nwdfm wrote

Man i feel so behind that i didnt even know LoRA.

1

JClub t1_j9j5cv4 wrote

Sorry, but why do we need another package? Can't you build on top of https://github.com/huggingface/peft ?

0

cccntu OP t1_j9jz6ov wrote

This project started out as me exploring if PyTorch parametrizations could be used to do LoRA, and it turned out perfect for this task! And I simply wanted to share that.
I think it would be interesting to see it integrated into PEFT, too. Although they already have their own LoRA implementation there.

1