Add demo.py
Browse files
demo.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
model_path = "./"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
+
model_path,
|
| 9 |
+
device_map="auto",
|
| 10 |
+
trust_remote_code=True,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
prompt = "灞变笢鐪佹渶楂樼殑灞辨槸"
|
| 14 |
+
|
| 15 |
+
print("=================== input ===================")
|
| 16 |
+
print(prompt)
|
| 17 |
+
print("=================== output ==================")
|
| 18 |
+
|
| 19 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 20 |
+
outputs = model.generate(
|
| 21 |
+
**inputs,
|
| 22 |
+
max_new_tokens=50,
|
| 23 |
+
)
|
| 24 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 25 |
+
|
| 26 |
+
print(result)
|