Update README.md
Browse files
README.md
CHANGED
@@ -21,32 +21,43 @@ What is the meaning of life?<|im_end|>
|
|
21 |
<|im_start|>assistant
|
22 |
```
|
23 |
|
24 |
-
##
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
<|im_start|>assistant
|
22 |
```
|
23 |
|
24 |
+
## Examples
|
25 |
+
|
26 |
+
```python
|
27 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
28 |
+
import torch
|
29 |
+
device = "cuda" # the device to load the model onto
|
30 |
+
|
31 |
+
model = AutoModelForCausalLM.from_pretrained(
|
32 |
+
"vilm/VinaLlama2-14B",
|
33 |
+
torch_dtype='auto',
|
34 |
+
device_map="auto"
|
35 |
+
)
|
36 |
+
tokenizer = AutoTokenizer.from_pretrained("vilm/VinaLlama2-14B")
|
37 |
+
|
38 |
+
prompt = "What is the mearning of life?"
|
39 |
+
messages = [
|
40 |
+
{"role": "system", "content": "You are a helpful AI assistant."},
|
41 |
+
{"role": "user", "content": prompt}
|
42 |
+
]
|
43 |
+
text = tokenizer.apply_chat_template(
|
44 |
+
messages,
|
45 |
+
tokenize=False,
|
46 |
+
add_generation_prompt=True
|
47 |
+
)
|
48 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(device)
|
49 |
+
|
50 |
+
generated_ids = model.generate(
|
51 |
+
model_inputs.input_ids,
|
52 |
+
max_new_tokens=1024,
|
53 |
+
eos_token_id=tokenizer.eos_token_id,
|
54 |
+
temperature=0.25,
|
55 |
+
)
|
56 |
+
generated_ids = [
|
57 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
58 |
+
]
|
59 |
+
|
60 |
+
response = tokenizer.batch_decode(generated_ids)[0]
|
61 |
+
print(response)
|
62 |
+
|
63 |
+
```
|