license: llama2
Lazy LoRA
Benefits
- using the updated Meta's LLaMA-2 models.
- support 4-bit qlora, extreme GPU memory and inference time saving;
- comparable MMLU evaluation dataset results, llama2-13b:
eval | test | comp-eval | comp-test | |
---|---|---|---|---|
llama2-13b | 56.57% | 55.71% | ||
ckpt-200 | 56.19% | 54.75% | -0.38% | -0.96% |
ckpt-800 | 53.16% | 55.06% | -3.41% | -0.65% |
llama2-13b: "31820c723bc0368c339e067553021dc6a8bf4375"
- This lazy-lora adapter is based on Meta's LLaMA-2-13b-hf, and using the oasst1 dataset, following Guanaco.
Introduction
Determine the rank of LoRA layers by the singular values of pretrained weight matrices. Also, combines:
- LoRA: LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS
- Prefix Tuning: [Prefix-Tuning: Optimizing Continuous Prompts for Generation](https://aclanthology.org/2021.acl-long.3 53/), [P-Tuning v2: Prompt Tuning Can Be Comparable to Fine-tuning Universally Across Scales and Tasks](https://arxiv.or g/pdf/2110.07602.pdf)
- Prompt Tuning: The Power of Scale for Parameter-Efficient Prompt Tuning
- LLaMA adapter: [LLaMA-Adapter: Efficient Fine-tuning of Language Models with Zero-init Attention] (https://arxiv.org/abs/2303.16199) in one model.
This allows you to perform LoRA (additional low rank adapters inserted to each linear layer), and prompt learning (additional virtual tokens attached to the input and to the attention layers acting as past_key_values
)
Usage:
import sys
sys.path.insert(1, '/workspace/asr/peft/src')
# TODO set this path to the lazy-lora source code path,
# or you can install it from source code:
# TODO, please install lazylora for usage:
# git clone git@github.com:Xianchao-Wu/peft.git
# cd peft
# python setup.py install
from transformers import (AutoTokenizer,
AutoModelForCausalLM, BitsAndBytesConfig)
from peft import PeftModel, PeftConfig
import os
import torch
#import ipdb; ipdb.set_trace()
cache_dir="/workspace/asr/peft/qlora"
# TODO set this cache_dir to the path where you
# stored (or, want to store) llama2-13b-hf model
lazylora_dir=os.getcwd()
# the path that contains 'adapter_config.json'
# and 'adapter_model.bin'
config = PeftConfig.from_pretrained(lazylora_dir)
tokenizer = AutoTokenizer.from_pretrained(
config.base_model_name_or_path,
cache_dir=cache_dir,
use_auth_token=True
)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_compute_dtype=torch.bfloat16
)
model = AutoModelForCausalLM.from_pretrained(
config.base_model_name_or_path,
quantization_config=bnb_config,
device_map="auto",
cache_dir=cache_dir,
use_auth_token=True
)
#model.print_trainable_parameters()
print(sum(p.numel() for p in model.parameters()))
# 6,671,979,520 -> half-size of 13B due to 4-bit loading
model = PeftModel.from_pretrained(model, lazylora_dir)
print('after adding lazy lora parameters:')
model.print_trainable_parameters()
# trainable params: 0 || all params: 6,922,290,688 || trainable%: 0.0
MMLU result:
MMLU eval result:
{"mmlu_loss": 1.459045737611944,
"mmlu_eval_accuracy_sociology": 0.8181818181818182,
"mmlu_eval_accuracy_high_school_government_and_politics": 0.7142857142857143,
"mmlu_eval_accuracy_marketing": 0.88,
"mmlu_eval_accuracy_us_foreign_policy": 0.9090909090909091,
"mmlu_eval_accuracy_high_school_world_history": 0.5,
"mmlu_eval_accuracy_management": 0.7272727272727273,
"mmlu_eval_accuracy_college_mathematics": 0.36363636363636365,
"mmlu_eval_accuracy_high_school_us_history": 0.8181818181818182,
"mmlu_eval_accuracy_high_school_computer_science": 0.5555555555555556,
"mmlu_eval_accuracy_elementary_mathematics": 0.3170731707317073,
"mmlu_eval_accuracy_high_school_chemistry": 0.36363636363636365,
"mmlu_eval_accuracy_computer_security": 0.8181818181818182,
"mmlu_eval_accuracy_college_chemistry": 0.375,
"mmlu_eval_accuracy_econometrics": 0.4166666666666667,
"mmlu_eval_accuracy_professional_psychology": 0.5362318840579711,
"mmlu_eval_accuracy_high_school_statistics": 0.30434782608695654,
"mmlu_eval_accuracy_high_school_macroeconomics": 0.5581395348837209,
"mmlu_eval_accuracy_moral_scenarios": 0.36,
"mmlu_eval_accuracy_moral_disputes": 0.6578947368421053,
"mmlu_eval_accuracy_astronomy": 0.5625,
"mmlu_eval_accuracy_professional_accounting": 0.41935483870967744,
"mmlu_eval_accuracy_human_sexuality": 0.5,
"mmlu_eval_accuracy_world_religions": 0.7894736842105263,
"mmlu_eval_accuracy_high_school_psychology": 0.8166666666666667,
"mmlu_eval_accuracy_nutrition": 0.7575757575757576,
"mmlu_eval_accuracy_high_school_geography": 0.8181818181818182,
"mmlu_eval_accuracy_global_facts": 0.4,
"mmlu_eval_accuracy_high_school_mathematics": 0.20689655172413793,
"mmlu_eval_accuracy_college_medicine": 0.4090909090909091,
"mmlu_eval_accuracy_electrical_engineering": 0.5,
"mmlu_eval_accuracy_jurisprudence": 0.6363636363636364,
"mmlu_eval_accuracy_public_relations": 0.5833333333333334,
"mmlu_eval_accuracy_virology": 0.4444444444444444,
"mmlu_eval_accuracy_high_school_physics": 0.29411764705882354,
"mmlu_eval_accuracy_college_physics": 0.6363636363636364,
"mmlu_eval_accuracy_miscellaneous": 0.686046511627907,
"mmlu_eval_accuracy_international_law": 0.8461538461538461,
"mmlu_eval_accuracy_human_aging": 0.6956521739130435,
"mmlu_eval_accuracy_conceptual_physics": 0.38461538461538464,
"mmlu_eval_accuracy_formal_logic": 0.2857142857142857,
"mmlu_eval_accuracy_medical_genetics": 0.7272727272727273,
"mmlu_eval_accuracy_philosophy": 0.6470588235294118,
"mmlu_eval_accuracy_professional_medicine": 0.5806451612903226,
"mmlu_eval_accuracy_security_studies": 0.6666666666666666,
"mmlu_eval_accuracy_college_biology": 0.625,
"mmlu_eval_accuracy_high_school_biology": 0.53125,
"mmlu_eval_accuracy_machine_learning": 0.45454545454545453,
"mmlu_eval_accuracy_high_school_microeconomics": 0.7307692307692307,
"mmlu_eval_accuracy_professional_law": 0.38823529411764707,
"mmlu_eval_accuracy_logical_fallacies": 0.7777777777777778,
"mmlu_eval_accuracy_high_school_european_history": 0.7222222222222222,
"mmlu_eval_accuracy_prehistory": 0.6,
"mmlu_eval_accuracy_abstract_algebra": 0.2727272727272727,
"mmlu_eval_accuracy_clinical_knowledge": 0.5517241379310345,
"mmlu_eval_accuracy_anatomy": 0.35714285714285715,
"mmlu_eval_accuracy_business_ethics": 0.2727272727272727,
"mmlu_eval_accuracy_college_computer_science": 0.45454545454545453,
"mmlu_eval_accuracy": 0.5618637260755334}
MMLU test result:
{"mmlu_loss": 1.4737504210172938,
"mmlu_test_accuracy_professional_law": 0.4172099087353325,
"mmlu_test_accuracy_formal_logic": 0.3412698412698413,
"mmlu_test_accuracy_anatomy": 0.4962962962962963,
"mmlu_test_accuracy_professional_medicine": 0.5404411764705882,
"mmlu_test_accuracy_high_school_mathematics": 0.2851851851851852,
"mmlu_test_accuracy_high_school_government_and_politics": 0.8134715025906736,
"mmlu_test_accuracy_electrical_engineering": 0.5448275862068965,
"mmlu_test_accuracy_conceptual_physics": 0.4595744680851064,
"mmlu_test_accuracy_jurisprudence": 0.7407407407407407,
"mmlu_test_accuracy_college_chemistry": 0.4,
"mmlu_test_accuracy_high_school_computer_science": 0.56,
"mmlu_test_accuracy_college_computer_science": 0.44,
"mmlu_test_accuracy_marketing": 0.7863247863247863,
"mmlu_test_accuracy_high_school_psychology": 0.7376146788990826,
"mmlu_test_accuracy_professional_psychology": 0.5522875816993464,
"mmlu_test_accuracy_logical_fallacies": 0.6748466257668712,
"mmlu_test_accuracy_high_school_microeconomics": 0.5672268907563025,
"mmlu_test_accuracy_international_law": 0.7107438016528925,
"mmlu_test_accuracy_high_school_world_history": 0.7088607594936709,
"mmlu_test_accuracy_medical_genetics": 0.57,
"mmlu_test_accuracy_professional_accounting": 0.41843971631205673,
"mmlu_test_accuracy_business_ethics": 0.57,
"mmlu_test_accuracy_moral_scenarios": 0.293854748603352,
"mmlu_test_accuracy_abstract_algebra": 0.34,
"mmlu_test_accuracy_elementary_mathematics": 0.328042328042328,
"mmlu_test_accuracy_high_school_biology": 0.6580645161290323,
"mmlu_test_accuracy_public_relations": 0.6090909090909091,
"mmlu_test_accuracy_high_school_physics": 0.31788079470198677,
"mmlu_test_accuracy_astronomy": 0.4934210526315789,
"mmlu_test_accuracy_high_school_us_history": 0.75,
"mmlu_test_accuracy_college_medicine": 0.5028901734104047,
"mmlu_test_accuracy_college_mathematics": 0.34,
"mmlu_test_accuracy_econometrics": 0.2894736842105263,
"mmlu_test_accuracy_clinical_knowledge": 0.6150943396226415,
"mmlu_test_accuracy_moral_disputes": 0.630057803468208,
"mmlu_test_accuracy_machine_learning": 0.26785714285714285,
"mmlu_test_accuracy_human_sexuality": 0.5801526717557252,
"mmlu_test_accuracy_virology": 0.4457831325301205,
"mmlu_test_accuracy_high_school_chemistry": 0.43349753694581283,
"mmlu_test_accuracy_high_school_geography": 0.6515151515151515,
"mmlu_test_accuracy_high_school_european_history": 0.6363636363636364,
"mmlu_test_accuracy_nutrition": 0.5849673202614379,
"mmlu_test_accuracy_human_aging": 0.6502242152466368,
"mmlu_test_accuracy_philosophy": 0.639871382636656,
"mmlu_test_accuracy_global_facts": 0.34,
"mmlu_test_accuracy_high_school_statistics": 0.4722222222222222,
"mmlu_test_accuracy_college_biology": 0.5486111111111112,
"mmlu_test_accuracy_management": 0.6893203883495146,
"mmlu_test_accuracy_sociology": 0.7213930348258707,
"mmlu_test_accuracy_security_studies": 0.6326530612244898,
"mmlu_test_accuracy_college_physics": 0.24509803921568626,
"mmlu_test_accuracy_high_school_macroeconomics": 0.5,
"mmlu_test_accuracy_us_foreign_policy": 0.83,
"mmlu_test_accuracy_miscellaneous": 0.7343550446998723,
"mmlu_test_accuracy_prehistory": 0.6512345679012346,
"mmlu_test_accuracy_computer_security": 0.69,
"mmlu_test_accuracy_world_religions": 0.7602339181286549,
"mmlu_test_accuracy": 0.5475190434068002}
License and intended use
This lazy-lora adapter is based on Meta's LLaMA-2-13b-hf, and using the oasst1 dataset, following Guanaco.
lazy lora adapter weights are available under LLAMA-2 license. Note the use of the lazy lora adapter weights, requires access to the LLaMA model weighs. Lazy lora is based on LLaMA and therefore should be used according to the LLaMA license.
Risks and Biases
The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. The model was trained on various public datasets; it is possible that this model could generate lewd, biased, or otherwise offensive outputs.