Khanin Udomchoksakul commited on
Fix Usage example: use apply_chat_template for instruction-tuned model
Browse files
README.md
CHANGED
|
@@ -78,18 +78,18 @@ python -c "import flash_attn; print('flash-attn OK, version:', flash_attn.__vers
|
|
| 78 |
|
| 79 |
## Usage
|
| 80 |
|
| 81 |
-
Use patched Transformers as you would the standard `transformers` library — the CUDA kernels are injected transparently:
|
| 82 |
|
| 83 |
```python
|
| 84 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 85 |
|
| 86 |
-
model = AutoModelForCausalLM.from_pretrained("google/gemma-4-E4B-it")
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 92 |
-
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 93 |
```
|
| 94 |
|
| 95 |
### Serving
|
|
|
|
| 78 |
|
| 79 |
## Usage
|
| 80 |
|
| 81 |
+
Use patched Transformers as you would the standard `transformers` library — the CUDA kernels are injected transparently. This is an instruction-tuned model, so prompts must go through the chat template:
|
| 82 |
|
| 83 |
```python
|
| 84 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 85 |
|
| 86 |
+
model = AutoModelForCausalLM.from_pretrained("google/gemma-4-E4B-it").cuda()
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
|
| 88 |
|
| 89 |
+
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
| 90 |
+
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True).to("cuda")
|
| 91 |
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 92 |
+
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 93 |
```
|
| 94 |
|
| 95 |
### Serving
|