georgethrax commited on
Commit
ce40a6e
·
verified ·
1 Parent(s): 8895d92

fix: update Transformers quickstart to be compatible with transformers v5.x

Browse files

apply_chat_template() changed its return_dict default from False (v4) to True (v5), causing AttributeError when passing the result directly to model.generate(). Use explicit return_dict=True with **inputs unpacking to work across both versions.

Files changed (1) hide show
  1. README.md +3 -1
README.md CHANGED
@@ -169,11 +169,13 @@ inputs = tokenizer.apply_chat_template(
169
  tokenize=True,
170
  add_generation_prompt=True,
171
  enable_thinking=False,
 
172
  return_tensors="pt",
173
  ).to(model.device)
174
 
175
  outputs = model.generate(inputs, max_new_tokens=128)
176
- print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))
 
177
  ```
178
 
179
  Recommended chat template sampling:
 
169
  tokenize=True,
170
  add_generation_prompt=True,
171
  enable_thinking=False,
172
+ return_dict=True,
173
  return_tensors="pt",
174
  ).to(model.device)
175
 
176
  outputs = model.generate(inputs, max_new_tokens=128)
177
+ outputs = model.generate(**inputs, max_new_tokens=128)
178
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
179
  ```
180
 
181
  Recommended chat template sampling: