Alexandru Gherghescu commited on
Commit ·
17be2cb
1
Parent(s): 5314a57
Add inference example
Browse files- inference.py +24 -0
inference.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig, TextStreamer
|
| 3 |
+
|
| 4 |
+
device = 'cuda'
|
| 5 |
+
prompt = "Mihai Eminescu a fost "
|
| 6 |
+
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained('faur-ai/llmamba', trust_remote_code=True, torch_dtype=torch.bfloat16).to(device)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained('faur-ai/llmamba', trust_remote_code=True)
|
| 9 |
+
|
| 10 |
+
streamer = TextStreamer(tokenizer)
|
| 11 |
+
|
| 12 |
+
inputs = tokenizer.encode(
|
| 13 |
+
prompt,
|
| 14 |
+
add_special_tokens=False,
|
| 15 |
+
return_tensors='pt',
|
| 16 |
+
).to(device)
|
| 17 |
+
|
| 18 |
+
outputs = model.generate(
|
| 19 |
+
streamer=streamer,
|
| 20 |
+
input_ids=inputs,
|
| 21 |
+
temperature=0.8,
|
| 22 |
+
do_sample=True,
|
| 23 |
+
max_new_tokens=100,
|
| 24 |
+
)
|