Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
## Quickstart
|
6 |
+
|
7 |
+
Here is a code snippet for quick use.
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
11 |
+
|
12 |
+
model_name = "newsbang/Homer-7B-v0.1"
|
13 |
+
|
14 |
+
model = AutoModelForCausalLM.from_pretrained(
|
15 |
+
model_name,
|
16 |
+
torch_dtype="auto",
|
17 |
+
device_map="auto"
|
18 |
+
)
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
20 |
+
|
21 |
+
messages = [
|
22 |
+
{"role": "system", "content": "Your name is Homer. You are a very helpful assistant."},
|
23 |
+
{"role": "user", "content": "Hello"}
|
24 |
+
]
|
25 |
+
text = tokenizer.apply_chat_template(
|
26 |
+
messages,
|
27 |
+
tokenize=False,
|
28 |
+
add_generation_prompt=True
|
29 |
+
)
|
30 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
31 |
+
|
32 |
+
generated_ids = model.generate(
|
33 |
+
**model_inputs,
|
34 |
+
max_new_tokens=512
|
35 |
+
)
|
36 |
+
generated_ids = [
|
37 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
38 |
+
]
|
39 |
+
|
40 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
41 |
+
```
|