Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
|
3 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
7 |
+
|
8 |
+
messages = [
|
9 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
10 |
+
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
|
11 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
12 |
+
]
|
13 |
+
|
14 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
15 |
+
|
16 |
+
outputs = model.generate(inputs, max_new_tokens=20)
|
17 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|