{"id":15839371,"url":"https://github.com/gunale0926/sorsa","last_synced_at":"2025-03-17T16:11:53.191Z","repository":{"id":243560169,"uuid":"812753383","full_name":"Gunale0926/SORSA","owner":"Gunale0926","description":"SORSA: Singular Values and Orthonormal Regularized Singular Vectors Adaptation of Large Language Models","archived":false,"fork":false,"pushed_at":"2025-02-24T18:31:53.000Z","size":4602,"stargazers_count":40,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T03:43:12.647Z","etag":null,"topics":["deep-learning","fine-tuning","llama","lora","machine-learning","nlp","peft","python","pytorch","rwkv","sorsa","svd","transformer"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2409.00055","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gunale0926.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-09T19:28:18.000Z","updated_at":"2025-03-05T13:52:50.000Z","dependencies_parsed_at":"2024-07-27T19:11:25.154Z","dependency_job_id":"5c34a125-c39c-4a85-b615-d2083353d614","html_url":"https://github.com/Gunale0926/SORSA","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"47604d91c52b6bc098890080658935f6c0dd964f"},"previous_names":["gunale0926/sorsa"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gunale0926%2FSORSA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gunale0926%2FSORSA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gunale0926%2FSORSA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gunale0926%2FSORSA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gunale0926","download_url":"https://codeload.github.com/Gunale0926/SORSA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066188,"owners_count":20392406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","fine-tuning","llama","lora","machine-learning","nlp","peft","python","pytorch","rwkv","sorsa","svd","transformer"],"created_at":"2024-10-05T16:04:20.879Z","updated_at":"2025-03-17T16:11:53.172Z","avatar_url":"https://github.com/Gunale0926.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SORSA: Singular Values and Orthonormal Regularized Singular Vectors Adaptation of Large Language Models\n\n[![arXiv](https://img.shields.io/badge/arXiv-2409.00055-b31b1b.svg)](https://arxiv.org/abs/2409.00055) [![PyPI - Version](https://img.shields.io/pypi/v/sorsa)](https://pypi.org/project/sorsa/)\n\nAuthor: [Yang Cao](https://scholar.google.com/citations?user=pCrKkUQAAAAJ)\n\nThis repository contains the codes of experiments of the paper *SORSA: Singular Values and Orthonormal Regularized Singular Vectors Adaptation of Large Language Models*.\n\n![Architecture of SORSA](./assets/SORSA.png)\n\nThe rapid advancement in large language models (LLMs) comes with a significant increase in their parameter size, presenting challenges for adaptation and fine-tuning. Parameter-efficient fine-tuning (PEFT) methods are widely used to adapt LLMs for downstream tasks efficiently. In this paper, we propose Singular Values and Orthonormal Regularized Singular Vectors Adaptation, or SORSA, a novel PEFT method. Each SORSA adapter consists of two main parts: trainable principal singular weights $W_p = U_p \\text{diag}(S_p) V^\\top_p$, and frozen residual weights $W_r = U_r \\text{diag}(S_r) V^\\top_r$. These parts are initialized by performing SVD on pre-trained weights. Moreover, we implement and analyze an orthonormal regularizer. SORSA adapters could be merged during inference, thus eliminating any inference latency.\n\n## Empirical Experiments\n\n![Exp](./assets/Exp.png)\n\n\n## Reproduce the Experiments\n\nFirst, install `sorsa` package from pip:\n```bash\npip install sorsa\n```\n\nThen, create `.env` file in the root directory of the project and add your [Hugging Face Access Token](https://huggingface.co/settings/tokens):\n```bash\nhf=Your_Hugging_Face_Access_Token\n```\n\n### Llama 2 7B, Mistral v0.1 7B and Gemma 7B\n\nFirst, install the packages via anaconda\n\n```bash\nconda env create -f environment.yml\n```\n\nRun scripts from `./scripts/train_sorsa.sh` to train the model.\n\nAfter training, run the ``./scripts/merge_sorsa.sh`` to merge the adapter to the base model:\n\nRun following command to evaluate on GSM-8K:\n\n```bash\npython3 run.py --name llama2_sorsa_r128 \\\n  --test \\\n  --test-dataset gsm-8k \\\n  --test-precision bf16\n```\n\nRun following command to evaluate on MATH:\n\n```bash\npython3 run.py --name llama2_sorsa_r128 \\\n  --test \\\n  --test-dataset math \\\n  --test-precision bf16\n```\n\nRun following command to evaluate on HumanEval:\n\n```bash\npython3 run.py --name llama2_sorsa_r128 \\\n  --test \\\n  --test-dataset humaneval \\\n  --test-precision bf16\n```\n\n### RWKV6\n\nIf you are training, merging or testing RWKV6 model, please add `--rwkv` flag to `run.py`.\n\n## Cite the work\n\nYou could cite the work by using the BibTeX code as follows:\n```bibtex\n@article{cao2024sorsa,\n  title={SORSA: Singular Values and Orthonormal Regularized Singular Vectors Adaptation of Large Language Models},\n  author={Cao, Yang},\n  journal={arXiv preprint arXiv:2409.00055},\n  year={2024}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgunale0926%2Fsorsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgunale0926%2Fsorsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgunale0926%2Fsorsa/lists"}