Praise2112 commited on
Commit
2d641c7
1 Parent(s): 482929b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +25 -0
README.md CHANGED
@@ -1,3 +1,28 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+
5
+
6
+ ``` python
7
+ import ctranslate2
8
+ import transformers
9
+ from huggingface_hub import snapshot_download
10
+
11
+ model_dir = snapshot_download(repo_id="Praise2112/Mistral-7B-Instruct-v0.1-int8-ct2")
12
+ generator = ctranslate2.Generator(model_dir, device="cuda", compute_type="int8") # GPU
13
+ # generator = ctranslate2.Generator(model_dir, device="cpu", compute_type="int8") #CPU
14
+ tokenizer = transformers.AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
15
+
16
+ messages = [
17
+ {"role": "user", "content": "What is your favourite condiment?"},
18
+ {"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!"},
19
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
20
+ ]
21
+
22
+ model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt")
23
+ model_inputs = [tokenizer.convert_ids_to_tokens(model_input) for model_input in model_inputs]
24
+ generated_ids = generator.generate_batch(model_inputs, max_length=1000, sampling_topk=10)
25
+ decoded = [res.sequences_ids[0] for res in generated_ids]
26
+ decoded = tokenizer.batch_decode(decoded)
27
+ print(decoded[0])
28
+ ```