Instructions to use trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration") model = AutoModelForMultimodalLM.from_pretrained("trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration
- SGLang
How to use trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration with Docker Model Runner:
docker model run hf.co/trl-internal-testing/tiny-MistralLarge4ForConditionalGeneration
Upload tiny MistralLarge4ForConditionalGeneration
Browse files- .gitattributes +1 -0
- README.md +9 -0
- chat_template.jinja +258 -0
- config.json +131 -0
- generation_config.json +5 -0
- model.safetensors +3 -0
- processor_config.json +32 -0
- tokenizer.json +3 -0
- tokenizer_config.json +12 -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
|
README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- trl
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# Tiny MistralLarge4ForConditionalGeneration
|
| 8 |
+
|
| 9 |
+
This is a minimal model built for unit tests in the [TRL](https://github.com/huggingface/trl) library.
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{#- Default system message if no system prompt is passed. #}
|
| 2 |
+
{%- set default_system_message = '' %}
|
| 3 |
+
|
| 4 |
+
{#- Begin of sequence token. #}
|
| 5 |
+
{{- bos_token }}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
{#- Handle system prompt if it exists. #}
|
| 9 |
+
{%- set loop_messages = messages %}
|
| 10 |
+
{%- if messages[0]['role'] != 'system' and default_system_message != '' %}
|
| 11 |
+
{{- '[SYSTEM_PROMPT]' + default_system_message + '[/SYSTEM_PROMPT]' }}
|
| 12 |
+
{%- endif %}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
{#- Tools and model settings definition #}
|
| 16 |
+
{%- set available_tools = '' %}
|
| 17 |
+
{%- set has_tools = false %}
|
| 18 |
+
{%- if tools is defined and tools is not none and tools|length > 0 %}
|
| 19 |
+
{%- set has_tools = true %}
|
| 20 |
+
{%- set available_tools = '[AVAILABLE_TOOLS]' + (tools| tojson) + '[/AVAILABLE_TOOLS]' %}
|
| 21 |
+
{%- endif %}
|
| 22 |
+
{%- set json_schema = none %}
|
| 23 |
+
{%- if response_format is defined and response_format is not none %}
|
| 24 |
+
{%- if response_format['type'] == 'json_schema' %}
|
| 25 |
+
{%- if 'json_schema' in response_format and response_format['json_schema'] is not none %}
|
| 26 |
+
{%- if 'schema' in response_format['json_schema'] %}
|
| 27 |
+
{%- if response_format['json_schema']['schema'] is not none %}
|
| 28 |
+
{%- set json_schema = response_format['json_schema']['schema'] %}
|
| 29 |
+
{%- else %}
|
| 30 |
+
{{- raise_exception('Response format `json_schema` must define the schema') }}
|
| 31 |
+
{%- endif %}
|
| 32 |
+
{%- else %}
|
| 33 |
+
{{- raise_exception('Response format `json_schema` must define the schema') }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- else %}
|
| 36 |
+
{{- raise_exception('Response format `json_schema` must define the schema') }}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- elif response_format['type'] == 'json_object' %}
|
| 39 |
+
{%- set json_schema = {'anyOf': [{'type': 'object'}, {'type': 'array'}]} %}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- if reasoning_effort is not defined or reasoning_effort is none %}
|
| 43 |
+
{%- set reasoning_effort = 'none' %}
|
| 44 |
+
{%- endif %}
|
| 45 |
+
{%- if reasoning_effort not in ['none', 'high'] %}
|
| 46 |
+
{{- raise_exception('reasoning_effort must be either "none" or "high"') }}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- if json_schema is not none %}
|
| 49 |
+
{%- set model_settings = '[MODEL_SETTINGS]{"json_schema": ' + (json_schema|tojson) + ', "reasoning_effort": "' + reasoning_effort + '"}[/MODEL_SETTINGS]' %}
|
| 50 |
+
{%- else %}
|
| 51 |
+
{%- set model_settings = '[MODEL_SETTINGS]{"reasoning_effort": "' + reasoning_effort + '"}[/MODEL_SETTINGS]' %}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
|
| 54 |
+
{#- Macros #}
|
| 55 |
+
{%- macro render_content(content, context_name, supported_types_desc, support_thinking, support_images) -%}
|
| 56 |
+
{%- if content is string -%}
|
| 57 |
+
{{- content -}}
|
| 58 |
+
{%- elif content -%}
|
| 59 |
+
{%- for block in content -%}
|
| 60 |
+
{%- if block['type'] == 'text' -%}
|
| 61 |
+
{{- block['text'] -}}
|
| 62 |
+
{%- elif support_thinking and block['type'] == 'thinking' -%}
|
| 63 |
+
{{- '[THINK]' + block['thinking'] -}}
|
| 64 |
+
{%- if block.get('closed', true) -%}{{- '[/THINK]' -}}{%- endif -%}
|
| 65 |
+
{%- elif support_images and block['type'] in ['image', 'image_url'] -%}
|
| 66 |
+
{{- '[IMG]' -}}
|
| 67 |
+
{%- else -%}
|
| 68 |
+
{{- raise_exception('Only ' + supported_types_desc + ' chunks are supported in ' + context_name + '.') -}}
|
| 69 |
+
{%- endif -%}
|
| 70 |
+
{%- endfor -%}
|
| 71 |
+
{%- else -%}
|
| 72 |
+
{{- raise_exception(context_name + ' must have non-empty content.') -}}
|
| 73 |
+
{%- endif -%}
|
| 74 |
+
{%- endmacro -%}
|
| 75 |
+
|
| 76 |
+
{#- Aggregate consecutive messages with the same role except system and tool. #}
|
| 77 |
+
{#- A sentinel message is appended so the last group gets flushed inside the loop. #}
|
| 78 |
+
{%- set ns_agg = namespace(messages=[], current_group=[], current_role=none) %}
|
| 79 |
+
{%- for message in loop_messages + [{'role': '__sentinel__'}] %}
|
| 80 |
+
{%- if message['role'] != ns_agg.current_role or message['role'] == 'system' or message['role'] == 'tool' %}
|
| 81 |
+
{%- if ns_agg.current_role == 'tool' %}
|
| 82 |
+
{%- set ns_agg.messages = ns_agg.messages + ns_agg.current_group %}
|
| 83 |
+
{%- elif ns_agg.current_role is not none %}
|
| 84 |
+
{%- set ns_c = namespace(text_parts=[], chunks=[], has_non_text=false, tool_calls=[]) %}
|
| 85 |
+
{%- for msg in ns_agg.current_group %}
|
| 86 |
+
{#- Convert reasoning / reasoning_content to a leading thinking chunk. #}
|
| 87 |
+
{%- set reasoning = msg.get('reasoning_content', msg.get('reasoning', none)) %}
|
| 88 |
+
{%- if reasoning is not none and reasoning != '' %}
|
| 89 |
+
{%- if msg['content'] is not none and msg['content'] is not string %}
|
| 90 |
+
{%- for block in msg['content'] %}
|
| 91 |
+
{%- if block['type'] == 'thinking' %}
|
| 92 |
+
{{- raise_exception('Message cannot have both thinking chunks in content and a top-level `reasoning` or `reasoning_content` field.') }}
|
| 93 |
+
{%- endif %}
|
| 94 |
+
{%- endfor %}
|
| 95 |
+
{%- endif %}
|
| 96 |
+
{%- set think_chunk = {'type': 'thinking', 'thinking': reasoning} %}
|
| 97 |
+
{%- if msg['content'] is string and msg['content'] != '' %}
|
| 98 |
+
{%- set new_content = [think_chunk, {'type': 'text', 'text': msg['content']}] %}
|
| 99 |
+
{%- elif msg['content'] is not none and msg['content'] is not string and msg['content'] | length > 0 %}
|
| 100 |
+
{%- set new_content = [think_chunk] + msg['content'] | list %}
|
| 101 |
+
{%- else %}
|
| 102 |
+
{%- set new_content = [think_chunk] %}
|
| 103 |
+
{%- endif %}
|
| 104 |
+
{%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
|
| 105 |
+
{%- set msg = {'role': msg['role'], 'content': new_content, 'tool_calls': msg['tool_calls']} %}
|
| 106 |
+
{%- else %}
|
| 107 |
+
{%- set msg = {'role': msg['role'], 'content': new_content} %}
|
| 108 |
+
{%- endif %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
{%- if msg['content'] is string %}
|
| 111 |
+
{%- set ns_c.text_parts = ns_c.text_parts + [msg['content']] %}
|
| 112 |
+
{%- elif msg['content'] is not none %}
|
| 113 |
+
{%- set ns_msg = namespace(msg_text_parts=[]) %}
|
| 114 |
+
{%- for block in msg['content'] %}
|
| 115 |
+
{%- if block['type'] == 'text' %}
|
| 116 |
+
{%- set ns_msg.msg_text_parts = ns_msg.msg_text_parts + [block['text']] %}
|
| 117 |
+
{%- else %}
|
| 118 |
+
{%- if ns_msg.msg_text_parts | length > 0 %}
|
| 119 |
+
{%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
|
| 120 |
+
{%- set ns_msg.msg_text_parts = [] %}
|
| 121 |
+
{%- endif %}
|
| 122 |
+
{%- if ns_c.text_parts | length > 0 %}
|
| 123 |
+
{%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
|
| 124 |
+
{%- set ns_c.text_parts = [] %}
|
| 125 |
+
{%- endif %}
|
| 126 |
+
{%- set ns_c.chunks = ns_c.chunks + [block] %}
|
| 127 |
+
{%- set ns_c.has_non_text = true %}
|
| 128 |
+
{%- endif %}
|
| 129 |
+
{%- endfor %}
|
| 130 |
+
{%- if ns_msg.msg_text_parts | length > 0 %}
|
| 131 |
+
{%- set ns_c.text_parts = ns_c.text_parts + [ns_msg.msg_text_parts | join('')] %}
|
| 132 |
+
{%- endif %}
|
| 133 |
+
{%- endif %}
|
| 134 |
+
{%- if msg['tool_calls'] is defined and msg['tool_calls'] is not none %}
|
| 135 |
+
{%- set ns_c.tool_calls = ns_c.tool_calls + msg['tool_calls'] | list %}
|
| 136 |
+
{%- endif %}
|
| 137 |
+
{%- endfor %}
|
| 138 |
+
{%- if ns_c.has_non_text %}
|
| 139 |
+
{%- if ns_c.text_parts | length > 0 %}
|
| 140 |
+
{%- set ns_c.chunks = ns_c.chunks + [{'type': 'text', 'text': ns_c.text_parts | join('\n\n')}] %}
|
| 141 |
+
{%- endif %}
|
| 142 |
+
{%- set merged_content = ns_c.chunks %}
|
| 143 |
+
{%- else %}
|
| 144 |
+
{%- set merged_content = ns_c.text_parts | join('\n\n') %}
|
| 145 |
+
{%- endif %}
|
| 146 |
+
{%- if ns_c.tool_calls | length > 0 %}
|
| 147 |
+
{%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content, 'tool_calls': ns_c.tool_calls}] %}
|
| 148 |
+
{%- else %}
|
| 149 |
+
{%- set ns_agg.messages = ns_agg.messages + [{'role': ns_agg.current_role, 'content': merged_content}] %}
|
| 150 |
+
{%- endif %}
|
| 151 |
+
{%- endif %}
|
| 152 |
+
{%- if message['role'] != '__sentinel__' %}
|
| 153 |
+
{%- set ns_agg.current_group = [message] %}
|
| 154 |
+
{%- set ns_agg.current_role = message['role'] %}
|
| 155 |
+
{%- endif %}
|
| 156 |
+
{%- else %}
|
| 157 |
+
{%- set ns_agg.current_group = ns_agg.current_group + [message] %}
|
| 158 |
+
{%- endif %}
|
| 159 |
+
{%- endfor %}
|
| 160 |
+
{%- set loop_messages = ns_agg.messages %}
|
| 161 |
+
|
| 162 |
+
{#- Validates message ordering. #}
|
| 163 |
+
{%- set ns = namespace(available_tools_and_settings_emitted=false) %}
|
| 164 |
+
{%- if loop_messages | length > 0 and loop_messages[0]['role'] not in ['user', 'system'] %}
|
| 165 |
+
{{- raise_exception('Conversation must start with a user or system message, got ' + loop_messages[0]['role'] + '.') }}
|
| 166 |
+
{%- endif %}
|
| 167 |
+
{%- set ns_order = namespace(previous_role=none) %}
|
| 168 |
+
{%- for message in loop_messages %}
|
| 169 |
+
{%- set current_role = message['role'] %}
|
| 170 |
+
{%- if ns_order.previous_role is not none %}
|
| 171 |
+
{%- if ns_order.previous_role == 'system' %}
|
| 172 |
+
{%- if current_role not in ['user', 'assistant', 'system'] %}
|
| 173 |
+
{{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
|
| 174 |
+
{%- endif %}
|
| 175 |
+
{%- elif ns_order.previous_role == 'user' %}
|
| 176 |
+
{%- if current_role not in ['assistant', 'system', 'user'] %}
|
| 177 |
+
{{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
|
| 178 |
+
{%- endif %}
|
| 179 |
+
{%- elif ns_order.previous_role == 'assistant' %}
|
| 180 |
+
{%- if current_role not in ['assistant', 'user', 'tool'] %}
|
| 181 |
+
{{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
|
| 182 |
+
{%- endif %}
|
| 183 |
+
{%- elif ns_order.previous_role == 'tool' %}
|
| 184 |
+
{%- if current_role not in ['assistant', 'tool', 'user'] %}
|
| 185 |
+
{{- raise_exception('Unexpected role \'' + current_role + '\' after role \'' + ns_order.previous_role + '\'') }}
|
| 186 |
+
{%- endif %}
|
| 187 |
+
{%- endif %}
|
| 188 |
+
{%- endif %}
|
| 189 |
+
{%- set ns_order.previous_role = current_role %}
|
| 190 |
+
{%- endfor %}
|
| 191 |
+
|
| 192 |
+
{#- Handle conversation messages. #}
|
| 193 |
+
{%- for message in loop_messages %}
|
| 194 |
+
{#- User messages supports text, image and image_url content. #}
|
| 195 |
+
{%- if message['role'] == 'user' %}
|
| 196 |
+
{%- if not ns.available_tools_and_settings_emitted %}
|
| 197 |
+
{{- available_tools }}
|
| 198 |
+
{{- model_settings }}
|
| 199 |
+
{%- set ns.available_tools_and_settings_emitted = true %}
|
| 200 |
+
{%- endif %}
|
| 201 |
+
{%- if message['content'] is not string and message['content'] %}
|
| 202 |
+
{#- When content has exactly one image and one text block, put image first. #}
|
| 203 |
+
{%- if message['content'] | length == 2 and message['content'][0]['type'] == 'text' and message['content'][1]['type'] in ['image', 'image_url'] %}
|
| 204 |
+
{%- set blocks = [message['content'][1], message['content'][0]] %}
|
| 205 |
+
{%- else %}
|
| 206 |
+
{%- set blocks = message['content'] %}
|
| 207 |
+
{%- endif %}
|
| 208 |
+
{%- set user_content = blocks %}
|
| 209 |
+
{%- else %}
|
| 210 |
+
{%- set user_content = message['content'] %}
|
| 211 |
+
{%- endif %}
|
| 212 |
+
{{- '[INST]' -}}
|
| 213 |
+
{{- render_content(content=user_content, context_name='user message content', supported_types_desc='text, image and image_url', support_thinking=false, support_images=true) -}}
|
| 214 |
+
{{- '[/INST]' }}
|
| 215 |
+
|
| 216 |
+
{#- Assistant messages supports text and thinking content. #}
|
| 217 |
+
{%- elif message['role'] == 'assistant' %}
|
| 218 |
+
{%- 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) %}
|
| 219 |
+
{{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
|
| 220 |
+
{%- endif %}
|
| 221 |
+
|
| 222 |
+
{%- if message['content'] %}
|
| 223 |
+
{{- render_content(content=message['content'], context_name='assistant message contents', supported_types_desc='text and thinking', support_thinking=true, support_images=false) -}}
|
| 224 |
+
{%- endif %}
|
| 225 |
+
|
| 226 |
+
{%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
|
| 227 |
+
{%- for tool in message['tool_calls'] %}
|
| 228 |
+
{{- '[TOOL_CALLS]' }}
|
| 229 |
+
{%- set name = tool['function']['name'] %}
|
| 230 |
+
{%- set arguments = tool['function']['arguments'] %}
|
| 231 |
+
{%- if arguments is not string %}
|
| 232 |
+
{%- set arguments = arguments|tojson|safe %}
|
| 233 |
+
{%- elif arguments == '' %}
|
| 234 |
+
{%- set arguments = '{}' %}
|
| 235 |
+
{%- endif %}
|
| 236 |
+
{{- name + '[ARGS]' + arguments }}
|
| 237 |
+
{%- endfor %}
|
| 238 |
+
{%- endif %}
|
| 239 |
+
|
| 240 |
+
{{- eos_token }}
|
| 241 |
+
|
| 242 |
+
{#- Tool messages (multimodal). #}
|
| 243 |
+
{%- elif message['role'] == 'tool' %}
|
| 244 |
+
{{- '[TOOL_RESULTS]' -}}
|
| 245 |
+
{{- render_content(content=message['content'], context_name='tool message contents', supported_types_desc='text and image', support_thinking=false, support_images=true) -}}
|
| 246 |
+
{{- '[/TOOL_RESULTS]' }}
|
| 247 |
+
|
| 248 |
+
{#- System messages. #}
|
| 249 |
+
{%- elif message['role'] == 'system' %}
|
| 250 |
+
{{- '[SYSTEM_PROMPT]' -}}
|
| 251 |
+
{{- render_content(content=message['content'], context_name='system message contents', supported_types_desc='text', support_thinking=false, support_images=false) -}}
|
| 252 |
+
{{- '[/SYSTEM_PROMPT]' -}}
|
| 253 |
+
|
| 254 |
+
{#- Raise exception for unsupported roles. #}
|
| 255 |
+
{%- else %}
|
| 256 |
+
{{- raise_exception('Only user, assistant, system and tool roles are supported, got ' + message['role'] + '.') }}
|
| 257 |
+
{%- endif %}
|
| 258 |
+
{%- endfor %}
|
config.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MistralLarge4ForConditionalGeneration"
|
| 4 |
+
],
|
| 5 |
+
"dtype": "bfloat16",
|
| 6 |
+
"image_token_index": 10,
|
| 7 |
+
"model_type": "mistral_large4",
|
| 8 |
+
"multimodal_projector_bias": false,
|
| 9 |
+
"projector_hidden_act": "gelu",
|
| 10 |
+
"spatial_merge_size": 2,
|
| 11 |
+
"text_config": {
|
| 12 |
+
"attention_bias": false,
|
| 13 |
+
"attention_dropout": 0.0,
|
| 14 |
+
"bos_token_id": 1,
|
| 15 |
+
"eos_token_id": 2,
|
| 16 |
+
"final_logit_softcapping": 30.0,
|
| 17 |
+
"first_k_dense_replace": 1,
|
| 18 |
+
"head_dim": 8,
|
| 19 |
+
"hidden_act": "silu",
|
| 20 |
+
"hidden_size": 32,
|
| 21 |
+
"index_head_dim": 16,
|
| 22 |
+
"index_n_heads": 2,
|
| 23 |
+
"index_topk": 4,
|
| 24 |
+
"indexer_types": [
|
| 25 |
+
"full",
|
| 26 |
+
"full",
|
| 27 |
+
"full",
|
| 28 |
+
"shared",
|
| 29 |
+
"shared",
|
| 30 |
+
"full",
|
| 31 |
+
"full",
|
| 32 |
+
"shared"
|
| 33 |
+
],
|
| 34 |
+
"initializer_range": 0.02,
|
| 35 |
+
"intermediate_size": 32,
|
| 36 |
+
"kv_lora_rank": 16,
|
| 37 |
+
"kv_source_layers": [
|
| 38 |
+
0,
|
| 39 |
+
1,
|
| 40 |
+
2,
|
| 41 |
+
3,
|
| 42 |
+
4,
|
| 43 |
+
5,
|
| 44 |
+
6,
|
| 45 |
+
3
|
| 46 |
+
],
|
| 47 |
+
"layer_types": [
|
| 48 |
+
"indexed_attention",
|
| 49 |
+
"indexed_attention",
|
| 50 |
+
"indexed_attention",
|
| 51 |
+
"indexed_attention",
|
| 52 |
+
"indexed_attention",
|
| 53 |
+
"indexed_attention",
|
| 54 |
+
"indexed_attention",
|
| 55 |
+
"indexed_attention"
|
| 56 |
+
],
|
| 57 |
+
"max_position_embeddings": 1048576,
|
| 58 |
+
"mlp_layer_types": [
|
| 59 |
+
"dense",
|
| 60 |
+
"sparse",
|
| 61 |
+
"sparse",
|
| 62 |
+
"sparse",
|
| 63 |
+
"sparse",
|
| 64 |
+
"sparse",
|
| 65 |
+
"sparse",
|
| 66 |
+
"sparse"
|
| 67 |
+
],
|
| 68 |
+
"model_type": "mistral_large4_text",
|
| 69 |
+
"moe_intermediate_size": 16,
|
| 70 |
+
"n_group": 1,
|
| 71 |
+
"n_routed_experts": 8,
|
| 72 |
+
"n_shared_experts": 1,
|
| 73 |
+
"no_rope_layer_interval": 4,
|
| 74 |
+
"no_rope_layers": [
|
| 75 |
+
1,
|
| 76 |
+
1,
|
| 77 |
+
1,
|
| 78 |
+
0,
|
| 79 |
+
1,
|
| 80 |
+
1,
|
| 81 |
+
1,
|
| 82 |
+
0
|
| 83 |
+
],
|
| 84 |
+
"num_attention_heads": 4,
|
| 85 |
+
"num_experts_per_tok": 2,
|
| 86 |
+
"num_hidden_layers": 8,
|
| 87 |
+
"num_key_value_heads": 4,
|
| 88 |
+
"output_router_logits": false,
|
| 89 |
+
"pad_token_id": null,
|
| 90 |
+
"qk_head_dim": 128,
|
| 91 |
+
"qk_nope_head_dim": 8,
|
| 92 |
+
"qk_rope_head_dim": 8,
|
| 93 |
+
"rms_norm_eps": 1e-05,
|
| 94 |
+
"rope_parameters": {
|
| 95 |
+
"attention_factor": 1.0,
|
| 96 |
+
"beta_fast": 32,
|
| 97 |
+
"beta_slow": 1,
|
| 98 |
+
"factor": 2048,
|
| 99 |
+
"original_max_position_embeddings": 512,
|
| 100 |
+
"rope_theta": 10000.0,
|
| 101 |
+
"rope_type": "yarn"
|
| 102 |
+
},
|
| 103 |
+
"routed_scaling_factor": 1.0,
|
| 104 |
+
"tie_word_embeddings": false,
|
| 105 |
+
"topk_group": 1,
|
| 106 |
+
"use_cache": true,
|
| 107 |
+
"v_head_dim": 8,
|
| 108 |
+
"vocab_size": 204800
|
| 109 |
+
},
|
| 110 |
+
"tie_word_embeddings": false,
|
| 111 |
+
"transformers_version": "5.21.0.dev0",
|
| 112 |
+
"vision_config": {
|
| 113 |
+
"attention_dropout": 0.0,
|
| 114 |
+
"head_dim": 4,
|
| 115 |
+
"hidden_act": "silu",
|
| 116 |
+
"hidden_size": 16,
|
| 117 |
+
"image_size": 1540,
|
| 118 |
+
"initializer_range": 0.02,
|
| 119 |
+
"intermediate_size": 32,
|
| 120 |
+
"model_type": "pixtral",
|
| 121 |
+
"num_attention_heads": 4,
|
| 122 |
+
"num_channels": 3,
|
| 123 |
+
"num_hidden_layers": 2,
|
| 124 |
+
"patch_size": 14,
|
| 125 |
+
"rope_parameters": {
|
| 126 |
+
"rope_theta": 10000.0,
|
| 127 |
+
"rope_type": "axial"
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
"vision_feature_layer": -1
|
| 131 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 1,
|
| 3 |
+
"eos_token_id": 2,
|
| 4 |
+
"transformers_version": "5.21.0.dev0"
|
| 5 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:288001a0565e8174b42f35e6049f7d61d7a9249894fac1c6d8a0fd070375f717
|
| 3 |
+
size 26585376
|
processor_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_break_token": "[IMG_BREAK]",
|
| 3 |
+
"image_end_token": "[IMG_END]",
|
| 4 |
+
"image_processor": {
|
| 5 |
+
"do_convert_rgb": true,
|
| 6 |
+
"do_normalize": true,
|
| 7 |
+
"do_pad": true,
|
| 8 |
+
"do_rescale": true,
|
| 9 |
+
"do_resize": true,
|
| 10 |
+
"image_mean": [
|
| 11 |
+
0.48145466,
|
| 12 |
+
0.4578275,
|
| 13 |
+
0.40821073
|
| 14 |
+
],
|
| 15 |
+
"image_processor_type": "PixtralImageProcessor",
|
| 16 |
+
"image_std": [
|
| 17 |
+
0.26862954,
|
| 18 |
+
0.26130258,
|
| 19 |
+
0.27577711
|
| 20 |
+
],
|
| 21 |
+
"patch_size": 14,
|
| 22 |
+
"resample": 3,
|
| 23 |
+
"rescale_factor": 0.00392156862745098,
|
| 24 |
+
"size": {
|
| 25 |
+
"longest_edge": 1540
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"image_token": "[IMG]",
|
| 29 |
+
"patch_size": 14,
|
| 30 |
+
"processor_class": "PixtralProcessor",
|
| 31 |
+
"spatial_merge_size": 2
|
| 32 |
+
}
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b4155d8f91d3a5ca0679da30f9135b1223addb1c835f35329b7be44d84b90256
|
| 3 |
+
size 27851231
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"local_files_only": true,
|
| 7 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 8 |
+
"pad_token": "<pad>",
|
| 9 |
+
"processor_class": "PixtralProcessor",
|
| 10 |
+
"tokenizer_class": "TokenizersBackend",
|
| 11 |
+
"unk_token": "<unk>"
|
| 12 |
+
}
|