Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when running example script #66

Open
DePasqualeOrg opened this issue Sep 29, 2024 · 4 comments
Open

Errors when running example script #66

DePasqualeOrg opened this issue Sep 29, 2024 · 4 comments

Comments

@DePasqualeOrg
Copy link

When running the example script from the readme, I get the following error:

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

@DePasqualeOrg
Copy link
Author

DePasqualeOrg commented Sep 29, 2024

I was able to resolve this by manually setting the chat template:

llava_1_5_chat_template = '''{% for message in messages %}
  {% if message.role == 'system' %}
    {{ message.content.strip() }}
    {{ '\n' }}

  {% elif message.role == 'user' %}
    {% if message.content is string %}
      USER: {{ message.content.strip() }}

    {% elif message.content is iterable %}
      USER: 
      
      {% for content in message.content %}
        
        {% if content.type == 'image_url' and content.image_url is mapping and content.image_url.url is string%}
          {{ content.image_url.url.strip() + ' ' }}
        {% endif %}

      {% endfor %}

      {% for content in message.content %}

        {% if content.type == 'text' %}
          {{ content.text.strip() }}
        {% endif %}

      {% endfor %}

    {% endif %}

    {{ '\n' }}

  {% elif message.role == 'assistant' and message.content is not none %}
    ASSISTANT: {{ message.content.strip() }}
    {{ '\n' }}
  {% endif %}

{% endfor %}

{% if add_generation_prompt %}
  ASSISTANT: 
{% endif %}'''

model_path = "mlx-community/llava-1.5-7b-4bit"
tokenizer_config = {"chat_template": llava_1_5_chat_template}
model, processor = load(model_path, tokenizer_config)

However, when running generate, I now get the following error, which I suppose will be fixed in #67.

TypeError: Model.__call__() got an unexpected keyword argument 'image_grid_thw'

@DePasqualeOrg DePasqualeOrg changed the title Chat template error when running example script Errors when running example script Sep 29, 2024
@Blaizzy
Copy link
Owner

Blaizzy commented Sep 29, 2024

Hey @DePasqualeOrg

I managed to replicate the issue and will fix it in #67

Yesterday, I accidentally introduced a bug on v0.0.14 and v0.0.15.

@Blaizzy
Copy link
Owner

Blaizzy commented Sep 29, 2024

This template issue is being cause by transformers :(

@Blaizzy
Copy link
Owner

Blaizzy commented Sep 29, 2024

I have to reupload all models again.

They moved the templates to the preprocessor config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants