LlamaFinetuneBase commited on
Commit
640ae6b
·
verified ·
1 Parent(s): bf6ee6f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +288 -0
README.md ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - fr
5
+ - de
6
+ - es
7
+ - it
8
+ - pt
9
+ - ru
10
+ - zh
11
+ - ja
12
+ license: apache-2.0
13
+ library_name: vllm
14
+ extra_gated_description: If you want to learn more about how we process your personal
15
+ data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
16
+ ---
17
+
18
+ # Model Card for Pixtral-12B-2409
19
+
20
+ The Pixtral-12B-2409 is a Multimodal Model of 12B parameters plus a 400M parameter vision encoder.
21
+
22
+ For more details about this model please refer to our release [blog post](https://mistral.ai/news/pixtral-12b/).
23
+
24
+ Feel free to try it [here](https://chat.mistral.ai/chat)
25
+
26
+ ## Key features
27
+ - Natively multimodal, trained with interleaved image and text data
28
+ - 12B parameter Multimodal Decoder + 400M parameter Vision Encoder
29
+ - Supports variable image sizes
30
+ - Leading performance in its weight class on multimodal tasks
31
+ - Maintains state-of-the-art performance on text-only benchmarks
32
+ - Sequence length: 128k
33
+ - License: Apache 2.0
34
+
35
+ ## Benchmarks
36
+ The performance of Pixtral-12B-2409 compared to multimodal models.
37
+ All models were re-evaluated and benchmarked through the same evaluation pipeline.
38
+
39
+ ### Multimodal Benchmarks
40
+
41
+ | | Pixtral 12B | Qwen2 7B VL | LLaVA-OV 7B | Phi-3 Vision | Phi-3.5 Vision |
42
+ |:-------------------:|:-------------:|:----------:|:-------------:|:--------------:|:--------------:|
43
+ | **MMMU** *(CoT)* | <ins>**52.5**</ins> | 47.6 | 45.1 | 40.3 | 38.3 |
44
+ | **Mathvista** *(CoT)* | <ins>**58.0**</ins> | 54.4 | 36.1 | 36.4 | 39.3 |
45
+ | **ChartQA** *(CoT)* | <ins>**81.8**</ins> | 38.6 | 67.1 | 72.0 | 67.7 |
46
+ | **DocVQA** *(ANLS)* | 90.7 | <ins>**94.5**</ins> | 90.5 | 84.9 | 74.4 |
47
+ | **VQAv2** *(VQA Match)* | <ins>**78.6**</ins> | 75.9 | 78.3 | 42.4 | 56.1 |
48
+
49
+ ### Instruction Following
50
+
51
+ | | Pixtral 12B | Qwen2 7B VL | LLaVA-OV 7B | Phi-3 Vision | Phi-3.5 Vision |
52
+ |:-------------------:|:-------------:|:----------:|:-------------:|:--------------:|:--------------:|
53
+ | **MM MT-Bench** | <ins>**6.05**</ins> | 5.43 | 4.12 | 3.70 |4.46 |
54
+ | **Text MT-Bench** | <ins>**7.68**</ins> | 6.41 | 6.94 | 6.27 |6.31 |
55
+ | **MM IF-Eval** | <ins>**52.7**</ins> | 38.9 | 42.5 | 41.2 |31.4 |
56
+ | **Text IF-Eval** | <ins>**61.3**</ins> | 50.1 | 51.4 | 50.9 |47.4 |
57
+
58
+ ### Text Benchmarks
59
+
60
+ | | Pixtral 12B | Qwen2 7B VL | LLaVA-OV 7B | Phi-3 Vision | Phi-3.5 Vision |
61
+ |:-------------------:|:-------------:|:----------:|:-------------:|:--------------:|:--------------:|
62
+ | **MMLU** *(5-shot)* | <ins>**69.2**</ins> | 68.5 | 67.9 | 63.5 | 63.6 |
63
+ | **Math** *(Pass@1)* | <ins>**48.1**</ins> | 27.8 | 38.6 | 29.2 | 28.4 |
64
+ | **Human Eval** *(Pass@1)* | <ins>**72.0**</ins> | 64.6 | 65.9 | 48.8 | 49.4 |
65
+
66
+ ### Comparison with Closed Source and Larger Models
67
+ | | Pixtral 12B | Claude-3 Haiku | Gemini-1.5 Flash 8B *(0827)* | . |*LLaVA-OV 72B* | *GPT-4o* | *Claude-3.5 Sonnet* |
68
+ |:-------------------:|:-------------:|:----------------:|:----------------------:|:--------:|:----:|:-------------------:|:-------------------:|
69
+ | **MMMU** *(CoT)* | **52.5** | 50.4 | 50.7 | |*54.4* |<ins>*68.6*</ins> | *68.0* |
70
+ | **Mathvista** *(CoT)* | **58.0** | 44.8 | 56.9 | |*57.2* |<ins>*64.6*</ins> | *64.4* |
71
+ | **ChartQA** *(CoT)* | **81.8** | 69.6 | 78.0 | |*66.9* |*85.1* | <ins>*87.6*</ins> |
72
+ | **DocVQA** *(ANLS)* | **90.7**</ins> | 74.6 | 79.5 | |<ins>*91.6*</ins> |*88.9* | *90.3* |
73
+ | **VQAv2** *(VQA Match)* | **78.6** | 68.4 | 65.5 | |<ins>*83.8*</ins> |*77.8* | *70.7* |
74
+
75
+ ## Usage Examples
76
+
77
+ ### vLLM (recommended)
78
+
79
+ We recommend using Pixtral with the [vLLM library](https://github.com/vllm-project/vllm)
80
+ to implement production-ready inference pipelines with Pixtral.
81
+
82
+ **_Installation_**
83
+
84
+ Make sure you install `vLLM >= v0.6.1.post1`:
85
+
86
+ ```
87
+ pip install --upgrade vllm
88
+ ```
89
+
90
+ Also make sure you have `mistral_common >= 1.4.1` installed:
91
+
92
+ ```
93
+ pip install --upgrade mistral_common
94
+ ```
95
+
96
+ You can also make use of a ready-to-go [docker image](https://hub.docker.com/layers/vllm/vllm-openai/latest/images/sha256-de9032a92ffea7b5c007dad80b38fd44aac11eddc31c435f8e52f3b7404bbf39?context=explore).
97
+
98
+ **_Simple Example_**
99
+
100
+ ```py
101
+ from vllm import LLM
102
+ from vllm.sampling_params import SamplingParams
103
+
104
+ model_name = "mistralai/Pixtral-12B-2409"
105
+
106
+ sampling_params = SamplingParams(max_tokens=8192)
107
+
108
+ llm = LLM(model=model_name, tokenizer_mode="mistral")
109
+
110
+ prompt = "Describe this image in one sentence."
111
+ image_url = "https://picsum.photos/id/237/200/300"
112
+
113
+ messages = [
114
+ {
115
+ "role": "user",
116
+ "content": [{"type": "text", "text": prompt}, {"type": "image_url", "image_url": {"url": image_url}}]
117
+ },
118
+ ]
119
+
120
+ outputs = llm.chat(messages, sampling_params=sampling_params)
121
+
122
+ print(outputs[0].outputs[0].text)
123
+ ```
124
+
125
+ **_Advanced Example_**
126
+
127
+ You can also pass multiple images per message and/or pass multi-turn conversations
128
+
129
+ ```py
130
+ from vllm import LLM
131
+ from vllm.sampling_params import SamplingParams
132
+
133
+ model_name = "mistralai/Pixtral-12B-2409"
134
+ max_img_per_msg = 5
135
+
136
+ sampling_params = SamplingParams(max_tokens=8192, temperature=0.7)
137
+
138
+ # Lower max_num_seqs or max_model_len on low-VRAM GPUs.
139
+ llm = LLM(model=model_name, tokenizer_mode="mistral", limit_mm_per_prompt={"image": max_img_per_msg}, max_model_len=32768)
140
+
141
+ prompt = "Describe the following image."
142
+
143
+ url_1 = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/yosemite.png"
144
+ url_2 = "https://picsum.photos/seed/picsum/200/300"
145
+ url_3 = "https://picsum.photos/id/32/512/512"
146
+
147
+ messages = [
148
+ {
149
+ "role": "user",
150
+ "content": [{"type": "text", "text": prompt}, {"type": "image_url", "image_url": {"url": url_1}}, {"type": "image_url", "image_url": {"url": url_2}}],
151
+ },
152
+ {
153
+ "role": "assistant",
154
+ "content": "The images shows nature.",
155
+ },
156
+ {
157
+ "role": "user",
158
+ "content": "More details please and answer only in French!."
159
+ },
160
+ {
161
+ "role": "user",
162
+ "content": [{"type": "image_url", "image_url": {"url": url_3}}],
163
+ }
164
+ ]
165
+
166
+ outputs = llm.chat(messages=messages, sampling_params=sampling_params)
167
+ print(outputs[0].outputs[0].text)
168
+ ```
169
+
170
+ You can find more examples and tests directly in vLLM.
171
+ - [Examples](https://github.com/vllm-project/vllm/blob/main/examples/offline_inference_pixtral.py)
172
+ - [Tests](https://github.com/vllm-project/vllm/blob/main/tests/models/test_pixtral.py)
173
+
174
+ **_Server_**
175
+
176
+ You can also use pixtral in a server/client setting.
177
+
178
+ 1. Spin up a server:
179
+
180
+ ```
181
+ vllm serve mistralai/Pixtral-12B-2409 --tokenizer_mode mistral --limit_mm_per_prompt 'image=4'
182
+ ```
183
+
184
+ 2. And ping the client:
185
+
186
+ ```
187
+ curl --location 'http://<your-node-url>:8000/v1/chat/completions' \
188
+ --header 'Content-Type: application/json' \
189
+ --header 'Authorization: Bearer token' \
190
+ --data '{
191
+ "model": "mistralai/Pixtral-12B-2409",
192
+ "messages": [
193
+ {
194
+ "role": "user",
195
+ "content": [
196
+ {"type" : "text", "text": "Describe this image in detail please."},
197
+ {"type": "image_url", "image_url": {"url": "https://s3.amazonaws.com/cms.ipressroom.com/338/files/201808/5b894ee1a138352221103195_A680%7Ejogging-edit/A680%7Ejogging-edit_hero.jpg"}},
198
+ {"type" : "text", "text": "and this one as well. Answer in French."},
199
+ {"type": "image_url", "image_url": {"url": "https://www.wolframcloud.com/obj/resourcesystem/images/a0e/a0ee3983-46c6-4c92-b85d-059044639928/6af8cfb971db031b.png"}}
200
+ ]
201
+ }
202
+ ]
203
+ }'
204
+ ```
205
+
206
+ ### Mistral-inference
207
+
208
+ We recommend using [mistral-inference](https://github.com/mistralai/mistral-inference) to quickly try out / "vibe-check" Pixtral.
209
+
210
+
211
+ **_Install_**
212
+
213
+ Make sure to have `mistral_inference >= 1.4.1` installed.
214
+
215
+ ```
216
+ pip install mistral_inference --upgrade
217
+ ```
218
+
219
+ **_Download_**
220
+
221
+ ```py
222
+ from huggingface_hub import snapshot_download
223
+ from pathlib import Path
224
+
225
+ mistral_models_path = Path.home().joinpath('mistral_models', 'Pixtral')
226
+ mistral_models_path.mkdir(parents=True, exist_ok=True)
227
+
228
+ snapshot_download(repo_id="mistralai/Pixtral-12B-2409", allow_patterns=["params.json", "consolidated.safetensors", "tekken.json"], local_dir=mistral_models_path)
229
+ ```
230
+
231
+ **_Chat_**
232
+
233
+ After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment.
234
+ You can pass text and images or image urls to the model in *instruction-following* mode as follows:
235
+
236
+ ```
237
+ mistral-chat $HOME/mistral_models/Pixtral --instruct --max_tokens 256 --temperature 0.35
238
+ ```
239
+
240
+ *E.g.* Try out something like:
241
+
242
+ ```
243
+ Text prompt: What can you see on the following picture?
244
+ [You can input zero, one or more images now.]
245
+ Image path or url [Leave empty and press enter to finish image input]: https://picsum.photos/id/237/200/300
246
+ Image path or url [Leave empty and press enter to finish image input]:
247
+ I see a black dog lying on a wooden surface. The dog appears to be looking up, and its eyes are clearly visible.
248
+ ```
249
+
250
+ **_Python_**
251
+
252
+ You can also run the model in a Python shell as follows.
253
+
254
+ ```py
255
+ from mistral_inference.transformer import Transformer
256
+ from mistral_inference.generate import generate
257
+
258
+ from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
259
+ from mistral_common.protocol.instruct.messages import UserMessage, TextChunk, ImageURLChunk
260
+ from mistral_common.protocol.instruct.request import ChatCompletionRequest
261
+
262
+ tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tekken.json")
263
+ model = Transformer.from_folder(mistral_models_path)
264
+
265
+ url = "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/yosemite.png"
266
+ prompt = "Describe the image."
267
+
268
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content=[ImageURLChunk(image_url=url), TextChunk(text=prompt)])])
269
+
270
+ encoded = tokenizer.encode_chat_completion(completion_request)
271
+
272
+ images = encoded.images
273
+ tokens = encoded.tokens
274
+
275
+ out_tokens, _ = generate([tokens], model, images=[images], max_tokens=256, temperature=0.35, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
276
+ result = tokenizer.decode(out_tokens[0])
277
+
278
+ print(result)
279
+ ```
280
+
281
+ ## Limitations
282
+
283
+ The Pixtral model does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
284
+ make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
285
+
286
+ ## The Mistral AI Team
287
+
288
+ Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Alok Kothari, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Augustin Garreau, Austin Birky, Bam4d, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Carole Rambaud, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Diogo Costa, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gaspard Blanchet, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Henri Roussez, Hichem Sattouf, Ian Mack, Jean-Malo Delignon, Jessica Chudnovsky, Justus Murke, Kartik Khandelwal, Lawrence Stewart, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Marjorie Janiewicz, Mickaël Seznec, Nicolas Schuhl, Niklas Muhs, Olivier de Garrigues, Patrick von Platen, Paul Jacob, Pauline Buche, Pavan Kumar Reddy, Perry Savas, Pierre Stock, Romain Sauvestre, Sagar Vaze, Sandeep Subramanian, Saurabh Garg, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibault Schueller, Thibaut Lavril, Thomas Wang, Théophile Gervet, Timothée Lacroix, Valera Nemychnikova, Wendy Shang, William El Sayed, William Marshall