RuterNorway commited on
Commit
e7322dc
1 Parent(s): 1101a0c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -0
README.md CHANGED
@@ -16,6 +16,8 @@ datasets:
16
  # Llama 2 13b Chat Norwegian LoRA adaptor
17
  **This is the LoRA adaptor for the Llama 2 13b Chat Norwegian model, and requires the original base model to run**
18
 
 
 
19
  Llama-2-13b-chat-norwegian is a variant of [Meta](https://huggingface.co/meta-llama)´s [Llama 2 13b Chat](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf) model, finetuned on a mix of norwegian datasets created in [Ruter AI Lab](https://ruter.no) the summer of 2023.
20
 
21
  The model is tuned to understand and generate text in Norwegian. It's trained for one epoch on norwegian-alpaca + 15000 samples of machine-translated data from OpenOrca (the dataset to be released). A small subset of custom-made instructional data is also included.
@@ -144,4 +146,49 @@ Llama 2 is a new technology that carries risks with use. Testing conducted to da
144
  For these reasons, as with all LLMs, Llama 2’s potential outputs cannot be predicted in advance, and the model may in some instances produce inaccurate, biased or other objectionable responses to user prompts.
145
  Therefore, before deploying any applications of Llama 2, developers should perform safety testing and tuning tailored to their specific applications of the model.
146
  Please see the Responsible Use Guide available at https://ai.meta.com/llama/responsible-use-guide/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  ```
 
16
  # Llama 2 13b Chat Norwegian LoRA adaptor
17
  **This is the LoRA adaptor for the Llama 2 13b Chat Norwegian model, and requires the original base model to run**
18
 
19
+ For a demo inference script, look at the end of this file.
20
+
21
  Llama-2-13b-chat-norwegian is a variant of [Meta](https://huggingface.co/meta-llama)´s [Llama 2 13b Chat](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf) model, finetuned on a mix of norwegian datasets created in [Ruter AI Lab](https://ruter.no) the summer of 2023.
22
 
23
  The model is tuned to understand and generate text in Norwegian. It's trained for one epoch on norwegian-alpaca + 15000 samples of machine-translated data from OpenOrca (the dataset to be released). A small subset of custom-made instructional data is also included.
 
146
  For these reasons, as with all LLMs, Llama 2’s potential outputs cannot be predicted in advance, and the model may in some instances produce inaccurate, biased or other objectionable responses to user prompts.
147
  Therefore, before deploying any applications of Llama 2, developers should perform safety testing and tuning tailored to their specific applications of the model.
148
  Please see the Responsible Use Guide available at https://ai.meta.com/llama/responsible-use-guide/
149
+ ```
150
+
151
+
152
+ # Demo script
153
+ This is a minimal example of how to use the adapter for inference
154
+
155
+ ```python
156
+ import torch
157
+ from peft import PeftModel
158
+ from transformers import LlamaTokenizer, LlamaForCausalLM
159
+
160
+
161
+ MODEL = 'meta-llama/Llama-2-13b-chat-hf'
162
+ ADAPTER = 'RuterNorway/Llama-2-13b-chat-norwegian-LoRa'
163
+ HF_TOKEN = '...'
164
+
165
+
166
+ prompt = """
167
+ ### Instruction
168
+ Hva heter du?
169
+ ### Answer
170
+ """
171
+
172
+
173
+ tokenizer = LlamaTokenizer.from_pretrained(MODEL, legacy=False, use_auth_token=HF_TOKEN)
174
+
175
+ base_model = LlamaForCausalLM.from_pretrained(
176
+ MODEL,
177
+ device_map='auto',
178
+ load_in_8bit=True,
179
+ torch_dtype=torch.float16,
180
+ use_auth_token=HF_TOKEN,
181
+ )
182
+ model = PeftModel.from_pretrained(
183
+ base_model, ADAPTER, torch_dtype=torch.float16, is_trainable=False
184
+ )
185
+
186
+
187
+ with torch.no_grad():
188
+ output_tensors = model.generate(
189
+ input_ids=tokenizer(prompt, return_tensors="pt").input_ids.cuda(),
190
+ max_new_tokens=128
191
+ )[0]
192
+
193
+ tokenizer.decode(output_tensors, skip_special_tokens=True).split('### Answer')[-1]
194
  ```