readme update
Browse files
    	
        README.md
    CHANGED
    
    | @@ -48,6 +48,7 @@ Average word error rate (WER) over the FLEURS, Mozilla Common Voice and Multilin | |
| 48 |  | 
| 49 | 
             
            The model can be used with the following frameworks;
         | 
| 50 | 
             
            - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
         | 
|  | |
| 51 |  | 
| 52 | 
             
            **Notes**:
         | 
| 53 |  | 
| @@ -235,4 +236,285 @@ req = TranscriptionRequest(model=model, audio=audio, language="en", temperature= | |
| 235 | 
             
            response = client.audio.transcriptions.create(**req)
         | 
| 236 | 
             
            print(response)
         | 
| 237 | 
             
            ```
         | 
| 238 | 
            -
            </details>
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 48 |  | 
| 49 | 
             
            The model can be used with the following frameworks;
         | 
| 50 | 
             
            - [`vllm (recommended)`](https://github.com/vllm-project/vllm): See [here](#vllm-recommended)
         | 
| 51 | 
            +
            - [`Transformers` 🤗](https://github.com/huggingface/transformers): See [here](#transformers)
         | 
| 52 |  | 
| 53 | 
             
            **Notes**:
         | 
| 54 |  | 
|  | |
| 236 | 
             
            response = client.audio.transcriptions.create(**req)
         | 
| 237 | 
             
            print(response)
         | 
| 238 | 
             
            ```
         | 
| 239 | 
            +
            </details>
         | 
| 240 | 
            +
             | 
| 241 | 
            +
            ### Transformers 🤗
         | 
| 242 | 
            +
             | 
| 243 | 
            +
            Voxtral is supported in Transformers natively!
         | 
| 244 | 
            +
             | 
| 245 | 
            +
            Install Transformers from source:
         | 
| 246 | 
            +
            ```bash
         | 
| 247 | 
            +
            pip install git+https://github.com/huggingface/transformers
         | 
| 248 | 
            +
            ```
         | 
| 249 | 
            +
             | 
| 250 | 
            +
            #### Audio Instruct
         | 
| 251 | 
            +
             | 
| 252 | 
            +
            <details>
         | 
| 253 | 
            +
              <summary>➡️ multi-audio + text instruction</summary>
         | 
| 254 | 
            +
             | 
| 255 | 
            +
            ```python
         | 
| 256 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 257 | 
            +
            import torch
         | 
| 258 | 
            +
             | 
| 259 | 
            +
            device = "cuda"
         | 
| 260 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 261 | 
            +
             | 
| 262 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 263 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 264 | 
            +
             | 
| 265 | 
            +
            conversation = [
         | 
| 266 | 
            +
                {
         | 
| 267 | 
            +
                    "role": "user",
         | 
| 268 | 
            +
                    "content": [
         | 
| 269 | 
            +
                        {
         | 
| 270 | 
            +
                            "type": "audio",
         | 
| 271 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/mary_had_lamb.mp3",
         | 
| 272 | 
            +
                        },
         | 
| 273 | 
            +
                        {
         | 
| 274 | 
            +
                            "type": "audio",
         | 
| 275 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
         | 
| 276 | 
            +
                        },
         | 
| 277 | 
            +
                        {"type": "text", "text": "What sport and what nursery rhyme are referenced?"},
         | 
| 278 | 
            +
                    ],
         | 
| 279 | 
            +
                }
         | 
| 280 | 
            +
            ]
         | 
| 281 | 
            +
             | 
| 282 | 
            +
            inputs = processor.apply_chat_template(conversation)
         | 
| 283 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 284 | 
            +
             | 
| 285 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 286 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 287 | 
            +
             | 
| 288 | 
            +
            print("\nGenerated response:")
         | 
| 289 | 
            +
            print("=" * 80)
         | 
| 290 | 
            +
            print(decoded_outputs[0])
         | 
| 291 | 
            +
            print("=" * 80)
         | 
| 292 | 
            +
            ```
         | 
| 293 | 
            +
            </details>
         | 
| 294 | 
            +
             | 
| 295 | 
            +
             | 
| 296 | 
            +
            <details>
         | 
| 297 | 
            +
              <summary>➡️ multi-turn</summary>
         | 
| 298 | 
            +
             | 
| 299 | 
            +
            ```python
         | 
| 300 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 301 | 
            +
            import torch
         | 
| 302 | 
            +
             | 
| 303 | 
            +
            device = "cuda"
         | 
| 304 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 305 | 
            +
             | 
| 306 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 307 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 308 | 
            +
             | 
| 309 | 
            +
            conversation = [
         | 
| 310 | 
            +
                {
         | 
| 311 | 
            +
                    "role": "user",
         | 
| 312 | 
            +
                    "content": [
         | 
| 313 | 
            +
                        {
         | 
| 314 | 
            +
                            "type": "audio",
         | 
| 315 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3",
         | 
| 316 | 
            +
                        },
         | 
| 317 | 
            +
                        {
         | 
| 318 | 
            +
                            "type": "audio",
         | 
| 319 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3",
         | 
| 320 | 
            +
                        },
         | 
| 321 | 
            +
                        {"type": "text", "text": "Describe briefly what you can hear."},
         | 
| 322 | 
            +
                    ],
         | 
| 323 | 
            +
                },
         | 
| 324 | 
            +
                {
         | 
| 325 | 
            +
                    "role": "assistant",
         | 
| 326 | 
            +
                    "content": "The audio begins with the speaker delivering a farewell address in Chicago, reflecting on his eight years as president and expressing gratitude to the American people. The audio then transitions to a weather report, stating that it was 35 degrees in Barcelona the previous day, but the temperature would drop to minus 20 degrees the following day.",
         | 
| 327 | 
            +
                },
         | 
| 328 | 
            +
                {
         | 
| 329 | 
            +
                    "role": "user",
         | 
| 330 | 
            +
                    "content": [
         | 
| 331 | 
            +
                        {
         | 
| 332 | 
            +
                            "type": "audio",
         | 
| 333 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
         | 
| 334 | 
            +
                        },
         | 
| 335 | 
            +
                        {"type": "text", "text": "Ok, now compare this new audio with the previous one."},
         | 
| 336 | 
            +
                    ],
         | 
| 337 | 
            +
                },
         | 
| 338 | 
            +
            ]
         | 
| 339 | 
            +
             | 
| 340 | 
            +
            inputs = processor.apply_chat_template(conversation)
         | 
| 341 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 342 | 
            +
             | 
| 343 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 344 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 345 | 
            +
             | 
| 346 | 
            +
            print("\nGenerated response:")
         | 
| 347 | 
            +
            print("=" * 80)
         | 
| 348 | 
            +
            print(decoded_outputs[0])
         | 
| 349 | 
            +
            print("=" * 80)
         | 
| 350 | 
            +
            ```
         | 
| 351 | 
            +
            </details>
         | 
| 352 | 
            +
             | 
| 353 | 
            +
             | 
| 354 | 
            +
            <details>
         | 
| 355 | 
            +
              <summary>➡️ text only</summary>
         | 
| 356 | 
            +
             | 
| 357 | 
            +
            ```python
         | 
| 358 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 359 | 
            +
            import torch
         | 
| 360 | 
            +
             | 
| 361 | 
            +
            device = "cuda"
         | 
| 362 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 363 | 
            +
             | 
| 364 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 365 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 366 | 
            +
             | 
| 367 | 
            +
            conversation = [
         | 
| 368 | 
            +
                {
         | 
| 369 | 
            +
                    "role": "user",
         | 
| 370 | 
            +
                    "content": [
         | 
| 371 | 
            +
                        {
         | 
| 372 | 
            +
                            "type": "text",
         | 
| 373 | 
            +
                            "text": "Why should AI models be open-sourced?",
         | 
| 374 | 
            +
                        },
         | 
| 375 | 
            +
                    ],
         | 
| 376 | 
            +
                }
         | 
| 377 | 
            +
            ]
         | 
| 378 | 
            +
             | 
| 379 | 
            +
            inputs = processor.apply_chat_template(conversation)
         | 
| 380 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 381 | 
            +
             | 
| 382 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 383 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 384 | 
            +
             | 
| 385 | 
            +
            print("\nGenerated response:")
         | 
| 386 | 
            +
            print("=" * 80)
         | 
| 387 | 
            +
            print(decoded_outputs[0])
         | 
| 388 | 
            +
            print("=" * 80)
         | 
| 389 | 
            +
            ```
         | 
| 390 | 
            +
            </details>
         | 
| 391 | 
            +
             | 
| 392 | 
            +
             | 
| 393 | 
            +
            <details>
         | 
| 394 | 
            +
              <summary>➡️ audio only</summary>
         | 
| 395 | 
            +
             | 
| 396 | 
            +
            ```python
         | 
| 397 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 398 | 
            +
            import torch
         | 
| 399 | 
            +
             | 
| 400 | 
            +
            device = "cuda"
         | 
| 401 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 402 | 
            +
             | 
| 403 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 404 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 405 | 
            +
             | 
| 406 | 
            +
            conversation = [
         | 
| 407 | 
            +
                {
         | 
| 408 | 
            +
                    "role": "user",
         | 
| 409 | 
            +
                    "content": [
         | 
| 410 | 
            +
                        {
         | 
| 411 | 
            +
                            "type": "audio",
         | 
| 412 | 
            +
                            "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
         | 
| 413 | 
            +
                        },
         | 
| 414 | 
            +
                    ],
         | 
| 415 | 
            +
                }
         | 
| 416 | 
            +
            ]
         | 
| 417 | 
            +
             | 
| 418 | 
            +
            inputs = processor.apply_chat_template(conversation)
         | 
| 419 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 420 | 
            +
             | 
| 421 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 422 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 423 | 
            +
             | 
| 424 | 
            +
            print("\nGenerated response:")
         | 
| 425 | 
            +
            print("=" * 80)
         | 
| 426 | 
            +
            print(decoded_outputs[0])
         | 
| 427 | 
            +
            print("=" * 80)
         | 
| 428 | 
            +
            ```
         | 
| 429 | 
            +
            </details>
         | 
| 430 | 
            +
             | 
| 431 | 
            +
             | 
| 432 | 
            +
            <details>
         | 
| 433 | 
            +
              <summary>➡️ batched inference</summary>
         | 
| 434 | 
            +
             | 
| 435 | 
            +
            ```python
         | 
| 436 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 437 | 
            +
            import torch
         | 
| 438 | 
            +
             | 
| 439 | 
            +
            device = "cuda"
         | 
| 440 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 441 | 
            +
             | 
| 442 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 443 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 444 | 
            +
             | 
| 445 | 
            +
            conversations = [
         | 
| 446 | 
            +
                [
         | 
| 447 | 
            +
                    {
         | 
| 448 | 
            +
                        "role": "user",
         | 
| 449 | 
            +
                        "content": [
         | 
| 450 | 
            +
                            {
         | 
| 451 | 
            +
                                "type": "audio",
         | 
| 452 | 
            +
                                "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3",
         | 
| 453 | 
            +
                            },
         | 
| 454 | 
            +
                            {
         | 
| 455 | 
            +
                                "type": "audio",
         | 
| 456 | 
            +
                                "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3",
         | 
| 457 | 
            +
                            },
         | 
| 458 | 
            +
                            {
         | 
| 459 | 
            +
                                "type": "text",
         | 
| 460 | 
            +
                                "text": "Who's speaking in the speach and what city's weather is being discussed?",
         | 
| 461 | 
            +
                            },
         | 
| 462 | 
            +
                        ],
         | 
| 463 | 
            +
                    }
         | 
| 464 | 
            +
                ],
         | 
| 465 | 
            +
                [
         | 
| 466 | 
            +
                    {
         | 
| 467 | 
            +
                        "role": "user",
         | 
| 468 | 
            +
                        "content": [
         | 
| 469 | 
            +
                            {
         | 
| 470 | 
            +
                                "type": "audio",
         | 
| 471 | 
            +
                                "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
         | 
| 472 | 
            +
                            },
         | 
| 473 | 
            +
                            {"type": "text", "text": "What can you tell me about this audio?"},
         | 
| 474 | 
            +
                        ],
         | 
| 475 | 
            +
                    }
         | 
| 476 | 
            +
                ],
         | 
| 477 | 
            +
            ]
         | 
| 478 | 
            +
             | 
| 479 | 
            +
            inputs = processor.apply_chat_template(conversations)
         | 
| 480 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 481 | 
            +
             | 
| 482 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 483 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 484 | 
            +
             | 
| 485 | 
            +
            print("\nGenerated responses:")
         | 
| 486 | 
            +
            print("=" * 80)
         | 
| 487 | 
            +
            for decoded_output in decoded_outputs:
         | 
| 488 | 
            +
                print(decoded_output)
         | 
| 489 | 
            +
                print("=" * 80)
         | 
| 490 | 
            +
            ```
         | 
| 491 | 
            +
            </details>
         | 
| 492 | 
            +
             | 
| 493 | 
            +
            #### Transcription
         | 
| 494 | 
            +
             | 
| 495 | 
            +
            <details>
         | 
| 496 | 
            +
              <summary>➡️ transcribe</summary>
         | 
| 497 | 
            +
             | 
| 498 | 
            +
            ```python
         | 
| 499 | 
            +
            from transformers import VoxtralForConditionalGeneration, AutoProcessor
         | 
| 500 | 
            +
            import torch
         | 
| 501 | 
            +
             | 
| 502 | 
            +
            device = "cuda"
         | 
| 503 | 
            +
            repo_id = "mistralai/Voxtral-Mini-3B-2507"
         | 
| 504 | 
            +
             | 
| 505 | 
            +
            processor = AutoProcessor.from_pretrained(repo_id)
         | 
| 506 | 
            +
            model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
         | 
| 507 | 
            +
             | 
| 508 | 
            +
            inputs = processor.apply_transcrition_request(language="en", audio="https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3", model_id=repo_id)
         | 
| 509 | 
            +
            inputs = inputs.to(device, dtype=torch.bfloat16)
         | 
| 510 | 
            +
             | 
| 511 | 
            +
            outputs = model.generate(**inputs, max_new_tokens=500)
         | 
| 512 | 
            +
            decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
         | 
| 513 | 
            +
             | 
| 514 | 
            +
            print("\nGenerated responses:")
         | 
| 515 | 
            +
            print("=" * 80)
         | 
| 516 | 
            +
            for decoded_output in decoded_outputs:
         | 
| 517 | 
            +
                print(decoded_output)
         | 
| 518 | 
            +
                print("=" * 80)
         | 
| 519 | 
            +
            ```
         | 
| 520 | 
            +
            </details>
         | 

