Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,37 @@ metrics:
|
|
7 |
- accuracy
|
8 |
library_name: transformers
|
9 |
pipeline_tag: text-generation
|
10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
- accuracy
|
8 |
library_name: transformers
|
9 |
pipeline_tag: text-generation
|
10 |
+
---
|
11 |
+
|
12 |
+
## Inference
|
13 |
+
|
14 |
+
```
|
15 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
16 |
+
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
18 |
+
'Nanbeige/Nanbeige2-8B-Chat',
|
19 |
+
use_fast=False,
|
20 |
+
trust_remote_code=True
|
21 |
+
)
|
22 |
+
model = AutoModelForCausalLM.from_pretrained(
|
23 |
+
'Nanbeige/Nanbeige2-8B-Chat',
|
24 |
+
torch_dtype='auto',
|
25 |
+
device_map='auto',
|
26 |
+
trust_remote_code=True
|
27 |
+
)
|
28 |
+
|
29 |
+
messages = [
|
30 |
+
{'role': 'user', 'content': 'Hello'}
|
31 |
+
]
|
32 |
+
prompt = tokenizer.apply_chat_template(
|
33 |
+
messages,
|
34 |
+
add_generation_prompt=True,
|
35 |
+
tokenize=False
|
36 |
+
)
|
37 |
+
input_ids = tokenizer(prompt, add_special_tokens=False, return_tensors='pt').input_ids
|
38 |
+
output_ids = model.generate(input_ids.to('cuda'))
|
39 |
+
resp = tokenizer.decode(output_ids[0][len(input_ids[0]):], skip_special_tokens=True)
|
40 |
+
|
41 |
+
print(resp)
|
42 |
+
```
|
43 |
+
|