File size: 1,631 Bytes
c3cce76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e52654f
c3cce76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
```CODE: 
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("PleIAs/Monad")
model = AutoModelForCausalLM.from_pretrained("PleIAs/Monad")
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_Monad_1hG6LEH.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/b8e73a8c87ba95e6/lib/python3.13/site-packages/transformers/tokenization_utils_base.py", line 1646, in apply_chat_template
    chat_template = self.get_chat_template(chat_template, tools)
  File "/tmp/.cache/uv/environments-v2/b8e73a8c87ba95e6/lib/python3.13/site-packages/transformers/tokenization_utils_base.py", line 1824, 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