divyamakkar0
commited on
Commit
·
ac31e85
1
Parent(s):
069a19d
add handler
Browse files- handler.py +27 -0
handler.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import os.path as op
|
4 |
+
|
5 |
+
output_dir = "./checkpoint-2"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(output_dir)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(output_dir, device_map="auto")
|
9 |
+
|
10 |
+
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
|
11 |
+
# messages = [
|
12 |
+
# {"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
|
13 |
+
# ]
|
14 |
+
|
15 |
+
# prepare the messages for the model
|
16 |
+
# input_ids = tokenizer.apply_chat_template(messages, truncation=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
|
17 |
+
|
18 |
+
# inference
|
19 |
+
# outputs = model.generate(
|
20 |
+
# input_ids=input_ids,
|
21 |
+
# max_new_tokens=256,
|
22 |
+
# do_sample=True,
|
23 |
+
# temperature=0.7,
|
24 |
+
# top_k=50,
|
25 |
+
# top_p=0.95
|
26 |
+
# )
|
27 |
+
# print(tokenizer.batch_decode(outputs, skip_special_tokens=True)[0])
|