vllm.config.compilation
¶
Classes:
-
CUDAGraphMode–Constants for the cudagraph mode in CompilationConfig.
-
CompilationConfig–Configuration for compilation.
-
CompilationMode–The compilation approach used for torch.compile-based compilation of the
-
DynamicShapesConfig–Configuration to control/debug torch compile dynamic shapes.
-
DynamicShapesType–Types of dynamic shapes handling in torch.compile().
-
PassConfig–Configuration for custom Inductor passes.
Functions:
-
decode_cudagraph_capture_grid–The request-count grid up to
max_requests: every count up to 6, then a -
decode_cudagraph_capture_max_tokens–The most tokens a uniform decode graph holds: the recorded max, which
-
decode_cudagraph_capture_shapes–The
(num_reqs, query_len)uniform decode graphs for the request counts -
prefill_cudagraph_capture_grid–The token-count grid up to
max_tokens: 1, 2, 4, every 8 up to 64, four -
varlen_decode_cudagraph_capture_grid–The token-count grid of adaptive verification's decode graphs: 1, 2, 4
CUDAGraphMode
¶
Bases: Enum
Constants for the cudagraph mode in CompilationConfig.
Meanwhile, the subset enum NONE, PIECEWISE and FULL are also
treated as concrete runtime mode for cudagraph runtime dispatching.
Source code in vllm/config/compilation.py
CompilationConfig
¶
Configuration for compilation.
You must pass CompilationConfig to VLLMConfig constructor. VLLMConfig's post_init does further initialization. If used outside of the VLLMConfig, some fields will be left in an improper state.
It contains PassConfig, which controls the custom fusion/transformation passes. The rest has three parts:
- Top-level Compilation control:
- CudaGraph capture:
- Inductor compilation:
compile_sizes- [
compile_ranges_endpoints] [vllm.config.CompilationConfig.compile_ranges_endpoints] inductor_compile_configinductor_passes- custom inductor passes
Why we have different sizes for cudagraph and inductor: - cudagraph: a cudagraph captured for a specific size can only be used for the same size. We need to capture all the sizes we want to use. - inductor: a graph compiled by inductor for a general shape can be used for different sizes. Inductor can also compile for specific sizes, where it can have more information to optimize the graph with fully static shapes. However, we find the general shape compilation is sufficient for most cases. It might be beneficial to compile for certain small batchsizes, where inductor is good at optimizing.
Methods:
-
compute_hash–Provide a hash that uniquely identifies all the configs
-
custom_op_log_check–This method logs the enabled/disabled custom ops and checks that the
-
get_compile_ranges–Get the compile ranges for the compilation config.
-
init_backend–Initialize the backend for the compilation config from a vllm config.
-
post_init_cudagraph_sizes–To complete the initialization after cudagraph related
-
validate_cudagraph_mode_before–Enable parsing of the
cudagraph_modeenum type from string. -
validate_mode_before–Enable parsing the
modefield from string mode names. -
validate_pass_config_before–Enable parsing of the
pass_configfield from a dictionary.
Attributes:
-
backend(str) –The backend for compilation. It needs to be a string:
-
cache_dir(str) –The directory to store the compiled graph, to accelerate Inductor
-
compilation_time(float) –time taken for compilation
-
compile_cache_save_format(Literal['binary', 'unpacked']) –Format for saving torch compile cache:
-
compile_mm_encoder(bool) –Whether or not to compile the multimodal encoder.
-
compile_ranges_endpoints(list[int] | None) –Endpoints for Inductor compile ranges.
-
compile_sizes(list[int | str] | None) –Sizes to compile for inductor. In addition
-
cudagraph_capture_sizes(list[int]) –Sizes to capture cudagraph.
-
cudagraph_copy_inputs(bool) –Whether to copy input tensors for
-
cudagraph_decoder_replay(bool) –Run the decoder replay layers of YOCO models (e.g. DeepSeek-V4.1) in CUDA
-
cudagraph_mm_encoder(bool) –Enable CUDA graph capture for multimodal encoder (ViT).
-
cudagraph_mode(CUDAGraphMode) –The mode of the cudagraph:
-
cudagraph_num_of_warmups(int) –Number of warmup runs for cudagraph.
-
cudagraph_specialize_lora(bool) –Whether to create separate cuda graphs for cases with and without active
-
custom_ops(list[str]) –Fine-grained control over which custom ops to enable/disable. Use 'all'
-
debug_dump_path(Path | None) –The path to dump the debug information.
-
decode_cudagraph_capture_request_sizes(list[int] | None) –Request counts of the FULL CUDA graphs for uniform decode batches, whose
-
decoder_replay_cudagraph_capture_sizes(list[int]) –Decoder replay CUDA graph sizes for YOCO models (e.g. DeepSeek-V4.1), at
-
decoder_replay_trim_threshold(int) –For YOCO models (e.g. DeepSeek-V4.1), PIECEWISE graphs with at least this
-
disabled_custom_ops(Counter[str]) –custom ops that are disabled
-
dynamic_shapes_config(DynamicShapesConfig) –Configuration for dynamic shapes options
-
enabled_custom_ops(Counter[str]) –custom ops that are enabled
-
encoder_compilation_time(float) –time taken for multimodal encoder compilation
-
encoder_cudagraph_max_frames_per_batch(int | None) –Maximum total video frames per batch for encoder CUDA graph capture.
-
encoder_cudagraph_max_vision_items_per_batch(int) –Maximum number of images/videos per batch for encoder CUDA graph capture.
-
encoder_cudagraph_token_budgets(list[int]) –Token budget levels for encoder CUDA graph capture.
-
fast_moe_cold_start(bool | None) –Optimization for fast MOE cold start.
-
inductor_compile_config(dict) –Additional configurations for inductor.
-
inductor_passes(dict[str, str]) –Additional passes for inductor. It is a dictionary
-
ir_enable_torch_wrap(bool) –If True, enable vllm_ir torch custom op wrapping during the forward pass.
-
local_cache_dir(str) –local cache dir for each rank
-
max_cudagraph_capture_size(int) –The maximum cudagraph capture size.
-
max_decode_cudagraph_capture_requests(int | None) –Largest request count of a decode CUDA graph; with adaptive verification
-
max_decode_cudagraph_capture_tokens(int | None) –Token budget of a uniform decode CUDA graph: each runner captures
n -
max_prefill_cudagraph_capture_tokens(int | None) –Largest token count of a prefill CUDA graph. None (default): 8192 on SM100
-
mode(CompilationMode) –The compilation approach used for torch.compile-based compilation of the
-
pass_config(PassConfig) –Custom inductor passes, see PassConfig for more details
-
prefill_cudagraph_capture_token_sizes(list[int] | None) –Token counts of the CUDA graphs for prefill batches: every batch that is
-
splitting_ops(list[str] | None) –A list of ops to exclude from cudagraphs, used in piecewise compilation.
-
static_all_moe_layers(list[str]) –The names of all the MOE layers in the model
-
static_forward_context(dict[str, Any]) –Per-model forward context
-
traced_files(set[str]) –files that are traced for compilation
-
use_breakable_cudagraph(bool | None) –Whether to use breakable CUDA graphs (runtime stream-capture breaks
-
use_inductor_graph_partition(bool) –Use inductor graph partition to split the graph at cudagraph_unsafe ops.
Source code in vllm/config/compilation.py
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 588 589 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 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 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 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 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 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | |
backend = ''
class-attribute
instance-attribute
¶
The backend for compilation. It needs to be a string:
- "" (empty string): use the default backend ("inductor" on CUDA-alike platforms).
- "eager"/"openxla"/...: use the specified backend registered in PyTorch.
- "full.module.name": a qualified name which can be used to import the
backend function.
We use string to avoid serialization issues when using compilation in a
distributed setting. When the compilation mode is 1 or 2, the backend is
used for the compilation directly (it sees the whole graph). When the
compilation mode is 3, the backend supports both whole graph and piecewise
compilation, available backends include eager, inductor, and custom backends,
the latter of which can be defined via get_compile_backend. Furthermore,
compilation is only piecewise if splitting ops is set accordingly and
use_inductor_graph_partition is off. Note that the default options for
splitting ops are sufficient for piecewise compilation.
cache_dir = ''
class-attribute
instance-attribute
¶
The directory to store the compiled graph, to accelerate Inductor compilation. By default, it will use model-related information to generate a cache directory.
compilation_time = field(default=0.0, init=False)
class-attribute
instance-attribute
¶
time taken for compilation
compile_cache_save_format = field(default_factory=lambda: envs.VLLM_COMPILE_CACHE_SAVE_FORMAT)
class-attribute
instance-attribute
¶
Format for saving torch compile cache:
-
"binary": saves as binary file (multiprocess safe)
-
"unpacked": saves as directory structure for inspection/debugging (NOT multiprocess safe)
Defaults to VLLM_COMPILE_CACHE_SAVE_FORMAT if not specified.
compile_mm_encoder = False
class-attribute
instance-attribute
¶
Whether or not to compile the multimodal encoder.
Currently, this only works for Qwen2_5_vl and mLLaMa4 models on selected
platforms. It may also work for models loaded with the Transformers modeling backend
if the encoder is compilable. Disabled by default until more models are
supported/tested to work.
compile_ranges_endpoints = None
class-attribute
instance-attribute
¶
Endpoints for Inductor compile ranges. The compile ranges are [1, endpoints[0]], [endpoints[0] + 1, endpoints[1]], ..., [endpoints[-1] + 1, max_num_batched_tokens]. Compile sizes are also used single element ranges, the range is represented as [compile_sizes[i], compile_sizes[i]].
If a range overlaps with the compile size, graph for compile size will be prioritized, i.e. if we have a range [1, 8] and a compile size 4, graph for compile size 4 will be compiled and used instead of the graph for range [1, 8].
compile_sizes = None
class-attribute
instance-attribute
¶
Sizes to compile for inductor. In addition to integers, it also supports "cudagraph_capture_sizes" to specify the sizes for cudagraph capture.
cudagraph_capture_sizes = None
class-attribute
instance-attribute
¶
Sizes to capture cudagraph. - None (default): capture sizes are inferred from vllm config. - list[int]: capture sizes are specified as given.
Deprecated with model runner V2, which takes
prefill_cudagraph_capture_token_sizes and
decode_cudagraph_capture_request_sizes instead. Set there, these token
counts are the prefill sizes and, rounded up to whole requests of the target
model's query length, the decode sizes. After config resolution it holds the
token count of every captured graph.
cudagraph_copy_inputs = False
class-attribute
instance-attribute
¶
Whether to copy input tensors for cudagraph. If the caller can guarantee that the same input buffers are always used, it can set this to False. Otherwise, it should set this to True, and the compiler will copy the input to an internally managed buffer. Default is False. Note that this flag is only effective when cudagraph_mode is PIECEWISE.
cudagraph_decoder_replay = True
class-attribute
instance-attribute
¶
Run the decoder replay layers of YOCO models (e.g. DeepSeek-V4.1) in CUDA graphs of their own, and trim them in PIECEWISE graph steps. Requires breakable PIECEWISE graphs; off under LoRA, prompt embeddings and non-first PP ranks.
cudagraph_mm_encoder = False
class-attribute
instance-attribute
¶
Enable CUDA graph capture for multimodal encoder (ViT). When enabled, captures full encoder forward as CUDA graph for each token budget level.
cudagraph_mode = None
class-attribute
instance-attribute
¶
The mode of the cudagraph:
- NONE, no cudagraph capture.
- PIECEWISE.
- FULL.
- FULL_DECODE_ONLY.
- FULL_AND_PIECEWISE. (v1 default)
PIECEWISE mode build piecewise cudagraph only, keeping the cudagraph incompatible ops (i.e. some attention ops) outside the cudagraph for general flexibility.
FULL mode: Capture full cudagraph for all batches. Can be good for small models or workloads with small prompts; not supported by many backends. Generally for performance FULL_AND_PIECEWISE is better.
FULL_DECODE_ONLY mode: Capture full cudagraph for decode batches only. Mixed prefill-decode batches are run without cudagraphs. Can be good for decode instances in a P/D setup where prefill is not as important so we can save some memory.
FULL_AND_PIECEWISE mode: Capture full cudagraph for decode batches and piecewise cudagraph for prefill and mixed prefill-decode batches. This is the most performant mode for most models and is the default.
Currently, the cudagraph mode is only used for the v1 engine. Note that the cudagraph logic is generally orthogonal to the compilation logic. While piecewise cudagraphs require piecewise compilation (mode=VLLM_COMPILE and non-empty splitting_ops), full cudagraphs are supported with and without compilation.
Warning: This flag is new and subject to change in addition more modes may be added.
cudagraph_num_of_warmups = 0
class-attribute
instance-attribute
¶
Number of warmup runs for cudagraph. It means the first several runs will be treated as warmup runs. Only after that, the execution will be recorded, and the recorded cudagraph will be used for subsequent runs.
cudagraph_specialize_lora = True
class-attribute
instance-attribute
¶
Whether to create separate cuda graphs for cases with and without active
LoRA adapters. When set to False, the LoRA-enabled cuda graph will be used
for all cases, incurring the overhead of running LoRA ops even when no
adapters are active. Setting this to True will remove this overhead at the
cost of increased startup time and slightly higher memory usage.
When enable_lora is False, this option has no effect.
custom_ops = field(default_factory=list)
class-attribute
instance-attribute
¶
Fine-grained control over which custom ops to enable/disable. Use 'all' to enable all, 'none' to disable all. Also specify a list of custom op names to enable (prefixed with a '+'), or disable (prefixed with a '-'). Examples:
- 'all,-op1' to enable all except op1
- 'none,+op1,+op2' to enable only op1 and op2
By default, all custom ops are enabled when running without Inductor and disabled when running with Inductor: mode>CompilationMode.NONE and backend="inductor". Inductor generates (fused) Triton kernels for disabled custom ops.
debug_dump_path = None
class-attribute
instance-attribute
¶
The path to dump the debug information.
decode_cudagraph_capture_request_sizes = None
class-attribute
instance-attribute
¶
Request counts of the FULL CUDA graphs for uniform decode batches, whose
requests all have the same query length q: 1 + num_speculative_tokens
for the target model, K or K + 1 for DSpark, DFlash and multi-module MTP
drafters. A runner captures n requests as n * q tokens, for each n up
to the most requests its batches have and the recorded
max_cudagraph_capture_size // q. One-token draft decodes (EAGLE, EAGLE3, MTP)
take the request-count grid up to max_num_seqs instead. [] captures none.
None (default): the request-count grid up to
max_decode_cudagraph_capture_requests.
With adaptive verification, the target model's decode batches mix query
lengths, so they take token-keyed FULL graphs instead: the token-count grid
up to max_decode_cudagraph_capture_requests * (1 + num_speculative_tokens)
tokens, within max_decode_cudagraph_capture_tokens. These request counts
then set the draft decode graphs alone.
decoder_replay_cudagraph_capture_sizes = field(default_factory=list)
class-attribute
instance-attribute
¶
Decoder replay CUDA graph sizes for YOCO models (e.g. DeepSeek-V4.1), at most max_num_batched_tokens. If empty: multiples of sliding_window up to min(max_cudagraph_capture_size, max_num_seqs * sliding_window), coarser past 16 * sliding_window. Larger replay batches run eagerly.
decoder_replay_trim_threshold = Field(default=768, ge=0)
class-attribute
instance-attribute
¶
For YOCO models (e.g. DeepSeek-V4.1), PIECEWISE graphs with at least this many padded tokens trim the decoder replay batch; must exceed the replay window (128), below which nothing trims. Independent of the replay graph capture sizes; eager steps still trim.
disabled_custom_ops = field(default_factory=Counter, init=False)
class-attribute
instance-attribute
¶
custom ops that are disabled
dynamic_shapes_config = field(default_factory=DynamicShapesConfig)
class-attribute
instance-attribute
¶
Configuration for dynamic shapes options
enabled_custom_ops = field(default_factory=Counter, init=False)
class-attribute
instance-attribute
¶
custom ops that are enabled
encoder_compilation_time = field(default=0.0, init=False)
class-attribute
instance-attribute
¶
time taken for multimodal encoder compilation
encoder_cudagraph_max_frames_per_batch = None
class-attribute
instance-attribute
¶
Maximum total video frames per batch for encoder CUDA graph capture.
Controls the cu_seqlens buffer size (one entry per attention sequence,
i.e. one per video frame).
If None (default), auto-inferred as encoder_cudagraph_max_vision_items_per_batch
* max_frames_per_video (model-specific value according to processing_info).
Positive value overrides auto-inference and applies to all budget levels.
If we limit the video count per prompt to 0, it will also be set to 0
(i.e., fall back to image-only mode).
encoder_cudagraph_max_vision_items_per_batch = 0
class-attribute
instance-attribute
¶
Maximum number of images/videos per batch for encoder CUDA graph capture. Determines the fixed batch size used during graph capture. If 0 (default), auto-inferred as max_budget // min_budget from the model's budget range. User-provided positive value overrides auto-inference.
encoder_cudagraph_token_budgets = field(default_factory=list)
class-attribute
instance-attribute
¶
Token budget levels for encoder CUDA graph capture. Each budget defines a fixed token capacity. At runtime, images are greedy-packed into the smallest fitting budget and the corresponding CUDA graph is replayed. If empty (default), auto-inferred from model architecture as power-of-2 levels from the model's estimated min budget to max budget. User-provided values override auto-inference. Example: [2048, 4096, 8192, 13824]
fast_moe_cold_start = None
class-attribute
instance-attribute
¶
Optimization for fast MOE cold start.
This is a bit of a hack that assumes that: 1. the only decoder forward pass being run is the current model 2. the decoder forward pass runs all of the MOEs in the order in which they are initialized
When the above two conditions hold, this option greatly decreases cold start time for MOE models.
The options are: - True: optimization is always on - False: optimization is always off - None: optimization is on usually but off for speculative decoding
If conditions 1&2 don't hold then this option will lead to silent incorrectness. The only condition in which this doesn't hold is speculative decoding, where there is a draft model that may have MOEs in them.
NB: We're working on a longer-term solution that doesn't need these assumptions.
inductor_compile_config = field(default_factory=dict)
class-attribute
instance-attribute
¶
Additional configurations for inductor. - None: use default configurations.
inductor_passes = field(default_factory=dict)
class-attribute
instance-attribute
¶
Additional passes for inductor. It is a dictionary
from pass name to pass function qualified name. We use function
name because the config uses JSON format. If we pass the config
from Python, functions can also be passed directly via Python object
constructor, e.g. CompilationConfig(inductor_passes={"a": func}).
ir_enable_torch_wrap = None
class-attribute
instance-attribute
¶
If True, enable vllm_ir torch custom op wrapping during the forward pass. When False, torch custom op wrapping is disabled, allowing Dynamo to trace the selected implementation directly or avoiding torch custom op overhead in eager mode. Defaults to True when using Inductor with vllm-compile (backend=="inductor" and mode == VLLM_COMPILE), False otherwise.
local_cache_dir = field(default=None, init=False)
class-attribute
instance-attribute
¶
local cache dir for each rank
max_cudagraph_capture_size = None
class-attribute
instance-attribute
¶
The maximum cudagraph capture size.
If cudagraph_capture_sizes is specified, this will be set to the largest size in that list (or checked for consistency if specified). If cudagraph_capture_sizes is not specified, the list of sizes is generated automatically following the pattern:
[1, 2, 4] + list(range(8, 256, 8)) + list(
range(256, max_cudagraph_capture_size + 1, 16))
If not specified, max_cudagraph_capture_size is capped at 512 by default, or 1024 on data center Blackwell GPUs. This avoids OOM in tight memory scenarios with small max_num_seqs, and limits capture of large graphs that increase startup time and memory usage. Uniform decode sizes are appended only within this default ceiling.
Deprecated with model runner V2, which takes
max_prefill_cudagraph_capture_tokens (tokens) and
max_decode_cudagraph_capture_requests (requests) instead. After config
resolution it holds the token count of the widest captured graph.
max_decode_cudagraph_capture_requests = Field(default=None, ge=0)
class-attribute
instance-attribute
¶
Largest request count of a decode CUDA graph; with adaptive verification
it also bounds the verify graphs' tokens (see
decode_cudagraph_capture_request_sizes). None (default): max_num_seqs on
SM100 GPUs, otherwise the most requests that the platform's default
max_cudagraph_capture_size holds at the target model's query lengths.
Graphs no wider than the widest prefill graph mostly reuse its memory in the
shared graph pool. Wider graphs, and FULL graphs of
models with large per-token buffers (e.g. DeepSeek's indexer at a long
max_model_len), take memory from the KV cache.
max_decode_cudagraph_capture_tokens = Field(default=None, ge=1)
class-attribute
instance-attribute
¶
Token budget of a uniform decode CUDA graph: each runner captures n
requests at query length q only while n * q fits, and wider decode
batches take the prefill graphs. It also bounds adaptive verification's
token-keyed graphs. None (default): 8192 on SM100 GPUs, otherwise no budget.
Wider decode graphs take memory from the KV cache.
max_prefill_cudagraph_capture_tokens = Field(default=None, ge=0)
class-attribute
instance-attribute
¶
Largest token count of a prefill CUDA graph. None (default): 8192 on SM100
GPUs, otherwise the platform's default max_cudagraph_capture_size; at most
max_num_batched_tokens. More and wider graphs take memory from the KV
cache and lengthen startup.
mode = None
class-attribute
instance-attribute
¶
The compilation approach used for torch.compile-based compilation of the model.
- None: If None, we will select the default compilation mode. For V1 engine this is 3.
- 0: NONE: No torch.compile compilation is applied, model runs in fully eager pytorch mode. The model runs as-is.
- 1: STOCK_TORCH_COMPILE: The standard
torch.compilecompilation pipeline. - 2: DYNAMO_TRACE_ONCE: Single Dynamo trace through the model, avoiding recompilation by removing guards. Requires no dynamic-shape-dependent control-flow.
- 3: VLLM_COMPILE: Custom vLLM Inductor-based backend with caching, piecewise compilation, shape specialization, and custom passes.
pass_config = field(default_factory=PassConfig)
class-attribute
instance-attribute
¶
Custom inductor passes, see PassConfig for more details
prefill_cudagraph_capture_token_sizes = None
class-attribute
instance-attribute
¶
Token counts of the CUDA graphs for prefill batches: every batch that is
not a uniform decode batch, i.e. one with a prefill or with requests of
different query lengths, and every batch when cudagraph_mode is FULL or
PIECEWISE. Decode batches under adaptive verification are the exception;
see decode_cudagraph_capture_request_sizes. [] captures none, and sizes
above max_num_batched_tokens are dropped. None (default): the token-count
grid up to max_prefill_cudagraph_capture_tokens.
splitting_ops = None
class-attribute
instance-attribute
¶
A list of ops to exclude from cudagraphs, used in piecewise compilation.
The behavior depends on use_inductor_graph_partition:
-
When use_inductor_graph_partition=False (default): These ops are used for Dynamo FX-level graph splitting. The graph is split at these ops before Inductor compilation, creating separate subgraphs for cudagraph capture.
-
When use_inductor_graph_partition=True: These ops are used to register Inductor partition rules. The graph partitioning happens at Inductor codegen time after all passes and fusions are finished, allowing compilation and custom passes to operate on the full graph while still excluding these ops from cudagraphs.
If None, defaults to attention ops for piecewise cudagraphs. If empty list [], no ops are excluded (suitable for full cudagraphs).
static_all_moe_layers = field(default_factory=list, init=False)
class-attribute
instance-attribute
¶
The names of all the MOE layers in the model
static_forward_context = field(default_factory=dict, init=False)
class-attribute
instance-attribute
¶
Per-model forward context Map from layer name to layer objects that need to be accessed outside model code, e.g., Attention, FusedMOE when dp_size>1.
traced_files = field(default_factory=set, init=False)
class-attribute
instance-attribute
¶
files that are traced for compilation
use_breakable_cudagraph = None
class-attribute
instance-attribute
¶
Whether to use breakable CUDA graphs (runtime stream-capture breaks instead of torch.compile FX graph splitting).
Resolved by VllmConfig.post_init: an explicit VLLM_USE_BREAKABLE_CUDAGRAPH env var takes precedence, otherwise it is auto-enabled for breakable-by-default architectures (and for tuned batch-invariant setups). None means unresolved; readers fall back to envs.VLLM_USE_BREAKABLE_CUDAGRAPH so standalone CompilationConfig users keep working. Stored per-config (and pickled to workers) rather than written back to os.environ.
use_inductor_graph_partition = None
class-attribute
instance-attribute
¶
Use inductor graph partition to split the graph at cudagraph_unsafe ops.
This partition happens at inductor codegen time after all passes and fusions
are finished. It generates a single call function which wraps
cudagraph-safe ops into partition functions and leave cudagraph-unsafe ops
outside the partition functions. For a graph with N cudagraph-unsafe ops
(e.g., Attention), there would be N+1 partitions. To mark an op as
cudagraph unsafe, we can add tags=(torch._C.Tag.cudagraph_unsafe) when
register the custom op.
This config supports both full cudagraph and piecewise cudagraph without compiling twice. For piecewise cudagraph, it applies vLLM CUDAGraph wrapper to each partition. For N+1 partitions, there would be N+1 CUDAGraph wrapper instances.
For full CUDAGraph, we always apply a single CUDAGraph wrapper outside the
inductor call function in the model runner. The top-level full cudagraph
capture ignores all partitioning.
_skip_none_validation(value, handler)
classmethod
¶
Skip validation if the value is None when initialisation is delayed.
Source code in vllm/config/compilation.py
compute_hash()
¶
Provide a hash that uniquely identifies all the configs that affect the structure of the computation graph from input ids/embeddings to the final hidden states, excluding anything before input ids/embeddings and after the final hidden states.
Source code in vllm/config/compilation.py
custom_op_log_check()
¶
This method logs the enabled/disabled custom ops and checks that the passed custom_ops field only contains relevant ops. It is called at the end of set_current_vllm_config, after the custom ops have been instantiated.
Source code in vllm/config/compilation.py
get_compile_ranges()
¶
Get the compile ranges for the compilation config.
Source code in vllm/config/compilation.py
init_backend(vllm_config, prefix='', is_encoder=False, use_aot_compile=True)
¶
Initialize the backend for the compilation config from a vllm config.
Parameters:
-
(vllm_config¶VllmConfig) –The vllm config to initialize the backend from.
-
(prefix¶str, default:'') –Cache directory prefix for this compiled module.
-
(is_encoder¶bool, default:False) –Whether this module is used in an encoder (as opposed to a text backbone).
-
(use_aot_compile¶bool, default:True) –Whether the module permits AOT and direct artifacts.
Returns:
Source code in vllm/config/compilation.py
post_init_cudagraph_sizes()
¶
To complete the initialization after cudagraph related configs are set. This includes: - initialize compile_sizes
Source code in vllm/config/compilation.py
validate_cudagraph_mode_before(value)
classmethod
¶
Enable parsing of the cudagraph_mode enum type from string.
Source code in vllm/config/compilation.py
validate_mode_before(value)
classmethod
¶
Enable parsing the mode field from string mode names.
Accepts both integers (0-3) and string names, like NONE, STOCK_TORCH_COMPILE,
DYNAMO_TRACE_ONCE, VLLM_COMPILE.
Source code in vllm/config/compilation.py
validate_pass_config_before(value)
classmethod
¶
Enable parsing of the pass_config field from a dictionary.
Source code in vllm/config/compilation.py
CompilationMode
¶
Bases: IntEnum
The compilation approach used for torch.compile-based compilation of the model.
Attributes:
-
DYNAMO_TRACE_ONCE–Single Dynamo trace through the model, avoiding recompilation.
-
NONE–No torch.compile compilation is applied, model runs in fully eager pytorch mode.
-
STOCK_TORCH_COMPILE–The standard
torch.compilecompilation pipeline. -
VLLM_COMPILE–Custom vLLM Inductor-based backend with caching, piecewise compilation,
Source code in vllm/config/compilation.py
DYNAMO_TRACE_ONCE = 2
class-attribute
instance-attribute
¶
Single Dynamo trace through the model, avoiding recompilation.
NONE = 0
class-attribute
instance-attribute
¶
No torch.compile compilation is applied, model runs in fully eager pytorch mode. The model runs as-is.
STOCK_TORCH_COMPILE = 1
class-attribute
instance-attribute
¶
The standard torch.compile compilation pipeline.
VLLM_COMPILE = 3
class-attribute
instance-attribute
¶
Custom vLLM Inductor-based backend with caching, piecewise compilation, shape specialization, and custom passes.
DynamicShapesConfig
¶
Configuration to control/debug torch compile dynamic shapes.
Methods:
-
compute_hash–Provide a hash for DynamicShapesConfig.
Attributes:
-
assume_32_bit_indexing(bool) –whether all tensor sizes can use 32 bit indexing.
-
evaluate_guards(bool) –A debug mode to detect and fail if Dynamo ever specializes a dynamic shape by
-
type(DynamicShapesType) –Controls the type of dynamic shapes handling to use with torch.compile().
Source code in vllm/config/compilation.py
assume_32_bit_indexing = False
class-attribute
instance-attribute
¶
whether all tensor sizes can use 32 bit indexing.
True requires PyTorch 2.10+
evaluate_guards = False
class-attribute
instance-attribute
¶
A debug mode to detect and fail if Dynamo ever specializes a dynamic shape by guarding on it. When True, dynamic shape guards are not dropped from dynamo. And a failure will be triggered if a recompilation ever happens due to that. This mode requires VLLM_USE_BYTECODE_HOOK to be 0. Enabling this allow observing the dynamic shapes guards in the tlparse artifacts also. When type is backed, aot_compile must be disabled for this mode to work. until this change picked up https://github.com/pytorch/pytorch/pull/169239.
type = DynamicShapesType.BACKED
class-attribute
instance-attribute
¶
Controls the type of dynamic shapes handling to use with torch.compile().
- BACKED: Default PyTorch behavior with potential guards ignored.
- UNBACKED: No guards guaranteed (most sound) but may throw data dependent errors.
- BACKED_SIZE_OBLIVIOUS: Experimental safer alternative to backed/unbacked.
compute_hash()
¶
Provide a hash for DynamicShapesConfig.
DynamicShapesType
¶
Types of dynamic shapes handling in torch.compile(). see Dynamic shapes and vllm guard dropping in torch_compile.md for more details.
Attributes:
-
BACKED–Use backed dynamic shapes. torch.compile() guards on backed dynamic
-
BACKED_SIZE_OBLIVIOUS–Experimental flag that treats backed symbols as unbacked when explicit
-
UNBACKED–Use unbacked dynamic shapes. Guaranteed not to be guarded on and not
Source code in vllm/config/compilation.py
BACKED = 'backed'
class-attribute
instance-attribute
¶
Use backed dynamic shapes. torch.compile() guards on backed dynamic shapes and may add guards. Symbols are specialized to 0, 1, or >=2 even without encountering branching on those ranges.
BACKED_SIZE_OBLIVIOUS = 'backed_size_oblivious'
class-attribute
instance-attribute
¶
Experimental flag that treats backed symbols as unbacked when explicit unbacked handling is defined.
UNBACKED = 'unbacked'
class-attribute
instance-attribute
¶
Use unbacked dynamic shapes. Guaranteed not to be guarded on and not 0/1 specialized, but may throw data dependent errors when branches require their value without explicit unbacked handling.
PassConfig
¶
Configuration for custom Inductor passes.
This is separate from general CompilationConfig so that inductor passes
don't all have access to full configuration - that would create a cycle as
the PassManager is set as a property of config.
You must pass PassConfig to VLLMConfig constructor via the CompilationConfig constructor. VLLMConfig's post_init does further initialization. If used outside of the VLLMConfig, some fields may be left in an improper state.
Methods:
-
compute_hash–Produces a hash unique to the pass configuration.
-
flashinfer_max_size–Returns the max communication size in bytes for flashinfer
-
log_enabled_passes–Log the enabled custom fusion passes.
Attributes:
-
eliminate_noops(bool) –Eliminate no-op ops.
-
enable_qk_norm_rope_fusion(bool) –Enable fused Q/K RMSNorm + RoPE pass.
-
fi_allreduce_fusion_max_size_mb(float | None) –The threshold of the communicated tensor sizes under which
-
fuse_act_padding(bool) –Fuse the custom RMSNorm + padding ops.
-
fuse_act_quant(bool) –Fuse the custom SiluMul + quant ops.
-
fuse_allreduce_rms(bool) –Enable flashinfer allreduce fusion.
-
fuse_attn_quant(bool) –Fuse the custom Attention and MLAAttention + quant ops.
-
fuse_mla_dual_rms_norm(bool) –Fuse paired q/kv RMS norms in MLA attention.
-
fuse_norm_quant(bool) –Fuse the custom RMSNorm + quant ops.
-
fuse_qk_norm_rope_kvcache(bool) –Fuse QK RMSNorm + RoPE/MRoPE + KV cache update into an AITER HIP
-
fuse_rope_kvcache(bool) –Fuse the QK rope + KV cache ops.
-
fuse_rope_kvcache_cat_mla(bool) –Enable fused MLA KV cache update with RoPE.
-
rope_kvcache_fusion_max_token_num(int) –The threshold for ROCm AITER RoPE+KVCache fusion e.g. for small batch decode.
Source code in vllm/config/compilation.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
eliminate_noops = Field(default=True)
class-attribute
instance-attribute
¶
Eliminate no-op ops.
enable_qk_norm_rope_fusion = None
class-attribute
instance-attribute
¶
Enable fused Q/K RMSNorm + RoPE pass.
fi_allreduce_fusion_max_size_mb = None
class-attribute
instance-attribute
¶
The threshold of the communicated tensor sizes under which vllm should use flashinfer fused allreduce. Specified as a float in MB. Unspecified will fallback to default values which are compute capability and world size dependent. FI_ALLREDUCE_FUSION_MAX_SIZE_MB = { 90: { 2: 64, # 64MB 4: 2, # 2MB 8: 1, # 1MB }, 100: { 2: 64, # 64MB 4: 32, # 32MB 8: 1, # 1MB }, }, where key is the device capability
fuse_act_padding = None
class-attribute
instance-attribute
¶
Fuse the custom RMSNorm + padding ops.
fuse_act_quant = None
class-attribute
instance-attribute
¶
Fuse the custom SiluMul + quant ops.
fuse_allreduce_rms = None
class-attribute
instance-attribute
¶
Enable flashinfer allreduce fusion.
fuse_attn_quant = None
class-attribute
instance-attribute
¶
Fuse the custom Attention and MLAAttention + quant ops.
fuse_mla_dual_rms_norm = None
class-attribute
instance-attribute
¶
Fuse paired q/kv RMS norms in MLA attention.
fuse_norm_quant = None
class-attribute
instance-attribute
¶
Fuse the custom RMSNorm + quant ops.
fuse_qk_norm_rope_kvcache = Field(default=None)
class-attribute
instance-attribute
¶
Fuse QK RMSNorm + RoPE/MRoPE + KV cache update into an AITER HIP kernel. Supersedes both enable_qk_norm_rope_fusion and fuse_rope_kvcache for layers that support it. Auto-enabled at O2+ on ROCm for models with QK-norm (e.g. Qwen3-MoE and Qwen3-VL-class architectures).
fuse_rope_kvcache = None
class-attribute
instance-attribute
¶
Fuse the QK rope + KV cache ops.
fuse_rope_kvcache_cat_mla = None
class-attribute
instance-attribute
¶
Enable fused MLA KV cache update with RoPE.
rope_kvcache_fusion_max_token_num = 256
class-attribute
instance-attribute
¶
The threshold for ROCm AITER RoPE+KVCache fusion e.g. for small batch decode. Larger batch sizes e.g. during prefill will use the unfused kernels. Also applies to the fused QK-Norm+RoPE/MRoPE+KVCache pass.
_skip_none_validation(value, handler)
classmethod
¶
Skip validation if the value is None when initialisation is delayed.
Source code in vllm/config/compilation.py
compute_hash()
¶
Produces a hash unique to the pass configuration. Any new fields that affect compilation should be added to the hash. Any future fields that don't affect compilation should be excluded.
Source code in vllm/config/compilation.py
flashinfer_max_size(world_size)
¶
Returns the max communication size in bytes for flashinfer allreduce fusion for the given world size. Returns None if world size is not supported by configs as it's not supported by flashinfer.
Source code in vllm/config/compilation.py
log_enabled_passes()
¶
Log the enabled custom fusion passes. This is called at the end of VLLMConfig post_init, after all defaults are finalized. TODO also log the compile ranges for which this is enabled.
Source code in vllm/config/compilation.py
_walk_grid(limit, step)
¶
Sizes 1, ..., limit, each the next multiple of the largest power of two
not above step(size).
Source code in vllm/config/compilation.py
decode_cudagraph_capture_grid(max_requests)
¶
The request-count grid up to max_requests: every count up to 6, then a
step of the largest power of two not above 0.65 * n^(2/3) (2 from 8, 4 from
16, 8 from 48, 16 from 128, 32 from 352): 64 sizes at 1024.
Source code in vllm/config/compilation.py
decode_cudagraph_capture_max_tokens(config)
¶
The most tokens a uniform decode graph holds: the recorded max, which attention backends size their buffers by, within the decode token budget.
Source code in vllm/config/compilation.py
decode_cudagraph_capture_shapes(sizes, query_lens, max_tokens)
¶
The (num_reqs, query_len) uniform decode graphs for the request counts
sizes, for each query length up to the most requests it maps to and
max_tokens tokens. A batch pads to the smallest graph that holds it, so
the first size above a limit is captured at the limit and larger ones are
unreachable.
Source code in vllm/config/compilation.py
prefill_cudagraph_capture_grid(max_tokens, dense_head=False)
¶
The token-count grid up to max_tokens: 1, 2, 4, every 8 up to 64, four
sizes per doubling up to 1024 (every count up to 32 with dense_head), then
every 256 tokens, and every 512 once 7% of the size exceeds 512: 54 sizes at
8192.
Source code in vllm/config/compilation.py
varlen_decode_cudagraph_capture_grid(max_tokens, dense_head=False)
¶
The token-count grid of adaptive verification's decode graphs: 1, 2, 4
(every count up to 32 with dense_head), then 4 sizes per doubling from 8
to 1024, every 128 up to 4096 and every 256 beyond. Adaptive verification
picks its verify budget from the captured sizes, so it needs a finer grid
than prefill.