Update README.md
Browse files
README.md
CHANGED
@@ -70,14 +70,19 @@ Trurl 2, same as a Llama 2, is a new technology that carries risks with use. Tes
|
|
70 |
Please see the Meta's Responsible Use Guide available at [https://ai.meta.com/llama/responsible-use-guide/](https://ai.meta.com/llama/responsible-use-guide)
|
71 |
|
72 |
# Example use
|
|
|
|
|
|
|
|
|
|
|
73 |
## LLM
|
74 |
Simply pass a prompt to a model and decode an output. Model will continue writing text based on sample you provided.
|
75 |
```
|
76 |
import torch
|
77 |
-
from transformers import
|
78 |
|
79 |
-
tokenizer =
|
80 |
-
model =
|
81 |
|
82 |
prompt = "Yesterday, when I was"
|
83 |
|
@@ -86,11 +91,13 @@ tokenized_prompt = tokenizer(prompt, return_tensors="pt")
|
|
86 |
model.eval()
|
87 |
with torch.no_grad():
|
88 |
print(tokenizer.decode(
|
89 |
-
model.generate(
|
90 |
skip_special_tokens=True))
|
91 |
```
|
92 |
Generated output:
|
93 |
-
> Yesterday, when I was in the city, I saw a man who was walking
|
|
|
|
|
94 |
|
95 |
## Chat
|
96 |
When using TRURL in a chat mode you should remember to use Llama 2 conversation template like in the example below.
|
@@ -98,10 +105,10 @@ When using TRURL in a chat mode you should remember to use Llama 2 conversation
|
|
98 |
|
99 |
```
|
100 |
import torch
|
101 |
-
from transformers import
|
102 |
|
103 |
-
tokenizer =
|
104 |
-
model =
|
105 |
|
106 |
prompt = """
|
107 |
<s>[INST] <<SYS>> You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.
|
@@ -140,7 +147,7 @@ tokenized_prompt = tokenizer(prompt, return_tensors="pt")
|
|
140 |
model.eval()
|
141 |
with torch.no_grad():
|
142 |
print(tokenizer.decode(
|
143 |
-
model.generate(
|
144 |
skip_special_tokens=True))
|
145 |
```
|
146 |
|
|
|
70 |
Please see the Meta's Responsible Use Guide available at [https://ai.meta.com/llama/responsible-use-guide/](https://ai.meta.com/llama/responsible-use-guide)
|
71 |
|
72 |
# Example use
|
73 |
+
## Installation
|
74 |
+
To use Quantized models you have to have the newest transformers (`pip install transformers --upgrade`), tokenizers (`pip install tokenizers --upgrade`), accelerate and bitsandbytes.
|
75 |
+
|
76 |
+
If your output looks like random letters it means that you probably have wrong library version.
|
77 |
+
|
78 |
## LLM
|
79 |
Simply pass a prompt to a model and decode an output. Model will continue writing text based on sample you provided.
|
80 |
```
|
81 |
import torch
|
82 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
83 |
|
84 |
+
tokenizer = AutoTokenizer.from_pretrained("Voicelab/trurl-2-7b-8bit")
|
85 |
+
model = AutoModelForCausalLM.from_pretrained("Voicelab/trurl-2-7b-8bit", device_map="auto")
|
86 |
|
87 |
prompt = "Yesterday, when I was"
|
88 |
|
|
|
91 |
model.eval()
|
92 |
with torch.no_grad():
|
93 |
print(tokenizer.decode(
|
94 |
+
model.generate(tokenized_prompt.data["input_ids"], max_new_tokens=200, temperature=0)[0],
|
95 |
skip_special_tokens=True))
|
96 |
```
|
97 |
Generated output:
|
98 |
+
> Yesterday, when I was in the city, I saw a man who was walking with a cane. and he was walking with a very slow pace. I felt so sad for him. I wanted to help him, but I didn't know how. I wished I could do something to make him feel better.
|
99 |
+
> Today, I saw the same man again. He was walking with the same slow pace, but this time he was walking with a woman who was supporting him. I felt so happy for him. I realized that he was not alone anymore and that he had someone to support him. I wished I could do the same for him.
|
100 |
+
> I realized that sometimes, all we need is someone to support us. We don't need to be alone. We don't need to be sad. We just need someone to be there for us. And I am grateful that I could be there for him today.
|
101 |
|
102 |
## Chat
|
103 |
When using TRURL in a chat mode you should remember to use Llama 2 conversation template like in the example below.
|
|
|
105 |
|
106 |
```
|
107 |
import torch
|
108 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
109 |
|
110 |
+
tokenizer = AutoTokenizer.from_pretrained("Voicelab/trurl-2-7b-8bit")
|
111 |
+
model = AutoModelForCausalLM.from_pretrained("Voicelab/trurl-2-7b-8bit", device_map="auto")
|
112 |
|
113 |
prompt = """
|
114 |
<s>[INST] <<SYS>> You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.
|
|
|
147 |
model.eval()
|
148 |
with torch.no_grad():
|
149 |
print(tokenizer.decode(
|
150 |
+
model.generate(tokenized_prompt.data["input_ids"], max_new_tokens=200, temperature=0)[0],
|
151 |
skip_special_tokens=True))
|
152 |
```
|
153 |
|