Olivier-Truong commited on
Commit
0e0f51b
·
verified ·
1 Parent(s): 20b296d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,10 +1,21 @@
1
- from transformers import AutoModelForCausalLM
2
-
 
 
3
  model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
4
- model.to("cpu")
5
-
6
- generated_ids = model.generate(tokens, max_new_tokens=1000, do_sample=True)
 
 
 
 
 
 
 
 
 
7
 
8
- # decode with mistral tokenizer
9
- result = tokenizer.decode(generated_ids[0].tolist())
10
- print(result)
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+
3
+ device = "cpu" # the device to load the model onto
4
+
5
  model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
6
+ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
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
+ encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
15
+
16
+ model_inputs = encodeds.to(device)
17
+ model.to(device)
18
 
19
+ generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
20
+ decoded = tokenizer.batch_decode(generated_ids)
21
+ print(decoded[0])