Run this model with HF Jobs

Run trl-internal-testing/tiny-Mistral3ForConditionalGeneration on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/trl-internal-testing/tiny-Mistral3ForConditionalGeneration. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/trl-internal-testing/tiny-Mistral3ForConditionalGeneration on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/trl-internal-testing/tiny-Mistral3ForConditionalGeneration. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/trl-internal-testing/tiny-Mistral3ForConditionalGeneration. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
File size: 17,211 Bytes
4c60fed
6c2dec9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c60fed
 
 
6c2dec9
4c60fed
 
 
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c2dec9
 
 
 
 
 
 
 
 
 
4c60fed
 
6c2dec9
 
4c60fed
 
 
 
 
 
 
 
6c2dec9
 
 
 
 
 
 
 
4c60fed
 
 
 
 
 
 
6c2dec9
 
 
 
 
 
4c60fed
 
 
 
 
 
 
 
 
 
6c2dec9
 
4c60fed
 
 
6c2dec9
4c60fed
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
6c2dec9
 
4c60fed
 
 
 
 
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c2dec9
4c60fed
 
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c2dec9
 
4c60fed
 
 
 
 
 
 
6c2dec9
4c60fed
 
 
6c2dec9
4c60fed
 
 
6c2dec9
4c60fed
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c2dec9
4c60fed
 
 
 
6c2dec9
4c60fed
 
 
 
 
6c2dec9
4c60fed
 
 
 
 
 
 
 
 
 
 
 
6c2dec9
4c60fed
 
 
 
6c2dec9
4c60fed
 
 
 
6c2dec9
4c60fed
 
 
 
 
6c2dec9
4c60fed
 
 
 
