Update model.py
Browse files
model.py
CHANGED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install -qU transformers accelerate
|
2 |
+
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
import transformers
|
5 |
+
import torch
|
6 |
+
|
7 |
+
model = "SirWumpus/FinMA"
|
8 |
+
messages = [{"role": "user", "content": "What is a large language model?"}]
|
9 |
+
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
11 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
12 |
+
pipeline = transformers.pipeline(
|
13 |
+
"text-generation",
|
14 |
+
model=model,
|
15 |
+
torch_dtype=torch.float16,
|
16 |
+
device_map="auto",
|
17 |
+
)
|
18 |
+
|
19 |
+
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
20 |
+
print(outputs[0]["generated_text"])
|