unsloth icon indicating copy to clipboard operation
unsloth copied to clipboard

Add Phi-3 chat template

Open djannot opened this issue 9 months ago • 5 comments

I'd like to fine tune the new Phi-3 model added yesterday, but it looks like the chat template file hasn't been updated to support it

djannot avatar Apr 30 '24 06:04 djannot

There is now an example for it: https://colab.research.google.com/drive/1NvkBmkHfucGO3Ve9s1NKZvMNlw5p83ym?usp=sharing

molbal avatar Apr 30 '24 17:04 molbal

@molbal this example doesn't show how to use the chat template with the Phi-3 model and the https://github.com/unslothai/unsloth/blob/main/unsloth/chat_templates.py file doesn't include it

djannot avatar Apr 30 '24 17:04 djannot

I don't know that unfortunately.. Maybe its somewhere in here? https://github.com/unslothai/unsloth/pull/397 Or someone on the Discord server could help

molbal avatar Apr 30 '24 18:04 molbal

in my tries it used it thus https://github.com/CrispStrobe/unsloth/blob/main/Phi3_ORPO_Unsloth.ipynb but now you can adapt to the non-llamafied model ofc

CrispStrobe avatar May 01 '24 15:05 CrispStrobe

Oh very good point on the phi-3 template - will add one in

danielhanchen avatar May 01 '24 18:05 danielhanchen

Any update @danielhanchen ?

djannot avatar May 21 '24 18:05 djannot

@djannot Oh sorry! I actually added it in already - sorry guys forgot to update you all!


# Phi-3
phi3_template = \
    "{{ bos_token }}"\
    "{% for message in messages %}"\
        "{{'<|' + message['role'] + '|>\n' + message['content'] + '<|end|>\n'}}"\
    "{% endfor %}"\
    "{% if add_generation_prompt %}"\
        "{{ '<|assistant|>\n' }}"\
    "{% endif %}"
phi3_template_eos_token = "<|end|>"
CHAT_TEMPLATES["phi-3"] = (phi3_template, phi3_template_eos_token,)

Use "phi-3" I might also allow "phi3"

danielhanchen avatar May 21 '24 20:05 danielhanchen

Thanks !

djannot avatar May 21 '24 20:05 djannot

I suppose it also works for Phi3 medium?

molbal avatar May 22 '24 07:05 molbal