from transformers import VoxtralForConditionalGeneration, VoxtralProcessor, BitsAndBytesConfig
from huggingface_hub import hf_hub_download
from transformers.audio_utils import load_audio_as
audio_url = "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3"
audio_path = hf_hub_download(repo_id="hf-internal-testing/dummy-audio-samples", filename="bcn_weather.mp3", repo_type="dataset")
audio_base64 = load_audio_as(audio_path, return_format="base64", force_mono=True)
# audio + text
conversation = [
{
"role": "user",
"content": [
{"type": "audio", "url": audio_url},
{"type": "audio", "path": audio_path},
{"type": "audio", "base64": audio_base64},
{"type": "text", "text": "How many audio do you hear?"},
],
},
]
processor = VoxtralProcessor.from_pretrained("mistralai/Voxtral-Mini-3B-2507")
inputs = processor.apply_chat_template(conversation)
***@Z590M-GAMING-X:~/Documents/Code/***/api$ /home/***/Documents/Code/***/api/.venv/bin/python /home/***/Documents/Code/***/api/main.py
bcn_weather.mp3: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 353k/353k [00:01<00:00, 292kB/s]
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
Traceback (most recent call last):
File "/home/***/Documents/Code/***/api/main.py", line 23, in <module>
inputs = processor.apply_chat_template(conversation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/transformers/models/voxtral/processing_voxtral.py", line 175, in apply_chat_template
template_kwargs = _get_template_variables(chat_template)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/transformers/utils/chat_template_utils.py", line 396, in _get_template_variables
compiled = _compile_jinja_template(chat_template)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/transformers/utils/chat_template_utils.py", line 421, in _compile_jinja_template
return _cached_compile_jinja_template(chat_template)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/transformers/utils/chat_template_utils.py", line 495, in _cached_compile_jinja_template
return jinja_env.from_string(chat_template)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 1111, in from_string
return cls.from_code(self, self.compile(source), gs, None)
^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 764, in compile
source = self._generate(source, name, filename, defer_init=defer_init)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/jinja2/environment.py", line 694, in _generate
return generate( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/***/Documents/Code/***/api/.venv/lib/python3.12/site-packages/jinja2/compiler.py", line 112, in generate
raise TypeError("Can't compile non template nodes")
TypeError: Can't compile non template nodes
System Info
transformersversion: 5.4.0Who can help?
@eustlb
Information
Tasks
examplesfolder (such as GLUE/SQuAD, ...)Reproduction
Expected behavior
apply_chat_templateshould applies the model's chat completion template given a conversation without error