This commit is contained in:
Daniel Han 2025-01-08 14:38:41 -08:00
commit 40a1206e8e
3 changed files with 46 additions and 1 deletions

View file

@ -890,6 +890,46 @@ CHAT_TEMPLATES["qwen2.5"] = (qwen25_template, qwen25_template_eos_token, False,
DEFAULT_SYSTEM_MESSAGE["qwen2.5"] = qwen25_default_system_message # No system message in Qwen 2.5
pass
# =========================================== Phi-4
# "{{ bos_token }}"\ # Phi-4 removes BOS?
phi4_template = \
"{% for message in messages %}"\
"{% if (message['role'] == 'system') %}"\
"{{'<|im_start|>system<|im_sep|>' + message['content'] + '<|im_end|>'}}"\
"{% elif (message['role'] == 'user') %}"\
"{{'<|im_start|>user<|im_sep|>' + message['content'] + '<|im_end|>'}}"\
"{% elif (message['role'] == 'assistant') %}"\
"{{'<|im_start|>assistant<|im_sep|>' + message['content'] + '<|im_end|>'}}"\
"{% endif %}"\
"{% endfor %}"\
"{% if add_generation_prompt %}"\
"{{ '<|im_start|>assistant<|im_sep|>' }}"\
"{% endif %}"
pass
_phi4_ollama_template = \
"{{ if .System }}<|im_start|><|system|><|im_sep|>{{ .System }}<|im_end|>{{ end }}"\
"{{ if .Prompt }}<|im_start|><|user|><|im_sep|>{{ .Prompt }}<|im_end|>{{ end }}"\
"<|im_start|><|assistant|><|im_sep|>{{ .Response }}<|im_end|>"
# Ollama from https://www.ollama.com/library/phi4 is different
phi4_ollama = \
f'''
FROM {{__FILE_LOCATION__}}
TEMPLATE """{_phi4_ollama_template}"""
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_sep|>"
PARAMETER temperature 1.5
PARAMETER min_p 0.1
'''
phi4_template_eos_token = "<|im_end|>"
CHAT_TEMPLATES["phi-4"] = (phi4_template, phi4_template_eos_token, False, phi4_ollama,)
DEFAULT_SYSTEM_MESSAGE["phi-4"] = None # No system message in Phi-4
pass
def _change_system_message(template: str, type_chat_template: str, system_message: str = None):
system_message_pattern = r"\{system_message\}"

View file

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "2025.1.1"
__version__ = "2025.1.2"
__all__ = [
"SUPPORTS_BFLOAT16",

View file

@ -520,6 +520,11 @@ __INT_TO_FLOAT_MAPPER = \
"unsloth/Llama-3.3-70B-Instruct",
"meta-llama/Llama-3.3-70B-Instruct",
),
"unsloth/phi-4-unsloth-bnb-4bit" : (
"unsloth/phi-4",
"microsoft/phi-4",
"unsloth/phi-4-bnb-4bit",
),
}
INT_TO_FLOAT_MAPPER = {}