Skip to content

Setting chat_template using tuple raise reference before assignment on Ollama #637

Closed

Description

@Erland366

Hey, I am using custom chat template for all of my projects. Therefore I usually pass tuple to chat_template params on get_chat_template.

With latest commit, there's a conflict on this. In the get_chat_template, if you pass tuple, then it'll unpack 2 values from it (code that I was talking about). But it makes this ollama chat template error because we didn't define it in above. I can't pass 4 values into this because it'll raise an error for unpacking to much values.

I think the solution for now could be defining default value like this for now?

    if type(chat_template) in (list, tuple,):
        # list default value for unpacking
        default_values = ["", "", False, None]

        chat_template, stop_word, yes_map_eos_token, ollama_modelfile = (chat_template + default_values[len(chat_template):])[:4]
        chat_template, stop_word = chat_template
        assert(type(chat_template) is str)
        assert(type(stop_word) is str)

I think my explanation is horrible (sorry bad english), feel free to ask it more btw if you still confused.

Activity

  1. NeedsLoomis commented on Jun 15, 2024

    @NeedsLoomis

    Same issue

    tokenizer = get_chat_template(
        tokenizer,
        chat_template = (custom_template, eos_token),
        mapping = {"role" : "from", "content" : "value", "user" : "human", "assistant" : "gpt"}
        map_eos_token = True,
    )

    Results in

    [/usr/local/lib/python3.10/dist-packages/unsloth/chat_templates.py](https://localhost:8080/#) in get_chat_template(tokenizer, chat_template, mapping, map_eos_token, system_message)
        698 
        699     # Add Ollama
    --> 700     tokenizer._ollama_modelfile = ollama_modelfile
        701     tokenizer._system_message   = system_message
        702     return tokenizer#, stopping_criteria
    
    UnboundLocalError: local variable 'ollama_modelfile' referenced before assignment
    
  2. danielhanchen commented on Jun 15, 2024

    @danielhanchen
    Member

    Oh my whoops! Will fix this asap! Thanks for the heads up!

  3. danielhanchen commented on Jun 15, 2024

    @danielhanchen
    Member

    Just fixed this! (Hopefully!)

  4. added
    fixed - pending confirmation
    and removed
    currently fixing
    on Jun 16, 2024
  5. Erland366 commented on Jun 22, 2024

    @Erland366
    CollaboratorAuthor

    Wait, forgot to respond this. Been tried this for a week ago and it runs fine. Tysm btw as always! will close this :D

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

    fixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions