Image-Text-to-Text
Transformers
Safetensors
llava
quantized
compressed-tensors
gptq
w4a16
vllm
ampere
conversational
Instructions to use aleada/Pixtral-12B-W4A16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aleada/Pixtral-12B-W4A16 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="aleada/Pixtral-12B-W4A16") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("aleada/Pixtral-12B-W4A16") model = AutoModelForMultimodalLM.from_pretrained("aleada/Pixtral-12B-W4A16", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use aleada/Pixtral-12B-W4A16 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "aleada/Pixtral-12B-W4A16" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "aleada/Pixtral-12B-W4A16", "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/aleada/Pixtral-12B-W4A16
- SGLang
How to use aleada/Pixtral-12B-W4A16 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 "aleada/Pixtral-12B-W4A16" \ --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": "aleada/Pixtral-12B-W4A16", "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 "aleada/Pixtral-12B-W4A16" \ --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": "aleada/Pixtral-12B-W4A16", "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 aleada/Pixtral-12B-W4A16 with Docker Model Runner:
docker model run hf.co/aleada/Pixtral-12B-W4A16
Fix chat template: handle system message with multimodal (list) content
Browse filesThe template did `"[INST]" + system_message`, assuming string content. OpenAI-compatible servers (vLLM / litellm) normalize content into the content-parts list form for multimodal models, so any request carrying a system message raised: can only concatenate str (not list) to str. Flatten system + assistant list content to their text chunks; the user branch was already list-aware.
- chat_template.jinja +38 -6
chat_template.jinja
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{%- if messages[0]["role"] == "system" %}
|
| 2 |
-
{%- set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
{%- set loop_messages = messages[1:] %}
|
| 4 |
{%- else %}
|
| 5 |
{%- set loop_messages = messages %}
|
|
@@ -12,9 +37,7 @@
|
|
| 12 |
{%- endif %}
|
| 13 |
{%- if message["role"] == "user" %}
|
| 14 |
{%- if loop.last and system_message is defined %}
|
| 15 |
-
{{- "[INST]" + system_message + "
|
| 16 |
-
|
| 17 |
-
" }}
|
| 18 |
{%- else %}
|
| 19 |
{{- "[INST]" }}
|
| 20 |
{%- endif %}
|
|
@@ -33,8 +56,17 @@
|
|
| 33 |
{%- endif %}
|
| 34 |
{{- "[/INST]" }}
|
| 35 |
{%- elif message["role"] == "assistant" %}
|
| 36 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
{%- else %}
|
| 38 |
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
|
| 39 |
{%- endif %}
|
| 40 |
-
{%- endfor %}
|
|
|
|
| 1 |
+
{#- Pixtral-12B chat template — patched 2026-07-05.
|
| 2 |
+
|
| 3 |
+
The original template did `"[INST]" + system_message` and
|
| 4 |
+
`message["content"] + eos_token`, assuming `content` is ALWAYS a
|
| 5 |
+
plain string. Pixtral is multimodal, so OpenAI-compatible servers
|
| 6 |
+
(vLLM, litellm, ...) normalize message content into the content-parts
|
| 7 |
+
LIST form (`[{"type": "text", "text": ...}]`) before the template
|
| 8 |
+
runs. A plain system/assistant message then arrives as a list and
|
| 9 |
+
`str + list` raises "can only concatenate str (not list) to str" —
|
| 10 |
+
any request carrying a `system` message 400'd.
|
| 11 |
+
|
| 12 |
+
Fix: flatten system + assistant content to their text chunks when
|
| 13 |
+
they arrive as a list. The user branch already handled both string
|
| 14 |
+
and list content (including [IMG]) correctly and is unchanged. #}
|
| 15 |
{%- if messages[0]["role"] == "system" %}
|
| 16 |
+
{%- set system_raw = messages[0]["content"] %}
|
| 17 |
+
{%- if system_raw is string %}
|
| 18 |
+
{%- set system_message = system_raw %}
|
| 19 |
+
{%- else %}
|
| 20 |
+
{%- set sys_ns = namespace(text="") %}
|
| 21 |
+
{%- for chunk in system_raw %}
|
| 22 |
+
{%- if chunk["type"] == "text" %}
|
| 23 |
+
{%- set sys_ns.text = sys_ns.text + chunk["text"] %}
|
| 24 |
+
{%- endif %}
|
| 25 |
+
{%- endfor %}
|
| 26 |
+
{%- set system_message = sys_ns.text %}
|
| 27 |
+
{%- endif %}
|
| 28 |
{%- set loop_messages = messages[1:] %}
|
| 29 |
{%- else %}
|
| 30 |
{%- set loop_messages = messages %}
|
|
|
|
| 37 |
{%- endif %}
|
| 38 |
{%- if message["role"] == "user" %}
|
| 39 |
{%- if loop.last and system_message is defined %}
|
| 40 |
+
{{- "[INST]" + system_message + "\n\n" }}
|
|
|
|
|
|
|
| 41 |
{%- else %}
|
| 42 |
{{- "[INST]" }}
|
| 43 |
{%- endif %}
|
|
|
|
| 56 |
{%- endif %}
|
| 57 |
{{- "[/INST]" }}
|
| 58 |
{%- elif message["role"] == "assistant" %}
|
| 59 |
+
{%- if message["content"] is string %}
|
| 60 |
+
{{- message["content"] + eos_token }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{%- for chunk in message["content"] %}
|
| 63 |
+
{%- if chunk["type"] == "text" %}
|
| 64 |
+
{{- chunk["text"] }}
|
| 65 |
+
{%- endif %}
|
| 66 |
+
{%- endfor %}
|
| 67 |
+
{{- eos_token }}
|
| 68 |
+
{%- endif %}
|
| 69 |
{%- else %}
|
| 70 |
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
|
| 71 |
{%- endif %}
|
| 72 |
+
{%- endfor %}
|