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
Commit ·
3184655
1
Parent(s): db367c5
Sync the chat template with the released checkpoint (#1)
Browse files- Sync the chat template with the released checkpoint (8f96adf936b7622c34a54012241869c784684f2e)
- chat_template.jinja +32 -32
chat_template.jinja
CHANGED
|
@@ -8,7 +8,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]'
|
| 12 |
{%- endif %}
|
| 13 |
|
| 14 |
|
|
@@ -17,38 +17,38 @@
|
|
| 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]'
|
| 21 |
{%- endif %}
|
| 22 |
{%- set json_schema = none %}
|
| 23 |
{%- if response_format is defined and response_format is not none %}
|
| 24 |
-
{%-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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
|
| 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 = '
|
| 44 |
{%- endif %}
|
| 45 |
-
{%- if reasoning_effort not in ['
|
| 46 |
-
{{- raise_exception('reasoning_effort must be
|
| 47 |
{%- endif %}
|
|
|
|
| 48 |
{%- if json_schema is not none %}
|
| 49 |
-
{%- set
|
| 50 |
-
{%-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
{%- endif %}
|
| 53 |
|
| 54 |
{#- Macros #}
|
|
@@ -60,16 +60,16 @@
|
|
| 60 |
{%- if block['type'] == 'text' -%}
|
| 61 |
{{- block['text'] -}}
|
| 62 |
{%- elif support_thinking and block['type'] == 'thinking' -%}
|
| 63 |
-
{{- '[THINK]'
|
| 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 '
|
| 69 |
{%- endif -%}
|
| 70 |
{%- endfor -%}
|
| 71 |
{%- else -%}
|
| 72 |
-
{{- raise_exception(context_name
|
| 73 |
{%- endif -%}
|
| 74 |
{%- endmacro -%}
|
| 75 |
|
|
@@ -162,7 +162,7 @@
|
|
| 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 '
|
| 166 |
{%- endif %}
|
| 167 |
{%- set ns_order = namespace(previous_role=none) %}
|
| 168 |
{%- for message in loop_messages %}
|
|
@@ -170,19 +170,19 @@
|
|
| 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 \''
|
| 174 |
{%- endif %}
|
| 175 |
{%- elif ns_order.previous_role == 'user' %}
|
| 176 |
{%- if current_role not in ['assistant', 'system', 'user'] %}
|
| 177 |
-
{{- raise_exception('Unexpected role \''
|
| 178 |
{%- endif %}
|
| 179 |
{%- elif ns_order.previous_role == 'assistant' %}
|
| 180 |
{%- if current_role not in ['assistant', 'user', 'tool'] %}
|
| 181 |
-
{{- raise_exception('Unexpected role \''
|
| 182 |
{%- endif %}
|
| 183 |
{%- elif ns_order.previous_role == 'tool' %}
|
| 184 |
{%- if current_role not in ['assistant', 'tool', 'user'] %}
|
| 185 |
-
{{- raise_exception('Unexpected role \''
|
| 186 |
{%- endif %}
|
| 187 |
{%- endif %}
|
| 188 |
{%- endif %}
|
|
@@ -233,7 +233,7 @@
|
|
| 233 |
{%- elif arguments == '' %}
|
| 234 |
{%- set arguments = '{}' %}
|
| 235 |
{%- endif %}
|
| 236 |
-
{{- name
|
| 237 |
{%- endfor %}
|
| 238 |
{%- endif %}
|
| 239 |
|
|
@@ -253,6 +253,6 @@
|
|
| 253 |
|
| 254 |
{#- Raise exception for unsupported roles. #}
|
| 255 |
{%- else %}
|
| 256 |
-
{{- raise_exception('Only user, assistant, system and tool roles are supported, got '
|
| 257 |
{%- endif %}
|
| 258 |
-
{%- endfor %}
|
|
|
|
| 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 |
|
|
|
|
| 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 |
+
{%- set response_format_type = response_format.get('type', 'text') %}
|
| 25 |
+
{%- set response_json_schema = response_format.get('json_schema') %}
|
| 26 |
+
{%- if response_format_type not in ['text', 'json_object', 'json_schema'] %}
|
| 27 |
+
{{- raise_exception('Response format type must be one of text, json_object or json_schema, got ' ~ response_format_type ~ '.') }}
|
| 28 |
+
{%- elif response_format_type == 'json_schema' %}
|
| 29 |
+
{%- if response_json_schema is none or response_json_schema.get('schema') is none %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
{{- raise_exception('Response format `json_schema` must define the schema') }}
|
| 31 |
+
{%- else %}
|
| 32 |
+
{%- set json_schema = response_json_schema['schema'] %}
|
| 33 |
{%- endif %}
|
| 34 |
+
{%- elif response_format_type == 'json_object' %}
|
| 35 |
{%- set json_schema = {'anyOf': [{'type': 'object'}, {'type': 'array'}]} %}
|
| 36 |
{%- endif %}
|
| 37 |
{%- endif %}
|
| 38 |
{%- if reasoning_effort is not defined or reasoning_effort is none %}
|
| 39 |
+
{%- set reasoning_effort = 'high' %}
|
| 40 |
{%- endif %}
|
| 41 |
+
{%- if reasoning_effort not in ['low', 'medium', 'high'] %}
|
| 42 |
+
{{- raise_exception('reasoning_effort must be one of "low", "medium", "high"') }}
|
| 43 |
{%- endif %}
|
| 44 |
+
{%- set model_settings_parts = [] %}
|
| 45 |
{%- if json_schema is not none %}
|
| 46 |
+
{%- set model_settings_parts = model_settings_parts + ['"json_schema": ' ~ (json_schema|tojson)] %}
|
| 47 |
+
{%- endif %}
|
| 48 |
+
{%- set model_settings_parts = model_settings_parts + ['"reasoning_effort": "' ~ reasoning_effort ~ '"'] %}
|
| 49 |
+
{%- set model_settings = '' %}
|
| 50 |
+
{%- if model_settings_parts %}
|
| 51 |
+
{%- set model_settings = '[MODEL_SETTINGS]{' ~ model_settings_parts|join(', ') ~ '}[/MODEL_SETTINGS]' %}
|
| 52 |
{%- endif %}
|
| 53 |
|
| 54 |
{#- Macros #}
|
|
|
|
| 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 |
|
|
|
|
| 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 %}
|
|
|
|
| 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 %}
|
|
|
|
| 233 |
{%- elif arguments == '' %}
|
| 234 |
{%- set arguments = '{}' %}
|
| 235 |
{%- endif %}
|
| 236 |
+
{{- name ~ '[ARGS]' ~ arguments }}
|
| 237 |
{%- endfor %}
|
| 238 |
{%- endif %}
|
| 239 |
|
|
|
|
| 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 %}
|