Khanin Udomchoksakul commited on
Commit
4f59882
·
verified ·
1 Parent(s): 42e38d8

Fix Usage example: use apply_chat_template for instruction-tuned model

Browse files
Files changed (1) hide show
  1. README.md +5 -5
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
- inputs = tokenizer("Hello, how are you?", return_tensors="pt").to("cuda")
90
- model = model.cuda()
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