mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-08-27 15:41:19 +02:00
16d222fc5e
* llama : support for MiniMax-Text-01 model * chore : renames to match the other MiniMax models * model : add logits mask as MiniMax-Text-01 embeddings tensor has zero-valued embeddings for tokens >= 200032 that produce zero logits disrupting the token sampling process * llama : replace hardcoded conditions with hparams.is_recr() * model : used build_rs() for recurrent state management * chore : code cleanup * model : optimized MiniMax-Text-01 by removing the state tranpose operations * chore : removed unnecessary ggml_cont() in MiniMax-Text-01 implementation * llama : add generic logits mask graph input * model : permuted diag_decay dimensions to avoid doing it inside MiniMax-Text-01 graph * chore : code cleanup * chore : code cleanup * model : use token positions when calculating MiniMax-Text-01 decay tensors * convert : add support for MiniMaxM1ForCausalLM as it seems to be the same as MiniMaxText01ForCausalLM * chat : add jinja template for MiniMax-M1 Co-authored-by: QscQ <qscqesze@gmail.com> * chore : code cleanup * tests : MINIMAX_01-related fixes * chore : silence Python lint errors * vocab : remove unnecessary vocab type * convert : update MiniMaxText01Model conversion to use yield when modifying tensors * convert : suppress tokens with zero-valued embeddings during MiniMax-Text-01 conversion * llama : removed logits mask - no longer necessary as token suppression is used instead * model : use common functions to make MiniMax-Text-01 implementation more concise Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * model : use common functions to make MiniMax-Text-01 implementation more concise Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co> * convert : override non-working built-in chat template during conversion * tests : skip arch MINIMAX_01 tests for WebGPU backend (it breaks again) --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com> Co-authored-by: QscQ <qscqesze@gmail.com> Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
91 lines
3.4 KiB
Django/Jinja
91 lines
3.4 KiB
Django/Jinja
{{ '<begin_of_document>' -}}
|
|
{%- if custom_tools is defined %}
|
|
{%- set tools = custom_tools %}
|
|
{%- endif %}
|
|
{%- if not tools is defined %}
|
|
{%- set tools = none %}
|
|
{%- endif %}
|
|
|
|
{#- Extract system message #}
|
|
{% set ns = namespace(system_prompt='') -%}
|
|
{%- if messages[0]['role'] == 'system' %}
|
|
{%- if messages[0]['content'] is string %}
|
|
{%- set ns.system_prompt = messages[0]['content']|trim %}
|
|
{%- else %}
|
|
{%- set ns.system_prompt = messages[0]['content'][0]['text']|trim %}
|
|
{%- endif %}
|
|
{%- set messages = messages[1:] %}
|
|
{%- else %}
|
|
{%- if tools is not none %}
|
|
{%- set ns.system_prompt = "You are a helpful assistant created by Minimax based on MiniMax-M1 model." %}
|
|
{%- else %}
|
|
{%- set ns.system_prompt = "You are a helpful assistant created by Minimax based on MiniMax-M1 model." %}
|
|
{%- endif %}
|
|
{%- endif %}
|
|
|
|
{#- System message #}
|
|
{%- if ns.system_prompt != '' %}
|
|
{{ '<beginning_of_sentence>system ai_setting=assistant\n' + ns.system_prompt + '<end_of_sentence>\n' -}}
|
|
{%- endif %}
|
|
|
|
{#- Tools configuration #}
|
|
{%- if tools is not none %}
|
|
{{ '<beginning_of_sentence>system tool_setting=tools\nYou are provided with these tools:\n<tools>\n' -}}
|
|
{%- for tool in tools %}
|
|
{{ tool | tojson ~ '\n' -}}
|
|
{%- endfor %}
|
|
{{ '</tools>\n\nIf you need to call tools, please respond with <tool_calls></tool_calls> XML tags, and provide tool-name and json-object of arguments, following the format below:\n<tool_calls>\n{"name": <tool-name>, "arguments": <args-json-object>}\n...\n</tool_calls><end_of_sentence>\n' -}}
|
|
{%- endif %}
|
|
|
|
{#- Process messages #}
|
|
{%- for message in messages %}
|
|
{%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}
|
|
{%- if message['role'] == 'user' %}
|
|
{{ '<beginning_of_sentence>user name=user\n' -}}
|
|
{%- if message['content'] is string %}
|
|
{{ message['content']|trim -}}
|
|
{%- else %}
|
|
{%- for content in message['content'] %}
|
|
{%- if content['type'] == 'text' %}
|
|
{{ content['text']|trim -}}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
{{ '<end_of_sentence>\n' -}}
|
|
{%- elif message['role'] == 'assistant' %}
|
|
{{ '<beginning_of_sentence>ai name=assistant\n' -}}
|
|
{%- if message['content'] is string %}
|
|
{{ message['content']|trim -}}
|
|
{%- else %}
|
|
{%- for content in message['content'] | selectattr('type', 'equalto', 'text') %}
|
|
{{ content['text']|trim -}}
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
{{ '<end_of_sentence>\n' -}}
|
|
{%- endif %}
|
|
{%- elif 'tool_calls' in message %}
|
|
{{ '<beginning_of_sentence>ai name=assistant\n<tool_calls>\n' -}}
|
|
{%- for tool_call in message.tool_calls %}
|
|
{{ '{"name": "' + tool_call.function.name + '", "arguments": ' + tool_call.function.arguments | tojson + '}\n' -}}
|
|
{%- endfor %}
|
|
{{ '</tool_calls><end_of_sentence>\n' -}}
|
|
{%- elif message.role == "tool" or message.role == "ipython" %}
|
|
{{ '<beginning_of_sentence>tool name=tools\n' -}}
|
|
{%- if message.content is string %}
|
|
{{ 'tool result: ' + message.content + '\n\n' -}}
|
|
{%- else %}
|
|
{%- for content in message['content'] %}
|
|
{%- if content['type'] == 'text' %}
|
|
{{ 'tool result: ' + content['text'] + '\n\n' -}}
|
|
{%- elif content.get('name') %}
|
|
{{ 'tool name: ' + content['name'] + '\ntool result: ' + content['text'] + '\n\n' -}}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- endif %}
|
|
{{ '<end_of_sentence>\n' -}}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
|
|
{%- if add_generation_prompt %}
|
|
{{ '<beginning_of_sentence>ai name=assistant\n' -}}
|
|
{%- endif %} |