Skip to content

Instantly share code, notes, and snippets.

@ngxson
Created May 23, 2024 11:51
Show Gist options
  • Save ngxson/38d8d89fb5d856187bcc70e78b1cc4f5 to your computer and use it in GitHub Desktop.
Save ngxson/38d8d89fb5d856187bcc70e78b1cc4f5 to your computer and use it in GitHub Desktop.
phi-3 templates
microsoft/Phi-3-mini-4k-instruct
"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}"
microsoft/Phi-3-mini-128k-instruct
"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}"
microsoft/Phi-3-small-8k-instruct
"{{ bos_token }}{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}"
microsoft/Phi-3-small-128k-instruct
"{{ bos_token }}{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}"
microsoft/Phi-3-medium-4k-instruct
"{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}"
microsoft/Phi-3-medium-128k-instruct
"{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}"
microsoft/Phi-3-vision-128k-instruct
"{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}"
const MODELS = [
'microsoft/Phi-3-mini-4k-instruct',
'microsoft/Phi-3-mini-128k-instruct',
'microsoft/Phi-3-small-8k-instruct',
'microsoft/Phi-3-small-128k-instruct',
'microsoft/Phi-3-medium-4k-instruct',
'microsoft/Phi-3-medium-128k-instruct',
'microsoft/Phi-3-vision-128k-instruct',
];
(async () => {
for (const m of MODELS) {
const res = await fetch(`https://huggingface.co/${m}/raw/main/tokenizer_config.json`);
const json = await res.json();
console.log(m);
console.log(JSON.stringify(json.chat_template));
console.log();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment