vllm.model_executor.models.pixtral
¶
Classes:
-
PatchMerger–Learned merging of spatial_merge_size ** 2 patches.
-
PixtralEncoderCudaGraphMixin–Encoder CUDA graph support for models built on a Pixtral vision tower.
-
PixtralForConditionalGeneration– -
PixtralHFVisionModel– -
PixtralImagePixelInputs–Dimensions:
-
VisionTransformer–
Functions:
-
apply_rotary_emb_vit–Rotate
xq/xkof shape (bsz, seq_len, n_heads, head_dim). -
pack_image_patches–Pack CHW images into one (num_patches, C * ph * pw) tensor.
-
pixtral_patch_embed–Normalize and project all CHW images in one matrix multiplication.
-
precompute_freqs_cis_2d–freqs_cis: 2D complex tensor of shape (height, width, dim // 2)
PatchMerger
¶
Bases: Module
Learned merging of spatial_merge_size ** 2 patches.
Methods:
-
forward_packed–Same as
forward, gathering blocks with_make_merge_indices. -
permute–Args:
Source code in vllm/model_executor/models/pixtral.py
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 | |
forward_packed(x, merge_indices)
¶
Same as forward, gathering blocks with _make_merge_indices.
Source code in vllm/model_executor/models/pixtral.py
permute(x, image_sizes)
¶
Parameters:
-
(x¶Tensor) –(N, D) where N is flattened and concatenated patch tokens for all images
-
(image_sizes¶list[tuple[int, int]]) –list of tuple of (height, width) in tokens for each image
Returns: image_features: reorders patch tokens so each grid of (spatial_merge_size, spatial_merge_size) is contiguous. now (N / spatial_merge_size ** 2, D * spatial_merge_size ** 2)
Source code in vllm/model_executor/models/pixtral.py
PixtralEncoderCudaGraphMixin
¶
Bases: SupportsEncoderCudaGraph
Encoder CUDA graph support for models built on a Pixtral vision tower.
All images of a batch are packed into one patch sequence. Capture buffers
are sized for the token budget, and the batch is padded with zero-length
sequences up to max_batch_size, so replays only copy fresh values into
fixed-shape buffers.
Methods:
-
project_packed_image_features–Map (N_patches, D) tower features to language model embeddings.
Attributes:
-
encoder_cudagraph_spatial_merge_size(int) –Patches merged per side by the projector, 1 when not merging.
Source code in vllm/model_executor/models/pixtral.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
PixtralForConditionalGeneration
¶
Bases: Module, SupportsLoRA, SupportsEagle3, SupportsMultiModal, SupportsPP, PixtralEncoderCudaGraphMixin
Methods:
-
forward–Run forward pass for pixtral.
Source code in vllm/model_executor/models/pixtral.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | |
forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)
¶
Run forward pass for pixtral.
Source code in vllm/model_executor/models/pixtral.py
PixtralHFVisionModel
¶
Bases: Module
Methods:
-
forward–Args:
-
forward_packed–Encode images packed by
pack_image_patches.
Attributes:
-
encoder_attention(MMEncoderAttention) –Attention of the first layer; all layers share its settings.
Source code in vllm/model_executor/models/pixtral.py
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 | |
encoder_attention
property
¶
Attention of the first layer; all layers share its settings.
forward(pixel_values, *, select_layers=None, feature_select_strategy=None)
¶
Parameters:
-
(pixel_values¶list[Tensor]) –Each image to be processed will be a separate tensor in pixel_values. This means it will be a list of tensors because multiple requests batched can have multiple images, each with their own shape potentially
-
(select_layers¶list[int] | None, default:None) –Layer indices whose features should be concatenated and used as the visual encoder output. If none are provided, the last layer is used.
Returns:
-
image_features(tuple[Tensor, ...]) –tensor of token features for all tokens of all images of shape (N_toks, D)
Source code in vllm/model_executor/models/pixtral.py
forward_packed(patches, positions, cu_seqlens, max_seqlen, sequence_lengths, *, select_layers=None, feature_select_strategy=None)
¶
Encode images packed by pack_image_patches.
patches holds (N_toks, C * patch_size**2) pixel patches (raw pixels
when input_norm normalizes on device) and positions their
(N_toks, 2) (row, col) coordinates; the attention arguments come from
packed_attention_metadata. Returns (N_toks, D) token features.
Source code in vllm/model_executor/models/pixtral.py
PixtralImagePixelInputs
¶
Bases: TensorSchema
Dimensions
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height of each image
- w: Width of each image
The result of stacking ImageEncoding.tokens from each prompt.
Source code in vllm/model_executor/models/pixtral.py
VisionTransformer
¶
Bases: Module
Methods:
-
forward–Args:
-
forward_packed–Encode images packed by
pack_image_patches.
Attributes:
-
encoder_attention(MMEncoderAttention) –Attention of the first layer; all layers share its settings.
Source code in vllm/model_executor/models/pixtral.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 | |
encoder_attention
property
¶
Attention of the first layer; all layers share its settings.
forward(images)
¶
Parameters:
Returns:
Source code in vllm/model_executor/models/pixtral.py
forward_packed(patches, positions, cu_seqlens, max_seqlen, sequence_lengths)
¶
Encode images packed by pack_image_patches.
patches holds (N_toks, C * patch_size**2) pixel patches and
positions their (N_toks, 2) (row, col) coordinates; the attention
arguments come from packed_attention_metadata. Returns (N_toks, D)
token features.
Source code in vllm/model_executor/models/pixtral.py
_make_merge_indices(grid_sizes, spatial_merge_size, device)
¶
Indices gathering each spatial_merge_size^2 patch block of the packed
sequence into one row, matching the patch mergers' unfold order.
Source code in vllm/model_executor/models/pixtral.py
_make_packed_sequence_metadata(sequence_lengths, attn_backend, hidden_size, tp_size, device, *, num_sequences=None, fp8_padded_hidden_size=None)
¶
Build varlen attention metadata for images packed in one sequence.
num_sequences pads the batch with zero-length sequences, which keeps the
metadata shapes fixed for encoder CUDA graphs while attention does no work
for the padding rows.
Source code in vllm/model_executor/models/pixtral.py
_patch_grid_positions(grid_sizes, device)
¶
(row, col) coordinates of every patch, packed as (num_patches, 2).
Source code in vllm/model_executor/models/pixtral.py
apply_rotary_emb_vit(xq, xk, freqs_cis)
¶
Rotate xq/xk of shape (bsz, seq_len, n_heads, head_dim).
freqs_cis is the real view (seq_len, head_dim / 2, 2) of the complex
frequencies.
Source code in vllm/model_executor/models/pixtral.py
pack_image_patches(images, patch_shape)
¶
Pack CHW images into one (num_patches, C * ph * pw) tensor.
Patches are laid out row-major per image, with each row flattened in the (C, ph, pw) order of a patch convolution weight. Returns the packed tensor and the (rows, cols) patch grid of every image.
Source code in vllm/model_executor/models/pixtral.py
pixtral_patch_embed(images, weight, input_norm)
¶
Normalize and project all CHW images in one matrix multiplication.
Source code in vllm/model_executor/models/pixtral.py
precompute_freqs_cis_2d(dim, height, width, theta)
¶
freqs_cis: 2D complex tensor of shape (height, width, dim // 2) to be indexed by (height, width) position tuples