code_execution_files / PleIAs_Baguettotron_1.txt
ariG23498's picture
ariG23498 HF Staff
Upload PleIAs_Baguettotron_1.txt with huggingface_hub
4545440 verified
raw
history blame
1.65 kB
```CODE:
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("PleIAs/Baguettotron")
model = AutoModelForCausalLM.from_pretrained("PleIAs/Baguettotron")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
```
ERROR:
Traceback (most recent call last):
File "/tmp/PleIAs_Baguettotron_1a3U371.py", line 31, in <module>
inputs = tokenizer.apply_chat_template(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
messages,
^^^^^^^^^
...<3 lines>...
return_tensors="pt",
^^^^^^^^^^^^^^^^^^^^
).to(model.device)
^
File "/tmp/.cache/uv/environments-v2/764d8b6eaf4a560a/lib/python3.13/site-packages/transformers/tokenization_utils_base.py", line 1647, in apply_chat_template
chat_template = self.get_chat_template(chat_template, tools)
File "/tmp/.cache/uv/environments-v2/764d8b6eaf4a560a/lib/python3.13/site-packages/transformers/tokenization_utils_base.py", line 1825, in get_chat_template
raise ValueError(
...<4 lines>...
)
ValueError: Cannot use chat template functions because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating