Skip to content

[Bug]: jinja2: raise_exception is undefined when a model's chat template tries to reject unsupported input #180

Description

@KLL535

Hello.
I encountered this error when running a model that does not support video in video processing mode; it seems the chat template is trying to notify me of this by triggering something like raise_exception("Video not supported") or similar. However, instead of a clear error message from the template, the entire inference process crashes with the following message, which does not reveal the cause of the crash:

Details

  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama.py", line 4497, in create_chat_completion
    return handler(
        llama=self,
    ...<52 lines>...
        reasoning_start_max_tokens=reasoning_start_max_tokens,
    )
  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama_multimodal.py", line 4354, in __call__
    return super().__call__(**kwargs)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama_multimodal.py", line 1740, in __call__
    full_prompt_ids, chunk_token_spans, chunks, bitmap_cleanup = self._process_mtmd_prompt(
                                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^
        llama=llama,
        ^^^^^^^^^^^^
    ...<5 lines>...
        add_generation_prompt=add_generation_prompt,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama_multimodal.py", line 1518, in _process_mtmd_prompt
    text = self._render_and_replace_media(
        messages=messages,
    ...<5 lines>...
        add_generation_prompt=add_generation_prompt,
    )
  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama_multimodal.py", line 1329, in _render_and_replace_media
    text = self._render_mtmd_prompt(
        messages=messages,
    ...<4 lines>...
        add_generation_prompt=add_generation_prompt,
    )
  File "I:\ComfyUI\python_embeded\Lib\site-packages\llama_cpp\llama_multimodal.py", line 1249, in _render_mtmd_prompt
    return self.chat_template.render(
           ~~~~~~~~~~~~~~~~~~~~~~~~~^
        messages=messages,
        ^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
        **getattr(self, "extra_template_arguments", {}),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\environment.py", line 1295, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 36, in top-level template code
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\sandbox.py", line 401, in call
    return __context.call(__obj, *args, **kwargs)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\runtime.py", line 784, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 1, in template
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\sandbox.py", line 399, in call
    if not __self.is_safe_callable(__obj):
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "I:\ComfyUI\python_embeded\Lib\site-packages\jinja2\sandbox.py", line 265, in is_safe_callable
    getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'raise_exception' is undefined

Thank you for supporting this library.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions