Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
# For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
|
3 |
+
# Doc / guide: https://huggingface.co/docs/hub/model-cards
|
4 |
+
{}
|
5 |
+
---
|
6 |
+
|
7 |
+
## Usage
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
11 |
+
import torch
|
12 |
+
|
13 |
+
model_id = 'datapaf/fvt_ift_rus'
|
14 |
+
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(
|
17 |
+
model_id,
|
18 |
+
torch_dtype=torch.bfloat16,
|
19 |
+
device_map='auto'
|
20 |
+
)
|
21 |
+
|
22 |
+
chat = [
|
23 |
+
{"role": "system", "content": "Ты AI-помощник, ответь на вопрос"},
|
24 |
+
{"role": "user", "content": "Привет! Как дела?"},
|
25 |
+
]
|
26 |
+
|
27 |
+
templated = tokenizer.apply_chat_template(chat, tokenize=False)
|
28 |
+
encoded = tokenizer(templated, return_tensors="pt",add_special_tokens=True)
|
29 |
+
inputs = {key: tensor.to(model.device) for key, tensor in encoded.items()}
|
30 |
+
|
31 |
+
output = model.generate(
|
32 |
+
**inputs,
|
33 |
+
max_new_tokens=1024,
|
34 |
+
do_sample=False,
|
35 |
+
repetition_penalty=1.2
|
36 |
+
)
|
37 |
+
|
38 |
+
decoded_output = tokenizer.decode(
|
39 |
+
output[0][inputs['input_ids'].size(1)+2:],
|
40 |
+
skip_special_tokens=True
|
41 |
+
)
|
42 |
+
|
43 |
+
print(decoded_output)
|
44 |
+
```
|