Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- chat_template.jinja +337 -0
- config.json +82 -0
- example_cli.py +18 -0
- generation_config.json +6 -0
- llmjp4_reasoning_parser.py +152 -0
- llmjp4_tokenizer.py +75 -0
- model.safetensors +3 -0
- recipe.yaml +7 -0
- special_tokens_map.json +51 -0
- tokenizer.json +3 -0
- tokenizer_config.json +9 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{#-
|
| 2 |
+
In addition to the normal inputs of `messages` and `tools`, this template also accepts the
|
| 3 |
+
following kwargs:
|
| 4 |
+
- "builtin_tools": A list, can contain "browser" and/or "python".
|
| 5 |
+
- "model_identity": A string that optionally describes the model identity.
|
| 6 |
+
- "reasoning_effort": A string that describes the reasoning effort, defaults to "medium".
|
| 7 |
+
#}
|
| 8 |
+
|
| 9 |
+
{#- Tool Definition Rendering ============================================== #}
|
| 10 |
+
{%- macro render_typescript_type(param_spec, required_params, is_nullable=false) -%}
|
| 11 |
+
{%- if param_spec.type == "array" -%}
|
| 12 |
+
{%- if param_spec['items'] -%}
|
| 13 |
+
{%- if param_spec['items']['type'] == "string" -%}
|
| 14 |
+
{{- "string[]" }}
|
| 15 |
+
{%- elif param_spec['items']['type'] == "number" -%}
|
| 16 |
+
{{- "number[]" }}
|
| 17 |
+
{%- elif param_spec['items']['type'] == "integer" -%}
|
| 18 |
+
{{- "number[]" }}
|
| 19 |
+
{%- elif param_spec['items']['type'] == "boolean" -%}
|
| 20 |
+
{{- "boolean[]" }}
|
| 21 |
+
{%- else -%}
|
| 22 |
+
{%- set inner_type = render_typescript_type(param_spec['items'], required_params) -%}
|
| 23 |
+
{%- if inner_type == "object | object" or inner_type|length > 50 -%}
|
| 24 |
+
{{- "any[]" }}
|
| 25 |
+
{%- else -%}
|
| 26 |
+
{{- inner_type + "[]" }}
|
| 27 |
+
{%- endif -%}
|
| 28 |
+
{%- endif -%}
|
| 29 |
+
{%- if param_spec.nullable -%}
|
| 30 |
+
{{- " | null" }}
|
| 31 |
+
{%- endif -%}
|
| 32 |
+
{%- else -%}
|
| 33 |
+
{{- "any[]" }}
|
| 34 |
+
{%- if param_spec.nullable -%}
|
| 35 |
+
{{- " | null" }}
|
| 36 |
+
{%- endif -%}
|
| 37 |
+
{%- endif -%}
|
| 38 |
+
{%- elif param_spec.type is defined and param_spec.type is iterable and param_spec.type is not string and param_spec.type is not mapping and param_spec.type[0] is defined -%}
|
| 39 |
+
{#- Handle array of types like ["object", "object"] from Union[dict, list] #}
|
| 40 |
+
{%- if param_spec.type | length > 1 -%}
|
| 41 |
+
{{- param_spec.type | join(" | ") }}
|
| 42 |
+
{%- else -%}
|
| 43 |
+
{{- param_spec.type[0] }}
|
| 44 |
+
{%- endif -%}
|
| 45 |
+
{%- elif param_spec.oneOf -%}
|
| 46 |
+
{#- Handle oneOf schemas - check for complex unions and fallback to any #}
|
| 47 |
+
{%- set has_object_variants = false -%}
|
| 48 |
+
{%- for variant in param_spec.oneOf -%}
|
| 49 |
+
{%- if variant.type == "object" -%}
|
| 50 |
+
{%- set has_object_variants = true -%}
|
| 51 |
+
{%- endif -%}
|
| 52 |
+
{%- endfor -%}
|
| 53 |
+
{%- if has_object_variants and param_spec.oneOf|length > 1 -%}
|
| 54 |
+
{{- "any" }}
|
| 55 |
+
{%- else -%}
|
| 56 |
+
{%- for variant in param_spec.oneOf -%}
|
| 57 |
+
{{- render_typescript_type(variant, required_params) -}}
|
| 58 |
+
{%- if variant.description %}
|
| 59 |
+
{{- "// " + variant.description }}
|
| 60 |
+
{%- endif -%}
|
| 61 |
+
{%- if variant.default is defined %}
|
| 62 |
+
{{ "// default: " + variant.default|tojson }}
|
| 63 |
+
{%- endif -%}
|
| 64 |
+
{%- if not loop.last %}
|
| 65 |
+
{{- " | " }}
|
| 66 |
+
{% endif -%}
|
| 67 |
+
{%- endfor -%}
|
| 68 |
+
{%- endif -%}
|
| 69 |
+
{%- elif param_spec.type == "string" -%}
|
| 70 |
+
{%- if param_spec.enum -%}
|
| 71 |
+
{{- '"' + param_spec.enum|join('" | "') + '"' -}}
|
| 72 |
+
{%- else -%}
|
| 73 |
+
{{- "string" }}
|
| 74 |
+
{%- if param_spec.nullable %}
|
| 75 |
+
{{- " | null" }}
|
| 76 |
+
{%- endif -%}
|
| 77 |
+
{%- endif -%}
|
| 78 |
+
{%- elif param_spec.type == "number" -%}
|
| 79 |
+
{{- "number" }}
|
| 80 |
+
{%- elif param_spec.type == "integer" -%}
|
| 81 |
+
{{- "number" }}
|
| 82 |
+
{%- elif param_spec.type == "boolean" -%}
|
| 83 |
+
{{- "boolean" }}
|
| 84 |
+
|
| 85 |
+
{%- elif param_spec.type == "object" -%}
|
| 86 |
+
{%- if param_spec.properties -%}
|
| 87 |
+
{{- "{\n" }}
|
| 88 |
+
{%- for prop_name, prop_spec in param_spec.properties.items() -%}
|
| 89 |
+
{{- prop_name -}}
|
| 90 |
+
{%- if prop_name not in (param_spec.required or []) -%}
|
| 91 |
+
{{- "?" }}
|
| 92 |
+
{%- endif -%}
|
| 93 |
+
{{- ": " }}
|
| 94 |
+
{{ render_typescript_type(prop_spec, param_spec.required or []) }}
|
| 95 |
+
{%- if not loop.last -%}
|
| 96 |
+
{{-", " }}
|
| 97 |
+
{%- endif -%}
|
| 98 |
+
{%- endfor -%}
|
| 99 |
+
{{- "}" }}
|
| 100 |
+
{%- else -%}
|
| 101 |
+
{{- "object" }}
|
| 102 |
+
{%- endif -%}
|
| 103 |
+
{%- else -%}
|
| 104 |
+
{{- "any" }}
|
| 105 |
+
{%- endif -%}
|
| 106 |
+
{%- endmacro -%}
|
| 107 |
+
|
| 108 |
+
{%- macro render_tool_namespace(namespace_name, tools) -%}
|
| 109 |
+
{{- "## " + namespace_name + "\n\n" }}
|
| 110 |
+
{{- "namespace " + namespace_name + " {\n\n" }}
|
| 111 |
+
{%- for tool in tools %}
|
| 112 |
+
{%- set tool = tool.function %}
|
| 113 |
+
{{- "// " + tool.description + "\n" }}
|
| 114 |
+
{{- "type "+ tool.name + " = " }}
|
| 115 |
+
{%- if tool.parameters and tool.parameters.properties %}
|
| 116 |
+
{{- "(_: {\n" }}
|
| 117 |
+
{%- for param_name, param_spec in tool.parameters.properties.items() %}
|
| 118 |
+
{%- if param_spec.description %}
|
| 119 |
+
{{- "// " + param_spec.description + "\n" }}
|
| 120 |
+
{%- endif %}
|
| 121 |
+
{{- param_name }}
|
| 122 |
+
{%- if param_name not in (tool.parameters.required or []) -%}
|
| 123 |
+
{{- "?" }}
|
| 124 |
+
{%- endif -%}
|
| 125 |
+
{{- ": " }}
|
| 126 |
+
{{- render_typescript_type(param_spec, tool.parameters.required or []) }}
|
| 127 |
+
{%- if param_spec.default is defined -%}
|
| 128 |
+
{%- if param_spec.enum %}
|
| 129 |
+
{{- ", // default: " + param_spec.default }}
|
| 130 |
+
{%- elif param_spec.oneOf %}
|
| 131 |
+
{{- "// default: " + param_spec.default }}
|
| 132 |
+
{%- else %}
|
| 133 |
+
{{- ", // default: " + param_spec.default|tojson }}
|
| 134 |
+
{%- endif -%}
|
| 135 |
+
{%- endif -%}
|
| 136 |
+
{%- if not loop.last %}
|
| 137 |
+
{{- ",\n" }}
|
| 138 |
+
{%- else %}
|
| 139 |
+
{{- ",\n" }}
|
| 140 |
+
{%- endif -%}
|
| 141 |
+
{%- endfor %}
|
| 142 |
+
{{- "}) => any;\n\n" }}
|
| 143 |
+
{%- else -%}
|
| 144 |
+
{{- "() => any;\n\n" }}
|
| 145 |
+
{%- endif -%}
|
| 146 |
+
{%- endfor %}
|
| 147 |
+
{{- "} // namespace " + namespace_name }}
|
| 148 |
+
{%- endmacro -%}
|
| 149 |
+
|
| 150 |
+
{%- macro render_builtin_tools(browser_tool, python_tool) -%}
|
| 151 |
+
{%- if browser_tool %}
|
| 152 |
+
{{- "## browser\n\n" }}
|
| 153 |
+
{{- "// Tool for browsing.\n" }}
|
| 154 |
+
{{- "// The `cursor` appears in brackets before each browsing display: `[{cursor}]`.\n" }}
|
| 155 |
+
{{- "// Cite information from the tool using the following format:\n" }}
|
| 156 |
+
{{- "// `【{cursor}†L{line_start}(-L{line_end})?】`, for example: `【6†L9-L11】` or `【8†L3】`.\n" }}
|
| 157 |
+
{{- "// Do not quote more than 10 words directly from the tool output.\n" }}
|
| 158 |
+
{{- "// sources=web (default: web)\n" }}
|
| 159 |
+
{{- "namespace browser {\n\n" }}
|
| 160 |
+
{{- "// Searches for information related to `query` and displays `topn` results.\n" }}
|
| 161 |
+
{{- "type search = (_: {\n" }}
|
| 162 |
+
{{- "query: string,\n" }}
|
| 163 |
+
{{- "topn?: number, // default: 10\n" }}
|
| 164 |
+
{{- "source?: string,\n" }}
|
| 165 |
+
{{- "}) => any;\n\n" }}
|
| 166 |
+
{{- "// Opens the link `id` from the page indicated by `cursor` starting at line number `loc`, showing `num_lines` lines.\n" }}
|
| 167 |
+
{{- "// Valid link ids are displayed with the formatting: `【{id}†.*】`.\n" }}
|
| 168 |
+
{{- "// If `cursor` is not provided, the most recent page is implied.\n" }}
|
| 169 |
+
{{- "// If `id` is a string, it is treated as a fully qualified URL associated with `source`.\n" }}
|
| 170 |
+
{{- "// If `loc` is not provided, the viewport will be positioned at the beginning of the document or centered on the most relevant passage, if available.\n" }}
|
| 171 |
+
{{- "// Use this function without `id` to scroll to a new location of an opened page.\n" }}
|
| 172 |
+
{{- "type open = (_: {\n" }}
|
| 173 |
+
{{- "id?: number | string, // default: -1\n" }}
|
| 174 |
+
{{- "cursor?: number, // default: -1\n" }}
|
| 175 |
+
{{- "loc?: number, // default: -1\n" }}
|
| 176 |
+
{{- "num_lines?: number, // default: -1\n" }}
|
| 177 |
+
{{- "view_source?: boolean, // default: false\n" }}
|
| 178 |
+
{{- "source?: string,\n" }}
|
| 179 |
+
{{- "}) => any;\n\n" }}
|
| 180 |
+
{{- "// Finds exact matches of `pattern` in the current page, or the page given by `cursor`.\n" }}
|
| 181 |
+
{{- "type find = (_: {\n" }}
|
| 182 |
+
{{- "pattern: string,\n" }}
|
| 183 |
+
{{- "cursor?: number, // default: -1\n" }}
|
| 184 |
+
{{- "}) => any;\n\n" }}
|
| 185 |
+
{{- "} // namespace browser\n\n" }}
|
| 186 |
+
{%- endif -%}
|
| 187 |
+
|
| 188 |
+
{%- if python_tool %}
|
| 189 |
+
{{- "## python\n\n" }}
|
| 190 |
+
{{- "Use this tool to execute Python code in your chain of thought. The code will not be shown to the user. This tool should be used for internal reasoning, but not for code that is intended to be visible to the user (e.g. when creating plots, tables, or files).\n\n" }}
|
| 191 |
+
{{- "When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 120.0 seconds. The drive at '/mnt/data' can be used to save and persist user files. Internet access for this session is UNKNOWN. Depends on the cluster.\n\n" }}
|
| 192 |
+
{%- endif -%}
|
| 193 |
+
{%- endmacro -%}
|
| 194 |
+
|
| 195 |
+
{#- System Message Construction ============================================ #}
|
| 196 |
+
{%- macro build_system_message() -%}
|
| 197 |
+
{%- if model_identity is not defined %}
|
| 198 |
+
{%- set model_identity = "You are LLM-jp-4, a large language model trained by LLM-jp." %}
|
| 199 |
+
{%- endif %}
|
| 200 |
+
{{- model_identity + "\n" -}}
|
| 201 |
+
{% if knowledge_cutoff is not defined %}
|
| 202 |
+
{%- set knowledge_cutoff = "2025-12" %}
|
| 203 |
+
{%- endif %}
|
| 204 |
+
{{- "Knowledge cutoff: " + knowledge_cutoff + "\n" -}}
|
| 205 |
+
{% if conversation_start_date is not defined %}
|
| 206 |
+
{%- set conversation_start_date = strftime_now("%Y-%m-%d") %}
|
| 207 |
+
{%- endif %}
|
| 208 |
+
{{- "Current date: " + conversation_start_date + "\n\n" }}
|
| 209 |
+
{%- if reasoning_effort is not defined %}
|
| 210 |
+
{%- set reasoning_effort = "medium" %}
|
| 211 |
+
{%- endif %}
|
| 212 |
+
{{- "Reasoning: " + reasoning_effort + "\n\n" }}
|
| 213 |
+
{%- if builtin_tools %}
|
| 214 |
+
{{- "# Tools\n\n" }}
|
| 215 |
+
{%- set available_builtin_tools = namespace(browser=false, python=false) %}
|
| 216 |
+
{%- for tool in builtin_tools %}
|
| 217 |
+
{%- if tool == "browser" %}
|
| 218 |
+
{%- set available_builtin_tools.browser = true %}
|
| 219 |
+
{%- elif tool == "python" %}
|
| 220 |
+
{%- set available_builtin_tools.python = true %}
|
| 221 |
+
{%- endif %}
|
| 222 |
+
{%- endfor %}
|
| 223 |
+
{{- render_builtin_tools(available_builtin_tools.browser, available_builtin_tools.python) }}
|
| 224 |
+
{%- endif -%}
|
| 225 |
+
{{- "# Valid channels: analysis, commentary, final. Channel must be included for every message." }}
|
| 226 |
+
{%- if tools -%}
|
| 227 |
+
{{- "\nCalls to these tools must go to the commentary channel: 'functions'." }}
|
| 228 |
+
{%- endif -%}
|
| 229 |
+
{%- endmacro -%}
|
| 230 |
+
|
| 231 |
+
{#- Main Template Logic ================================================= #}
|
| 232 |
+
{#- Set defaults #}
|
| 233 |
+
|
| 234 |
+
{#- Render system message #}
|
| 235 |
+
{{- "<|start|>system<|message|>" }}
|
| 236 |
+
{{- build_system_message() }}
|
| 237 |
+
{{- "<|end|>" }}
|
| 238 |
+
|
| 239 |
+
{#- Extract developer message #}
|
| 240 |
+
{%- if messages[0].role == "developer" or messages[0].role == "system" %}
|
| 241 |
+
{%- set developer_message = messages[0].content %}
|
| 242 |
+
{%- set loop_messages = messages[1:] %}
|
| 243 |
+
{%- else %}
|
| 244 |
+
{%- set developer_message = "" %}
|
| 245 |
+
{%- set loop_messages = messages %}
|
| 246 |
+
{%- endif %}
|
| 247 |
+
|
| 248 |
+
{#- Render developer message #}
|
| 249 |
+
{%- if developer_message or tools %}
|
| 250 |
+
{{- "<|start|>developer<|message|>" }}
|
| 251 |
+
{%- if developer_message %}
|
| 252 |
+
{{- "# Instructions\n\n" }}
|
| 253 |
+
{{- developer_message }}
|
| 254 |
+
{{- "\n\n" }}
|
| 255 |
+
{%- endif %}
|
| 256 |
+
{%- if tools -%}
|
| 257 |
+
{{- "# Tools\n\n" }}
|
| 258 |
+
{{- render_tool_namespace("functions", tools) }}
|
| 259 |
+
{%- endif -%}
|
| 260 |
+
{{- "<|end|>" }}
|
| 261 |
+
{%- endif %}
|
| 262 |
+
|
| 263 |
+
{#- Render messages #}
|
| 264 |
+
{%- set last_tool_call = namespace(name=none) %}
|
| 265 |
+
{%- for message in loop_messages -%}
|
| 266 |
+
{#- At this point only assistant/user/tool messages should remain #}
|
| 267 |
+
{%- if message.role == 'assistant' -%}
|
| 268 |
+
{#- Checks to ensure the messages are being passed in the format we expect #}
|
| 269 |
+
{%- if "content" in message %}
|
| 270 |
+
{%- if "<|channel|>analysis<|message|>" in message.content or "<|channel|>final<|message|>" in message.content %}
|
| 271 |
+
{{- raise_exception("You have passed a message containing <|channel|> tags in the content field. Instead of doing this, you should pass analysis messages (the string between '<|message|>' and '<|end|>') in the 'thinking' field, and final messages (the string between '<|message|>' and '<|end|>') in the 'content' field.") }}
|
| 272 |
+
{%- endif %}
|
| 273 |
+
{%- endif %}
|
| 274 |
+
{%- if "thinking" in message %}
|
| 275 |
+
{%- if "<|channel|>analysis<|message|>" in message.thinking or "<|channel|>final<|message|>" in message.thinking %}
|
| 276 |
+
{{- raise_exception("You have passed a message containing <|channel|> tags in the thinking field. Instead of doing this, you should pass analysis messages (the string between '<|message|>' and '<|end|>') in the 'thinking' field, and final messages (the string between '<|message|>' and '<|end|>') in the 'content' field.") }}
|
| 277 |
+
{%- endif %}
|
| 278 |
+
{%- endif %}
|
| 279 |
+
{%- if "tool_calls" in message %}
|
| 280 |
+
{#- We need very careful handling here - we want to drop the tool call analysis message if the model #}
|
| 281 |
+
{#- has output a later <|final|> message, but otherwise we want to retain it. This is the only case #}
|
| 282 |
+
{#- when we render CoT/analysis messages in inference. #}
|
| 283 |
+
{%- set future_final_message = namespace(found=false) %}
|
| 284 |
+
{%- for future_message in loop_messages[loop.index:] %}
|
| 285 |
+
{%- if future_message.role == 'assistant' and "tool_calls" not in future_message %}
|
| 286 |
+
{%- set future_final_message.found = true %}
|
| 287 |
+
{%- endif %}
|
| 288 |
+
{%- endfor %}
|
| 289 |
+
{#- We assume max 1 tool call per message, and so we infer the tool call name #}
|
| 290 |
+
{#- in "tool" messages from the most recent assistant tool call name #}
|
| 291 |
+
{%- set tool_call = message.tool_calls[0] %}
|
| 292 |
+
{%- if tool_call.function %}
|
| 293 |
+
{%- set tool_call = tool_call.function %}
|
| 294 |
+
{%- endif %}
|
| 295 |
+
{%- if message.content and message.thinking %}
|
| 296 |
+
{{- raise_exception("Cannot pass both content and thinking in an assistant message with tool calls! Put the analysis message in one or the other, but not both.") }}
|
| 297 |
+
{%- elif message.content and not future_final_message.found %}
|
| 298 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.content + "<|end|>" }}
|
| 299 |
+
{%- elif message.thinking and not future_final_message.found %}
|
| 300 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
|
| 301 |
+
{%- endif %}
|
| 302 |
+
{{- "<|start|>assistant to=" }}
|
| 303 |
+
{{- "functions." + tool_call.name + "<|channel|>commentary " }}
|
| 304 |
+
{{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
|
| 305 |
+
{{- tool_call.arguments|tojson }}
|
| 306 |
+
{{- "<|call|>" }}
|
| 307 |
+
{%- set last_tool_call.name = tool_call.name %}
|
| 308 |
+
{%- elif loop.last and not add_generation_prompt %}
|
| 309 |
+
{#- Only render the CoT if the final turn is an assistant turn and add_generation_prompt is false #}
|
| 310 |
+
{#- This is a situation that should only occur in training, never in inference. #}
|
| 311 |
+
{%- if "thinking" in message %}
|
| 312 |
+
{{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }}
|
| 313 |
+
{%- endif %}
|
| 314 |
+
{#- <|return|> indicates the end of generation, but <|end|> does not #}
|
| 315 |
+
{#- <|return|> should never be an input to the model, but we include it as the final token #}
|
| 316 |
+
{#- when training, so the model learns to emit it. #}
|
| 317 |
+
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|return|>" }}
|
| 318 |
+
{%- else %}
|
| 319 |
+
{#- CoT is dropped during all previous turns, so we never render it for inference #}
|
| 320 |
+
{{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }}
|
| 321 |
+
{%- set last_tool_call.name = none %}
|
| 322 |
+
{%- endif %}
|
| 323 |
+
{%- elif message.role == 'tool' -%}
|
| 324 |
+
{%- if last_tool_call.name is none %}
|
| 325 |
+
{{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
|
| 326 |
+
{%- endif %}
|
| 327 |
+
{{- "<|start|>functions." + last_tool_call.name }}
|
| 328 |
+
{{- " to=assistant<|channel|>commentary<|message|>" + message.content|tojson + "<|end|>" }}
|
| 329 |
+
{%- elif message.role == 'user' -%}
|
| 330 |
+
{{- "<|start|>user<|message|>" + message.content + "<|end|>" }}
|
| 331 |
+
{%- endif -%}
|
| 332 |
+
{%- endfor -%}
|
| 333 |
+
|
| 334 |
+
{#- Generation prompt #}
|
| 335 |
+
{%- if add_generation_prompt -%}
|
| 336 |
+
<|start|>assistant
|
| 337 |
+
{%- endif -%}
|
config.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LlamaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 1,
|
| 8 |
+
"dtype": "bfloat16",
|
| 9 |
+
"eos_token_id": 2,
|
| 10 |
+
"head_dim": 128,
|
| 11 |
+
"hidden_act": "silu",
|
| 12 |
+
"hidden_size": 5120,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 27648,
|
| 15 |
+
"max_position_embeddings": 65536,
|
| 16 |
+
"mlp_bias": false,
|
| 17 |
+
"model_type": "llama",
|
| 18 |
+
"num_attention_heads": 40,
|
| 19 |
+
"num_hidden_layers": 64,
|
| 20 |
+
"num_key_value_heads": 8,
|
| 21 |
+
"pad_token_id": null,
|
| 22 |
+
"pretraining_tp": 1,
|
| 23 |
+
"quantization_config": {
|
| 24 |
+
"config_groups": {
|
| 25 |
+
"group_0": {
|
| 26 |
+
"format": "nvfp4-pack-quantized",
|
| 27 |
+
"input_activations": {
|
| 28 |
+
"actorder": null,
|
| 29 |
+
"block_structure": null,
|
| 30 |
+
"dynamic": "local",
|
| 31 |
+
"group_size": 16,
|
| 32 |
+
"num_bits": 4,
|
| 33 |
+
"observer": "static_minmax",
|
| 34 |
+
"observer_kwargs": {},
|
| 35 |
+
"scale_dtype": "torch.float8_e4m3fn",
|
| 36 |
+
"strategy": "tensor_group",
|
| 37 |
+
"symmetric": true,
|
| 38 |
+
"type": "float",
|
| 39 |
+
"zp_dtype": null
|
| 40 |
+
},
|
| 41 |
+
"output_activations": null,
|
| 42 |
+
"targets": [
|
| 43 |
+
"Linear"
|
| 44 |
+
],
|
| 45 |
+
"weights": {
|
| 46 |
+
"actorder": null,
|
| 47 |
+
"block_structure": null,
|
| 48 |
+
"dynamic": false,
|
| 49 |
+
"group_size": 16,
|
| 50 |
+
"num_bits": 4,
|
| 51 |
+
"observer": "memoryless_minmax",
|
| 52 |
+
"observer_kwargs": {},
|
| 53 |
+
"scale_dtype": "torch.float8_e4m3fn",
|
| 54 |
+
"strategy": "tensor_group",
|
| 55 |
+
"symmetric": true,
|
| 56 |
+
"type": "float",
|
| 57 |
+
"zp_dtype": null
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"format": "nvfp4-pack-quantized",
|
| 62 |
+
"global_compression_ratio": null,
|
| 63 |
+
"ignore": [
|
| 64 |
+
"lm_head"
|
| 65 |
+
],
|
| 66 |
+
"kv_cache_scheme": null,
|
| 67 |
+
"quant_method": "compressed-tensors",
|
| 68 |
+
"quantization_status": "compressed",
|
| 69 |
+
"sparsity_config": {},
|
| 70 |
+
"transform_config": {},
|
| 71 |
+
"version": "0.17.1"
|
| 72 |
+
},
|
| 73 |
+
"rms_norm_eps": 1e-06,
|
| 74 |
+
"rope_parameters": {
|
| 75 |
+
"rope_theta": 500000,
|
| 76 |
+
"rope_type": "default"
|
| 77 |
+
},
|
| 78 |
+
"tie_word_embeddings": false,
|
| 79 |
+
"transformers_version": "5.14.1+solaropen2",
|
| 80 |
+
"use_cache": true,
|
| 81 |
+
"vocab_size": 196608
|
| 82 |
+
}
|
example_cli.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This script works similarly to the `vllm` CLI command,
|
| 2 |
+
# but registers additional components.
|
| 3 |
+
#
|
| 4 |
+
# Usage: python example_cli.py [...rest of vllm CLI arguments]
|
| 5 |
+
#
|
| 6 |
+
# Example:
|
| 7 |
+
# The following command runs the llm-jp-4-8b-thinking model with the llmjp4 reasoning parser.
|
| 8 |
+
# python example_cli.py serve llm-jp/llm-jp-4-8b-thinking --reasoning-parser llmjp4 --trust-remote-code
|
| 9 |
+
|
| 10 |
+
from vllm.entrypoints.cli import main as cli_main
|
| 11 |
+
|
| 12 |
+
# Load the custom reasoning before launching the CLI.
|
| 13 |
+
import llmjp4_reasoning_parser
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
cli_main.main()
|
| 18 |
+
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"transformers_version": "5.14.1+solaropen2"
|
| 6 |
+
}
|
llmjp4_reasoning_parser.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vLLM Reasoning parser implementation for llm-jp-4 models.
|
| 2 |
+
# The overall algorithm is based on `GptOssReasoningParser`, but applies some modification.
|
| 3 |
+
# https://github.com/llm-jp/vllm/blob/4383f1532e87e77b6f961e633230f47467cbd072/vllm/reasoning/gptoss_reasoning_parser.py#L65
|
| 4 |
+
|
| 5 |
+
from collections.abc import Sequence
|
| 6 |
+
import warnings
|
| 7 |
+
|
| 8 |
+
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
|
| 9 |
+
from vllm.entrypoints.openai.engine.protocol import DeltaMessage
|
| 10 |
+
from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
|
| 11 |
+
from vllm.reasoning.abs_reasoning_parsers import (
|
| 12 |
+
ReasoningParser,
|
| 13 |
+
ReasoningParserManager,
|
| 14 |
+
)
|
| 15 |
+
from vllm.tokenizers import TokenizerLike
|
| 16 |
+
|
| 17 |
+
from llmjp4_harmony import HarmonyMessageParser
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@ReasoningParserManager.register_module(["llmjp4"])
|
| 21 |
+
class Llmjp4ReasoningParser(ReasoningParser):
|
| 22 |
+
|
| 23 |
+
def __init__(self, tokenizer: TokenizerLike, *args, **kwargs):
|
| 24 |
+
super().__init__(tokenizer, *args, **kwargs)
|
| 25 |
+
|
| 26 |
+
tokenizer = self.model_tokenizer
|
| 27 |
+
vocab = self.vocab
|
| 28 |
+
|
| 29 |
+
self._parser = HarmonyMessageParser(tokenizer)
|
| 30 |
+
self._start_id = vocab["<|start|>"]
|
| 31 |
+
self._end_id = vocab["<|end|>"]
|
| 32 |
+
self._message_id = vocab["<|message|>"]
|
| 33 |
+
self._reasoning_end_prefix = tokenizer.encode("<|channel|>final")
|
| 34 |
+
self._reasoning_prefill = tokenizer.encode("<|start|>assistant")
|
| 35 |
+
|
| 36 |
+
def is_reasoning_end(self, input_ids: Sequence[int]) -> bool:
|
| 37 |
+
# Find the final message pattern: <|channel|>final ... <|message|>
|
| 38 |
+
end_prefix = self._reasoning_end_prefix
|
| 39 |
+
message_id_found = False
|
| 40 |
+
|
| 41 |
+
for i in range(len(input_ids) - len(end_prefix), -1, -1):
|
| 42 |
+
if input_ids[i] == self._end_id:
|
| 43 |
+
# Reached the previous message
|
| 44 |
+
return False
|
| 45 |
+
elif input_ids[i] == self._message_id:
|
| 46 |
+
message_id_found = True
|
| 47 |
+
elif input_ids[i] == end_prefix[0]:
|
| 48 |
+
if input_ids[i:i + len(end_prefix)] == end_prefix and message_id_found:
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
return False
|
| 52 |
+
|
| 53 |
+
def extract_content_ids(self, input_ids: list[int]) -> list[int]:
|
| 54 |
+
input_ids = self._reasoning_prefill + input_ids
|
| 55 |
+
|
| 56 |
+
for message in self._parser.reverse_iter_messages(input_ids):
|
| 57 |
+
if message.role is None:
|
| 58 |
+
continue
|
| 59 |
+
channel_str = self.model_tokenizer.decode(message.role.token_ids)
|
| 60 |
+
if channel_str.startswith("final"):
|
| 61 |
+
return message.content.token_ids if message.content else []
|
| 62 |
+
|
| 63 |
+
return []
|
| 64 |
+
|
| 65 |
+
def count_reasoning_tokens(self, token_ids: Sequence[int]) -> int:
|
| 66 |
+
return 0
|
| 67 |
+
|
| 68 |
+
def extract_reasoning(
|
| 69 |
+
self,
|
| 70 |
+
model_output: str,
|
| 71 |
+
request: ChatCompletionRequest | ResponsesRequest,
|
| 72 |
+
) -> tuple[str | None, str | None]:
|
| 73 |
+
warnings.warn(
|
| 74 |
+
"Non-streaming response is not correctly implemented"
|
| 75 |
+
" due to the limitation of the current vLLM interface."
|
| 76 |
+
)
|
| 77 |
+
# NOTE(odashi):
|
| 78 |
+
# This is a workaround implementation,
|
| 79 |
+
# should be replaced with a proper implementation the interface is updated.
|
| 80 |
+
# We still can not handle the preceding reasoning parts appropriately.
|
| 81 |
+
marker = " assistant final "
|
| 82 |
+
marker_index = model_output.rfind(marker)
|
| 83 |
+
if marker_index == -1:
|
| 84 |
+
return None, None
|
| 85 |
+
content = model_output[marker_index + len(marker):].strip()
|
| 86 |
+
return None, content
|
| 87 |
+
|
| 88 |
+
def extract_reasoning_streaming(
|
| 89 |
+
self,
|
| 90 |
+
previous_text: str,
|
| 91 |
+
current_text: str,
|
| 92 |
+
delta_text: str,
|
| 93 |
+
previous_token_ids: Sequence[int],
|
| 94 |
+
current_token_ids: Sequence[int],
|
| 95 |
+
delta_token_ids: Sequence[int],
|
| 96 |
+
) -> DeltaMessage | None:
|
| 97 |
+
previous_token_ids = self._reasoning_prefill + list(previous_token_ids)
|
| 98 |
+
current_token_ids = self._reasoning_prefill + list(current_token_ids)
|
| 99 |
+
|
| 100 |
+
last_start_index: int | None = None
|
| 101 |
+
for i in range(len(previous_token_ids) - 1, -1, -1):
|
| 102 |
+
if previous_token_ids[i] == self._start_id:
|
| 103 |
+
last_start_index = i
|
| 104 |
+
break
|
| 105 |
+
assert last_start_index is not None, "<|start|> must exists."
|
| 106 |
+
|
| 107 |
+
previous_messages = self._parser.get_all_messages(
|
| 108 |
+
previous_token_ids[last_start_index:]
|
| 109 |
+
)
|
| 110 |
+
current_messages = self._parser.get_all_messages(
|
| 111 |
+
current_token_ids[last_start_index:]
|
| 112 |
+
)
|
| 113 |
+
assert len(previous_messages) == 1
|
| 114 |
+
assert len(current_messages) >= 1
|
| 115 |
+
|
| 116 |
+
reasoning_delta: list[str] = []
|
| 117 |
+
content_delta: list[str] = []
|
| 118 |
+
|
| 119 |
+
# Continuation of the last message
|
| 120 |
+
previous_content = previous_messages[0].content
|
| 121 |
+
previous_text = self.model_tokenizer.decode(
|
| 122 |
+
previous_content.token_ids if previous_content else []
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Analyse messages
|
| 126 |
+
for i, message in enumerate(current_messages):
|
| 127 |
+
if (
|
| 128 |
+
message.role is None
|
| 129 |
+
or message.channel is None
|
| 130 |
+
or message.content is None
|
| 131 |
+
):
|
| 132 |
+
continue
|
| 133 |
+
|
| 134 |
+
role_text = self.model_tokenizer.decode(message.role.token_ids)
|
| 135 |
+
channel_text = self.model_tokenizer.decode(message.channel.token_ids)
|
| 136 |
+
current_text = self.model_tokenizer.decode(message.content.token_ids)
|
| 137 |
+
prefix = previous_text if i == 0 else ""
|
| 138 |
+
assert current_text.startswith(prefix)
|
| 139 |
+
delta_text = current_text[len(prefix):]
|
| 140 |
+
|
| 141 |
+
if role_text != "assistant" or not delta_text:
|
| 142 |
+
continue
|
| 143 |
+
|
| 144 |
+
if channel_text.startswith("final"):
|
| 145 |
+
content_delta.append(delta_text)
|
| 146 |
+
else:
|
| 147 |
+
reasoning_delta.append(delta_text)
|
| 148 |
+
|
| 149 |
+
return DeltaMessage(
|
| 150 |
+
reasoning="".join(reasoning_delta) if reasoning_delta else None,
|
| 151 |
+
content="".join(content_delta) if content_delta else None,
|
| 152 |
+
)
|
llmjp4_tokenizer.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import LlamaTokenizerFast
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Llmjp4Tokenizer(LlamaTokenizerFast):
|
| 5 |
+
_HARMONY_TOKENS: set[str] = {
|
| 6 |
+
"<|start|>",
|
| 7 |
+
"<|message|>",
|
| 8 |
+
"<|channel|>",
|
| 9 |
+
"<|constrain|>",
|
| 10 |
+
"<|end|>",
|
| 11 |
+
"<|return|>",
|
| 12 |
+
"<|call|>",
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# NOTE(odashi):
|
| 16 |
+
# Response schemas are not recognized automatically.
|
| 17 |
+
# We need to define them manually.
|
| 18 |
+
# https://github.com/huggingface/trl/issues/4609
|
| 19 |
+
_RESPONSE_SCHEMA = {
|
| 20 |
+
"type": "object",
|
| 21 |
+
"properties": {
|
| 22 |
+
"role": {"const": "assistant"},
|
| 23 |
+
"content": {"type": "string", "x-regex": r"<\|channel\|>final<\|message\|>(.*?)(?:<\|end\|>|<\|return\|>|$)"},
|
| 24 |
+
"thinking": {"type": "string", "x-regex": r"<\|channel\|>analysis<\|message\|>(.*?)<\|end\|>"},
|
| 25 |
+
"tool_calls": {
|
| 26 |
+
"x-regex-iterator": r"<\|channel\|>commentary (to=functions\..*?<\|message\|>.*?)(?:<\|call\|>|$)",
|
| 27 |
+
"type": "array",
|
| 28 |
+
"items": {
|
| 29 |
+
"type": "object",
|
| 30 |
+
"properties": {
|
| 31 |
+
"type": {"const": "function"},
|
| 32 |
+
"function": {
|
| 33 |
+
"type": "object",
|
| 34 |
+
"properties": {
|
| 35 |
+
"name": {"type": "string", "x-regex": r"^to=functions\.(\w+)"},
|
| 36 |
+
"arguments": {
|
| 37 |
+
"type": "object",
|
| 38 |
+
"x-regex": r"<\|message\|>(.*)",
|
| 39 |
+
"x-parser": "json",
|
| 40 |
+
"additionalProperties": {"type": "any"},
|
| 41 |
+
},
|
| 42 |
+
},
|
| 43 |
+
},
|
| 44 |
+
},
|
| 45 |
+
},
|
| 46 |
+
},
|
| 47 |
+
},
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
def __init__(self, *args, **kwargs):
|
| 51 |
+
super().__init__(*args, **kwargs)
|
| 52 |
+
|
| 53 |
+
self.response_schema = self._RESPONSE_SCHEMA
|
| 54 |
+
|
| 55 |
+
self._harmony_token_ids = {
|
| 56 |
+
self.convert_tokens_to_ids(token)
|
| 57 |
+
for token in self._HARMONY_TOKENS
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
def _decode(self, token_ids: int | list[int], *args, **kwargs):
|
| 61 |
+
if isinstance(token_ids, int):
|
| 62 |
+
token_ids = [token_ids]
|
| 63 |
+
|
| 64 |
+
result: list[str] = []
|
| 65 |
+
prev_pos = 0
|
| 66 |
+
|
| 67 |
+
# NOTE(odashi):
|
| 68 |
+
# Ensure that text tokens are decoded without preceding Harmony tokens
|
| 69 |
+
# to avoid incorrect addition of whitespaces.
|
| 70 |
+
for pos, token_id in enumerate(token_ids, start=1):
|
| 71 |
+
if token_id in self._harmony_token_ids or pos == len(token_ids):
|
| 72 |
+
result.append(super()._decode(token_ids[prev_pos:pos], *args, **kwargs))
|
| 73 |
+
prev_pos = pos
|
| 74 |
+
|
| 75 |
+
return "".join(result)
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f8851f7d108d46a904c8a25b934ce53de6422442b8a21c19d74b35396f8102e
|
| 3 |
+
size 21581240912
|
recipe.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
default_stage:
|
| 2 |
+
default_modifiers:
|
| 3 |
+
QuantizationModifier:
|
| 4 |
+
targets: [Linear]
|
| 5 |
+
ignore: [lm_head]
|
| 6 |
+
scheme: NVFP4
|
| 7 |
+
bypass_divisibility_checks: false
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|startoftext|>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"cls_token": {
|
| 10 |
+
"content": "<|cls|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"eos_token": {
|
| 17 |
+
"content": "<|return|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"mask_token": {
|
| 24 |
+
"content": "<|mask|>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"pad_token": {
|
| 31 |
+
"content": "<|endoftext|>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
},
|
| 37 |
+
"sep_token": {
|
| 38 |
+
"content": "<|sep|>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": false,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false
|
| 43 |
+
},
|
| 44 |
+
"unk_token": {
|
| 45 |
+
"content": "<|unk|>",
|
| 46 |
+
"lstrip": false,
|
| 47 |
+
"normalized": false,
|
| 48 |
+
"rstrip": false,
|
| 49 |
+
"single_word": false
|
| 50 |
+
}
|
| 51 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:276e3354c256201f5bbb475cb25141eed78d3dd557ab413cc2a98e5ac1ad2b80
|
| 3 |
+
size 12868574
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 6 |
+
"pad_token": "<unk>",
|
| 7 |
+
"tokenizer_class": "TokenizersBackend",
|
| 8 |
+
"unk_token": "<unk>"
|
| 9 |
+
}
|