Update README.md
Browse filesChange the tokenizer in the usage example of README.md to execute using the apply_chat_template method.
README.md
CHANGED
@@ -285,11 +285,11 @@ Where to send questions or comments about the model Instructions on how to provi
|
|
285 |
|
286 |
## How to use
|
287 |
|
288 |
-
This repository for use with
|
289 |
|
290 |
### Use with CTranslate2
|
291 |
|
292 |
-
This example code is obtained from [CTranslate2_transformers](https://opennmt.net/CTranslate2/guides/transformers.html#mpt).
|
293 |
More detailed information about the `generate_batch` methon can be found at [CTranslate2_Generator.generate_batch](https://opennmt.net/CTranslate2/python/ctranslate2.Generator.html#ctranslate2.Generator.generate_batch).
|
294 |
|
295 |
```python
|
@@ -297,14 +297,31 @@ import ctranslate2
|
|
297 |
import transformers
|
298 |
|
299 |
model_id = "avans06/Meta-Llama-3-8B-Instruct-ct2-int8_float16"
|
300 |
-
|
301 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
302 |
|
303 |
-
|
304 |
-
|
|
|
|
|
305 |
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
output = tokenizer.decode(results[0].sequences_ids[0])
|
|
|
|
|
308 |
```
|
309 |
|
310 |
## Hardware and Software
|
|
|
285 |
|
286 |
## How to use
|
287 |
|
288 |
+
This repository for use with [CTranslate2](https://github.com/OpenNMT/CTranslate2).
|
289 |
|
290 |
### Use with CTranslate2
|
291 |
|
292 |
+
This example code is obtained from [CTranslate2_transformers](https://opennmt.net/CTranslate2/guides/transformers.html#mpt) and [tokenizer AutoTokenizer](https://huggingface.co/docs/transformers/main_classes/tokenizer).
|
293 |
More detailed information about the `generate_batch` methon can be found at [CTranslate2_Generator.generate_batch](https://opennmt.net/CTranslate2/python/ctranslate2.Generator.html#ctranslate2.Generator.generate_batch).
|
294 |
|
295 |
```python
|
|
|
297 |
import transformers
|
298 |
|
299 |
model_id = "avans06/Meta-Llama-3-8B-Instruct-ct2-int8_float16"
|
300 |
+
model = ctranslate2.Generator(model_id, device="auto", compute_type="int8_float16")
|
301 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
|
302 |
|
303 |
+
messages = [
|
304 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
305 |
+
{"role": "user", "content": "Who are you?"},
|
306 |
+
]
|
307 |
|
308 |
+
input_ids = tokenizer.apply_chat_template(
|
309 |
+
messages,
|
310 |
+
tokenize=False,
|
311 |
+
add_generation_prompt=True
|
312 |
+
)
|
313 |
+
|
314 |
+
terminators = [
|
315 |
+
tokenizer.eos_token_id,
|
316 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
317 |
+
]
|
318 |
+
|
319 |
+
input_tokens = tokenizer.convert_ids_to_tokens(tokenizer.encode(input_ids))
|
320 |
+
|
321 |
+
results = model.generate_batch([input_tokens], include_prompt_in_result=False, max_length=256, sampling_temperature=0.6, sampling_topp=0.9, end_token=terminators)
|
322 |
output = tokenizer.decode(results[0].sequences_ids[0])
|
323 |
+
|
324 |
+
print(output)
|
325 |
```
|
326 |
|
327 |
## Hardware and Software
|