Git Product home page Git Product logo

asymmetrylora's Introduction

Asymmetry in Low-Rank Adapters of Foundation Models

🌟 ArXiv Preprint

This repo hosts the code for the paper "Asymmetry in Low-Rank Adapters of Foundation Models". We discover and analysis the asymmetry of the LoRA adapter matrices B and A,

🔗 Quick Links

Install Requirements

Step 1: Please follow the installation steps. First, make sure you have Pytorch installed.

pip3 install torch==1.13.0 torchvision

Step 2: Then install the rest of the required packages:

cd AsymmetryLoRA
pip install -r requirement.txt

Usage

Our LoRASYM module follows the structure of the peft module. Specifically, we provide a flexible interface to account for the initialization settings of matrices A and B:

  • V and U: Right and left singular matrices of the original weight matrix.
  • random: Initializes with a random orthonormal matrix.
  • he: Uses torch.nn.init.kaiming_uniform_ for random uniform distribution, optimizing neural network layer activations.

You can customize matrices A and B with these options.

Matrix Options Example Explanation
A V, rand, he, zero A_rand A is intialized as random orthonormal matrix and is freezed during training.
B U, rand, he, zero hB_zero B is initialized as zero and will be updated.

Explaination: A_rand_hB_zero means A is initialized as random orthonormal and unchanged, while B starts at zero and is being updated.

We provide a wrapper that compiles with other models from Huggingface's transformer models. The following is an example of usage:

from transformers import AutoModelForSequenceClassification
from LoRASYM_peft.local_peft_model_all import PeftModelForCausalLM_local,
from LoRASYM_peft.local_lorasym_all import LoRASYMConfig

model = AutoModelForSequenceClassification.from_pretrained(
        model_args.model_name_or_path,
    )

update_rule_dict = para_dict = {"update_A": False, "update_B": True, 
"A_init": "rand", "B_init": "zero"}

lorasym_config = LoRASYMConfig(
                r=16,   
                lora_alpha=32,
                lora_dropout=0.05,
                bias="none",
                modules_to_save=["classifier"],
                update_rule=update_rule_dict,
                task_type="SEQ_CLS",
                )

lora_model = PeftModelForCausalLM_local(model, lorasym_config)

GLUE benchmark

Use the following command to fine-tune RoBERTa-large model for tasks in the GLUE benchmark.

cd GPT_experiments

python -m run_glue_origin_ft --model_name_or_path roberta-large \
    --task_name rte \
    --ft_method LoRASYM \
    --bf16 True \
    --tf32 True \
    --do_train \
    --do_eval \
    --learning_rate 4e-4 \
    --num_train_epochs 20 \
    --input_seed 7 \
    --lora_svd_method A_rand_hB_zero \
    --lora_rank 8 \
    --lora_alpha 16 \
    --overwrite_output_dir 

Bugs or Questions?

If you have any questions related to the code or the paper, feel free to email Jiacheng Zhu ([email protected]). Please feel free to open an issue if you encounter any problems when using the code.

Citation

Please cite our paper if you find the repo helpful in your work:

@article{zhu2024asymmetry,
      title={Asymmetry in Low-Rank Adapters of Foundation Models}, 
      author={Jiacheng Zhu and Kristjan Greenewald and Kimia Nadjahi and Haitz Sáez de Ocáriz Borde and Rickard Brüel Gabrielsson and Leshem Choshen and Marzyeh Ghassemi and Mikhail Yurochkin and Justin Solomon},
      year={2024},
}

asymmetrylora's People

Contributors

jiacheng-zhu-aiml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

peikalunci

asymmetrylora's Issues

Paper, B.2. Proof of Lemma 4.1 - σ

In the proof, I don't see the definition of σ. Is it defined in the lemma? In the deriviation of L(Q,B∗)?

  1. If you can explain in Theorem 4.3 how you used the Von Neumann trace inequality that would be lovely. I think it is an equality and not an inequality there, because you inserted $Q^TQ$ which is Identity, since Q is orthogonal, so the whole expression is equal IMHO

  2. Why E[III_B] has the term (r/d) in it? since the trace is cyclic invariant, I think we can get rid of UU^T and then there's no (r/d) term

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.