Arnav0400 commited on
Commit
a7aa1cd
1 Parent(s): 08243e7

updated readme

Browse files
Files changed (1) hide show
  1. README.md +118 -2
README.md CHANGED
@@ -1,6 +1,122 @@
1
-
2
  # llama-7b-glora 🦙
3
 
4
  This model was built via parameter-efficient GLoRA finetuning of [llama-7b](https://huggingface.co/huggyllama/llama-7b) on the shareGPT dataset. We adapt only the attention layers using GLoRA.
5
 
6
- Model license: This model is under a non-commercial license (see the LICENSE file) same as LLaMA.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # llama-7b-glora 🦙
2
 
3
  This model was built via parameter-efficient GLoRA finetuning of [llama-7b](https://huggingface.co/huggyllama/llama-7b) on the shareGPT dataset. We adapt only the attention layers using GLoRA.
4
 
5
+ * Model license: This model is under a same license (see the LICENSE file) as LLaMA.
6
+ * GLoRA implementation: [script](https://github.com/Arnav0400/peft/blob/main/src/peft/tuners/glora.py)
7
+
8
+ ## Model Description
9
+
10
+ The architecture is similar to LLaMA-7B, but the bias is true for attention layers.
11
+
12
+ ## Limitations and Biases
13
+ _The following language is modified from [EleutherAI's GPT-NeoX-20B](https://huggingface.co/EleutherAI/gpt-neox-20b)_
14
+
15
+ This model can produce factually incorrect output, and should not be relied on to produce factually accurate information.
16
+ This model was trained on various public datasets.
17
+ While great efforts have been taken to clean the pretraining data, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
18
+
19
+ ## How to Use
20
+
21
+ Install and import the package dependencies:
22
+
23
+ ```python
24
+ !pip install -q -U huggingface_hub transformers torch accelerate
25
+ ```
26
+
27
+ ```python
28
+ import torch
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
30
+ ```
31
+
32
+ Basic model loading:
33
+
34
+ ```python
35
+ model = AutoModelForCausalLM.from_pretrained(
36
+ "MBZUAI-LLM/LLaMA-7B-GLoRA-ShareGPT",
37
+ use_auth_token=True,
38
+ torch_dtype=torch.bfloat16,
39
+ device_map="auto",
40
+ )
41
+ tokenizer = AutoTokenizer.from_pretrained("MBZUAI-LLM/LLaMA-7B-GLoRA-ShareGPT")
42
+ ```
43
+
44
+ Once loaded, the model and tokenizer can be used with the following code:
45
+
46
+ ```python
47
+ def llama_generate(
48
+ model: AutoModelForCausalLM,
49
+ tokenizer: AutoTokenizer,
50
+ prompt: str,
51
+ max_new_tokens: int = 128,
52
+ temperature: float = 0.92,
53
+ ) -> str:
54
+ """
55
+ Initialize the pipeline
56
+ Uses Hugging Face GenerationConfig defaults
57
+ https://huggingface.co/docs/transformers/v4.29.1/en/main_classes/text_generation#transformers.GenerationConfig
58
+ Args:
59
+ model (transformers.AutoModelForCausalLM): Model for text generation
60
+ tokenizer (transformers.AutoTokenizer): Tokenizer for model
61
+ prompt (str): Prompt for text generation
62
+ max_new_tokens (int, optional): Max new tokens after the prompt to generate. Defaults to 128.
63
+ temperature (float, optional): The value used to modulate the next token probabilities.
64
+ Defaults to 1.0
65
+ """
66
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
67
+ inputs = tokenizer(
68
+ [prompt],
69
+ return_tensors="pt",
70
+ return_token_type_ids=False,
71
+ ).to(
72
+ device
73
+ ) # tokenize inputs, load on device
74
+ # when running Torch modules in lower precision, it is best practice to use the torch.autocast context manager.
75
+ with torch.autocast("cuda", dtype=torch.bfloat16):
76
+ response = model.generate(
77
+ **inputs,
78
+ max_new_tokens=max_new_tokens,
79
+ temperature=temperature,
80
+ return_dict_in_generate=True,
81
+ eos_token_id=tokenizer.eos_token_id,
82
+ pad_token_id=tokenizer.pad_token_id,
83
+ )
84
+ decoded_output = tokenizer.decode(
85
+ response["sequences"][0],
86
+ skip_special_tokens=True,
87
+ ) # grab output in natural language
88
+ return decoded_output[len(prompt) :] # remove prompt from output
89
+ ```
90
+
91
+ We can now generate text! For example:
92
+
93
+ ```python
94
+ prompt = "You are a helpful assistant. Tell me a recipe for vegan banana bread.\n"
95
+ response = llama_generate(
96
+ model,
97
+ tokenizer,
98
+ prompt,
99
+ max_new_tokens=500,
100
+ temperature=0.92,
101
+ )
102
+ print(response)
103
+ ```
104
+
105
+ ## Disclaimer
106
+
107
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
108
+
109
+ ## Citation for GLoRA
110
+
111
+ ```
112
+ @misc{chavan2023oneforall,
113
+ title={One-for-All: Generalized LoRA for Parameter-Efficient Fine-tuning},
114
+ author={Arnav Chavan and Zhuang Liu and Deepak Gupta and Eric Xing and Zhiqiang Shen},
115
+ year={2023},
116
+ eprint={2306.07967},
117
+ archivePrefix={arXiv},
118
+ primaryClass={cs.LG}
119
+ }
120
+ ```
121
+
122
+ ---