6c2dec9
4c60fed
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
{#- Default system message if no system prompt is passed. #}
{#- Dates for the default system prompt, filled as in the model card's load_system_prompt(). #}
{%- set today = strftime_now("%Y-%m-%d") %}
{%- set date_parts = namespace(year=today[:4]|int, month=today[5:7]|int, day=today[8:10]|int) %}
{%- if date_parts.day > 1 %}
    {%- set date_parts.day = date_parts.day - 1 %}
{%- else %}
    {%- if date_parts.month == 1 %}
        {%- set date_parts.month = 12 %}
        {%- set date_parts.year = date_parts.year - 1 %}
    {%- else %}
        {%- set date_parts.month = date_parts.month - 1 %}
    {%- endif %}
    {%- if date_parts.month == 2 %}
        {%- set leap = date_parts.year % 4 == 0 and (date_parts.year % 100 != 0 or date_parts.year % 400 == 0) %}
        {%- set date_parts.day = 29 if leap else 28 %}
    {%- else %}
        {%- set date_parts.day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][date_parts.month - 1] %}
    {%- endif %}
{%- endif %}
{%- set yesterday = date_parts.year|string + '-' + ('0' if date_parts.month < 10 else '') + date_parts.month|string + '-' + ('0' if date_parts.day < 10 else '') + date_parts.day|string %}
{%- set default_system_message = 'You are Mistral Medium 3.5, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.
You are an intelligent conversational assistant powering an AI assistant called Le Chat.
Your knowledge base was last updated on Friday, November 1, 2024.
The current date is ' ~ today ~ '.

# GENERAL GUIDELINES

- Accurately answer the user\'s question.
- For uncertain information or when the user\'s request requires up-to-date or specific data, use the available tools to fetch the information.
- Be very attentive to dates, always try to resolve dates (e.g. "yesterday" is ' ~ yesterday ~ ') and when asked about information at specific dates, discard information that is at another date.

# WEB BROWSING INSTRUCTIONS

You cannot perform any web search or access internet to open URLs, links etc without dedicated tools.

# MULTI-MODAL INSTRUCTIONS

- You have the ability to read images.
- You cannot read audio nor videos.
- You cannot generate images without dedicated tools.

# TOOL CALLING INSTRUCTIONS

You may have access to tools that you can use to fetch information or perform actions. You must use these tools in the following situations:

1. When the request requires up-to-date information.
2. When the request requires specific data that you do not have in your knowledge base.
3. When the request involves actions that you cannot perform without tools.

Always prioritize using tools to provide the most accurate and helpful response.' %}

{#- Begin of sequence token. #}
{{- bos_token }}


{#- Reject an empty conversation, as the tokenizer does. #}
{%- if messages | length == 0 %}
    {{- raise_exception('Conversation must have at least one message') }}
{%- endif %}

{#- A single message must be a user or system message, as the tokenizer requires. #}
{%- if messages | length == 1 and messages[0]['role'] not in ['user', 'system', 'developer'] %}
    {{- raise_exception('Conversation must start with a user message or system message') }}
{%- endif %}

{#- Handle system prompt if it exists. #}
{%- set loop_messages = messages %}
{%- if messages[0]['role'] not in ['system', 'developer'] and default_system_message != '' %}
    {{- '[SYSTEM_PROMPT]' ~ default_system_message ~ '[/SYSTEM_PROMPT]' }}
{%- endif %}


{#- Tools and model settings definition #}
{%- set available_tools = '' %}
{%- set has_tools = false %}
{%- if tools is defined and tools is not none and tools|length > 0 %}
    {%- set has_tools = true %}
    {%- set ns_t = namespace(tools=[]) %}
    {%- for tool in tools %}
        {%- set tool_function = tool['function'] %}
        {%- set description = tool_function['description'] if 'description' in tool_function else none %}
        {%- set parameters = tool_function['parameters'] if 'parameters' in tool_function else none %}
        {%- set ns_t.tools = ns_t.tools + [{'type': tool['type'] if 'type' in tool else 'function', 'function': {'name': tool_function['name'], 'description': description if description is not none else '', 'parameters': parameters if parameters is not none else {}}}] %}
    {%- endfor %}
    {%- set available_tools = '[AVAILABLE_TOOLS]' ~ (ns_t.tools| tojson) ~ '[/AVAILABLE_TOOLS]' %}
{%- endif %}
{%- if reasoning_effort is not defined or reasoning_effort is none %}
    {%- set reasoning_effort = 'none' %}
{%- endif %}
{%- if reasoning_effort not in ['none', 'high'] %}
    {{- raise_exception('reasoning_effort must be either "none" or "high"') }}
{%- endif %}
{%- set model_settings_parts = [] %}
{%- set model_settings_parts = model_settings_parts + ['"reasoning_effort": "' ~ reasoning_effort ~ '"'] %}
{%- set model_settings = '' %}
{%- if model_settings_parts %}
    {%- set model_settings = '[MODEL_SETTINGS]{' ~ model_settings_parts|join(', ') ~ '}[/MODEL_SETTINGS]' %}
{%- endif %}

{#- Macros #}
{%- macro render_content(content, context_name, supported_types_desc, support_thinking, support_images) -%}
    {%- if content is string -%}
        {{- content -}}
    {%- elif content -%}
        {%- for block in content -%}
            {%- if block['type'] == 'text' -%}
                {{- block['text'] -}}
            {%- elif support_thinking and block['type'] == 'thinking' -%}
                {{- '[THINK]' ~ block['thinking'] -}}
                {%- if (block['closed'] if 'closed' in block else true) -%}{{- '[/THINK]' -}}{%- endif -%}
            {%- elif support_images and block['type'] in ['image', 'image_url'] -%}
                {{- '[IMG]' -}}
            {%- else -%}
                {{- raise_exception('Only ' ~ supported_types_desc ~ ' chunks are supported in ' ~ context_name ~ '.') -}}
            {%- endif -%}
        {%- endfor -%}
    {%- else -%}
        {{- raise_exception(context_name ~ ' must have non-empty content.') -}}
    {%- endif -%}
{%- endmacro -%}

{#- Aggregate consecutive messages with the same role except system and tool. #}
{#- A sentinel message is appended so the last group gets flushed inside the loop. #}
{%- set ns_agg = namespace(messages=[], current_group=[], current_role=none) %}
{%- for message in loop_messages + [{'role': '__sentinel__'}] %}
    {#- Read the developer role as system, as the tokenizer does. #}
    {%- set message = {'role': 'system', 'content': message['content']} if message['role'] == 'developer' else message %}
    {%- if message['role'] != ns_agg.current_role or message['role'] == 'system' or message['role'] == 'tool' %}
        {%- if ns_agg.current_role == 'tool' %}
            {%- set ns_agg.messages = ns_agg.messages + ns_agg.current_group %}
        {%- elif ns_agg.current_role is not none %}
            {%- set ns_c = namespace(text_parts=[], chunks=[], has_non_text=false, tool_calls=[]) %}
            {%- for msg in ns_agg.current_group %}
                {#- Convert reasoning / reasoning_content to a leading thinking chunk. #}
                {%- set reasoning = msg['reasoning_content'] if 'reasoning_content' in msg else (msg['reasoning'] if 'reasoning' in msg else none) %}
                {%- if reasoning is not none and reasoning != '' %}
                    {%- if msg['content'] is not none and msg['content'] is not string %}
                        {%- for block in msg['content'] %}
                            {%- if block['type'] == 'thinking' %}
                                {{- raise_exception('Message cannot have both thinking chunks in content and a top-level `reasoning` or `reasoning_content` field.') }}
                            {%- endif %}
                        {%- endfor %}
                    {%- endif %}
                    {%- set think_chunk = {'type': 'thinking', 'thinking': reasoning} %}
                    {%- if msg['content'] is string and msg['content'] != '' %}
                        {%- set new_content = [think_chunk, {'type': 'text', 'text': msg['content']}] %}
                    {%- elif msg['content'] is not none and msg['content'] is not string and msg['content'] | length > 0 %}
                        {%- set new_content = [think_chunk] + msg['content'] | list %}
                    {%- else %}
                        {%- set new_content = [think_chunk] %}
                    {%- endif %}
                    {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
                        {%- set msg = {'role': msg['role'], 'content': new_content, 'tool_calls': msg['tool_calls']} %}
                    {%- else %}
                        {%- set msg = {'role': msg['role'], 'content': new_content} %}
                    {%- endif %}
                {%- endif %}
                {%- if msg['content'] is string %}
                    {%- set ns_c.text_parts = ns_c.text_parts + ([msg['content']] if msg['content'] else []) %}
                {%- elif msg['content'] is not none %}
                    {%- set ns_msg = namespace(msg_text_parts=[]) %}
                    {%- for block in msg['content'] %}
                        {%- if block['type'] == 'text' %}
                            {%- set ns_msg.msg_text_parts = ns_msg.msg_text_parts + ([block['text']] if block['text'] else []) %}
                        {%- else %}
                            {%- if ns_msg.msg_text_parts | length > 0 %}
                                {%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
                                {%- set ns_msg.msg_text_parts = [] %}
                            {%- endif %}
                            {%- if ns_c.text_parts | length > 0 %}
                                {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
                                {%- set ns_c.text_parts = [] %}
                            {%- endif %}
                            {%- set ns_c.chunks = ns_c.chunks + [block] %}
                            {%- set ns_c.has_non_text = true %}
                        {%- endif %}
                    {%- endfor %}
                    {%- if ns_msg.msg_text_parts | length > 0 %}
                        {%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
                    {%- endif %}
                {%- endif %}
                {%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
                    {%- set ns_c.tool_calls = ns_c.tool_calls + msg['tool_calls'] | list %}
                {%- endif %}
            {%- endfor %}
            {%- if ns_c.has_non_text %}
                {%- if ns_c.text_parts | length > 0 %}
                    {%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
                {%- endif %}
                {%- set merged_content = ns_c.chunks %}
            {%- else %}
                {%- set merged_content = ns_c.text_parts | join('\n\n') %}
            {%- endif %}
            {%- if ns_c.tool_calls | length > 0 %}
                {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content, 'tool_calls': ns_c.tool_calls}] %}
            {%- else %}
                {%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content}] %}
            {%- endif %}
        {%- endif %}
        {%- if message['role'] != '__sentinel__' %}
            {%- set ns_agg.current_group = [message] %}
            {%- set ns_agg.current_role = message['role'] %}
        {%- endif %}
    {%- else %}
        {%- set ns_agg.current_group = ns_agg.current_group + [message] %}
    {%- endif %}
{%- endfor %}
{%- set loop_messages = ns_agg.messages %}

{#- Validates message ordering. #}
{%- set ns = namespace(available_tools_and_settings_emitted=false) %}
{%- if loop_messages | length > 0 and loop_messages[0]['role'] not in ['user', 'system', 'assistant'] %}
    {{- raise_exception('Conversation must start with a user, system or assistant message, got ' ~ loop_messages[0]['role'] ~ '.') }}
{%- endif %}
{%- set ns_order = namespace(previous_role=none) %}
{%- for message in loop_messages %}
    {%- set current_role = message['role'] %}
    {%- if ns_order.previous_role is not none %}
        {%- if ns_order.previous_role == 'system' %}
            {%- if current_role not in ['user', 'assistant', 'system'] %}
                {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
            {%- endif %}
        {%- elif ns_order.previous_role == 'user' %}
            {%- if current_role not in ['assistant', 'system', 'user'] %}
                {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
            {%- endif %}
        {%- elif ns_order.previous_role == 'assistant' %}
            {%- if current_role not in ['assistant', 'user', 'tool'] %}
                {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
            {%- endif %}
        {%- elif ns_order.previous_role == 'tool' %}
            {%- if current_role not in ['assistant', 'tool', 'user'] %}
                {{- raise_exception('Unexpected role \'' ~ current_role ~ '\' after role \'' ~ ns_order.previous_role ~ '\'') }}
            {%- endif %}
        {%- endif %}
    {%- endif %}
    {%- set ns_order.previous_role = current_role %}
{%- endfor %}

{#- Handle conversation messages. #}
{%- for message in loop_messages %}
    {#- User messages supports text, image and image_url content. #}
    {%- if message['role'] == 'user' %}
        {%- if not ns.available_tools_and_settings_emitted %}
            {{- available_tools }}
            {{- model_settings }}
            {%- set ns.available_tools_and_settings_emitted = true %}
        {%- endif %}
        {%- if message['content'] is not string and message['content'] %}
            {#- When content has exactly one image and one text block, put image first. #}
            {%- if message['content'] | length == 2 and message['content'][0]['type'] == 'text' and message['content'][1]['type'] in ['image', 'image_url'] %}
                {%- set blocks = [message['content'][1], message['content'][0]] %}
            {%- else %}
                {%- set blocks = message['content'] %}
            {%- endif %}
            {%- set user_content = blocks %}
        {%- else %}
            {%- set user_content = message['content'] %}
        {%- endif %}
        {{- '[INST]' -}}
        {{- render_content(content=user_content, context_name='user message content', supported_types_desc='text, image and image_url', support_thinking=false, support_images=true) -}}
        {{- '[/INST]' }}

    {#- Assistant messages supports text and thinking content. #}
    {%- elif message['role'] == 'assistant' %}
        {%- generation -%}
        {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
            {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
        {%- endif %}

        {%- if message['content'] %}
            {{- render_content(content=message['content'], context_name='assistant message contents', supported_types_desc='text and thinking', support_thinking=true, support_images=false) -}}
        {%- endif %}

        {%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
            {%- for tool in message['tool_calls'] %}
                {{- '[TOOL_CALLS]' }}
                {%- set name = tool['function']['name'] %}
                {%- set arguments = tool['function']['arguments'] %}
                {%- if arguments is not string %}
                    {%- set arguments = arguments|tojson|safe %}
                {%- elif arguments == '' %}
                    {%- set arguments = '{}' %}
                {%- endif %}
                {{- name ~ '[ARGS]' ~ arguments }}
            {%- endfor %}
        {%- endif %}

        {{- eos_token }}
        {%- endgeneration -%}

    {#- Tool messages (multimodal). #}
    {%- elif message['role'] == 'tool' %}
        {{- '[TOOL_RESULTS]' -}}
        {{- render_content(content=message['content'], context_name='tool message contents', supported_types_desc='text and image', support_thinking=false, support_images=true) -}}
        {{- '[/TOOL_RESULTS]' }}

    {#- System messages. #}
    {%- elif message['role'] == 'system' %}
        {{- '[SYSTEM_PROMPT]' -}}
        {{- render_content(content=message['content'], context_name='system message contents', supported_types_desc='text', support_thinking=false, support_images=false) -}}
        {{- '[/SYSTEM_PROMPT]' -}}

    {#- Raise exception for unsupported roles. #}
    {%- else %}
        {{- raise_exception('Only user, assistant, system and tool roles are supported, got ' ~ message['role'] ~ '.') }}
    {%- endif %}
{%- endfor %}