vllm.multimodal.processing
MultiModalHashes
module-attribute
¶
A collection of hashes with a similar structure as
MultiModalKwargs
.
PromptSeq
module-attribute
¶
A token sequence (list of token IDs) or text.
PromptTarget
module-attribute
¶
PromptTarget = Union[PromptSeq, PromptIndex]
The token sequence or text to update.
PromptUpdateContent
module-attribute
¶
PromptUpdateContent = Union[
Callable[[int], PromptUpdateInfo], PromptUpdateInfo
]
Given the index of the processed item within
modality
,
output the corresponding token sequence (or text).
For convenience, you can directly pass in the token sequence (or text) instead of a function if it does not depend on the input.
PromptUpdateInfo
module-attribute
¶
PromptUpdateInfo = Union[PromptSeq, PromptUpdateDetails]
The token sequence or text that are part of the update.
If only part of the content corresponds to feature placeholders, you can
use PromptUpdateDetails
to
specify which part.
BaseMultiModalProcessor
¶
Abstract base class to process multi-modal inputs to be used in vLLM.
Not to be confused with transformers.ProcessorMixin
.
Source code in vllm/multimodal/processing.py
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 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 |
|
__call__
¶
__call__(
prompt: str,
mm_data: MultiModalDataDict,
hf_processor_mm_kwargs: Mapping[str, object],
) -> MultiModalInputs
__init__
¶
__init__(
info: _I,
dummy_inputs: BaseDummyInputsBuilder[_I],
*,
cache: Optional[ProcessingCache] = None,
) -> None
Source code in vllm/multimodal/processing.py
_apply_hf_processor
¶
_apply_hf_processor(
prompt: Union[str, list[int]],
mm_data_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
*,
return_mm_hashes: bool,
) -> tuple[
list[int],
MultiModalKwargs,
Optional[MultiModalHashes],
bool,
]
Source code in vllm/multimodal/processing.py
_apply_hf_processor_main
¶
_apply_hf_processor_main(
prompt: Union[str, list[int]],
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
*,
enable_hf_prompt_update: bool,
) -> tuple[list[int], MultiModalKwargs, bool]
Apply the HF processor on the prompt text and multi-modal data.
In addition, return whether prompt updates have been applied
(for most HF processors, this should be True
).
Note
If enable_hf_prompt_update=False
, we use HF processor
to perform prompt updates if available; HF processor requires
that the prompt corresponds to multi-modal items.
Source code in vllm/multimodal/processing.py
_apply_hf_processor_mm_only
¶
_apply_hf_processor_mm_only(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> MultiModalKwargs
Apply the HF processor on the multi-modal data only.
Since HF processor requires that text and multi-modal items
correspond to each other, we generate dummy text using
DummyInputsBuilder
to go along with the multi-modal data.
Source code in vllm/multimodal/processing.py
_apply_hf_processor_text_mm
¶
_apply_hf_processor_text_mm(
prompt_text: str,
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> tuple[list[int], MultiModalKwargs, bool]
Apply the HF processor on the prompt text and multi-modal data together.
In addition, return whether prompt updates have been applied.
Source code in vllm/multimodal/processing.py
_apply_hf_processor_text_only
¶
Apply the HF processor on the prompt text only.
Since HF processor requires that text and multi-modal items correspond to each other, we create dummy multi-modal items to go along with the text.
Source code in vllm/multimodal/processing.py
_apply_hf_processor_tokens_only
¶
Apply the HF processor on the prompt tokens only.
Most HF processors accept prompt text but not prompt tokens.
If the HF processor adds or removes tokens that are not related to
multi-modal data, you should override this method so it is consistent
with the output of
_apply_hf_processor_text_only
on the
corresponding text.
Source code in vllm/multimodal/processing.py
_apply_prompt_updates
¶
_apply_prompt_updates(
token_ids: list[int],
mm_prompt_updates: Mapping[
str, Sequence[BoundPromptUpdate]
],
mm_item_counts: Mapping[str, int],
) -> tuple[
list[int],
str,
Mapping[str, list[PlaceholderFeaturesInfo]],
]
Source code in vllm/multimodal/processing.py
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 |
|
_apply_text_matches
¶
_apply_token_matches
¶
_bind_and_group_updates
¶
_bind_and_group_updates(
prompt_updates: Sequence[PromptUpdate],
) -> dict[str, Sequence[BoundPromptUpdate]]
Source code in vllm/multimodal/processing.py
_cached_apply_hf_processor
¶
_cached_apply_hf_processor(
prompt: Union[str, list[int]],
mm_data_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
*,
return_mm_hashes: bool,
) -> tuple[
list[int],
MultiModalKwargs,
Optional[MultiModalHashes],
bool,
]
Apply the HF processor on the full prompt text, caching the results and reusing cached results.
Source code in vllm/multimodal/processing.py
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 |
|
_call_hf_processor
¶
_call_hf_processor(
prompt: str,
mm_data: Mapping[str, object],
mm_kwargs: Mapping[str, object],
) -> BatchFeature
Call the HF processor on the prompt text and associated multi-modal data.
Source code in vllm/multimodal/processing.py
_find_mm_placeholders
¶
_find_mm_placeholders(
mm_prompt_updates: Mapping[
str, Sequence[BoundPromptUpdate]
],
new_token_ids: list[int],
mm_item_counts: Mapping[str, int],
) -> Mapping[str, list[PlaceholderFeaturesInfo]]
Source code in vllm/multimodal/processing.py
_get_cache_missing_items
¶
_get_cache_missing_items(
cache: ProcessingCache,
mm_data_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> tuple[
dict[str, list[ProcessingCacheOptionalItem]],
dict[str, list[object]],
]
Source code in vllm/multimodal/processing.py
_get_data_parser
¶
_get_data_parser() -> MultiModalDataParser
Construct a parser to preprocess multi-modal data items
before passing them to
_get_hf_mm_data
.
You can support additional modalities by creating a subclass
of MultiModalDataParser
that has additional subparsers.
Source code in vllm/multimodal/processing.py
_get_hf_mm_data
¶
_get_hf_mm_data(
mm_items: MultiModalDataItems,
) -> tuple[Mapping[str, object], Mapping[str, object]]
Source code in vllm/multimodal/processing.py
_get_mm_fields_config
abstractmethod
¶
_get_mm_fields_config(
hf_inputs: BatchFeature,
hf_processor_mm_kwargs: Mapping[str, object],
) -> Mapping[str, MultiModalFieldConfig]
Given the HF-processed data, output the metadata of each field.
Source code in vllm/multimodal/processing.py
_get_prompt_updates
abstractmethod
¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargs,
) -> Sequence[PromptUpdate]
Given the original multi-modal items for this modality and HF-processed data, output the updates to perform.
The information returned by this method is used to update token inputs which bypass the HF processor. It is also used to update the output of HF processor if the HF process does not apply prompt updates to text inputs.
Moreover, this information is critical to determine the token positions
in order to construct
PlaceholderRange
for each multi-modal item.
Source code in vllm/multimodal/processing.py
_hash_mm_items
¶
_hash_mm_items(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> MultiModalHashes
Create MM hashes to be returned (only used in V1).
Source code in vllm/multimodal/processing.py
_hf_processor_applies_updates
¶
_hf_processor_applies_updates(
prompt_text: str,
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
) -> bool
Return whether the HF processor applies prompt updates.
For most HF processors, this should be True
when multi-modal
data items are passed, but False
when multi-modal embeddings
are passed.
Source code in vllm/multimodal/processing.py
_maybe_apply_prompt_updates
¶
_maybe_apply_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
prompt_ids: list[int],
mm_kwargs: MultiModalKwargs,
is_update_applied: bool,
) -> tuple[
list[int],
str,
Mapping[str, list[PlaceholderFeaturesInfo]],
]
Source code in vllm/multimodal/processing.py
_merge_mm_kwargs
¶
_merge_mm_kwargs(
cache: ProcessingCache,
mm_cache_items: dict[
str, list[ProcessingCacheOptionalItem]
],
mm_missing_data: dict[str, list[object]],
mm_missing_kwargs: MultiModalKwargs,
) -> dict[str, list[ProcessingCacheItem]]
Source code in vllm/multimodal/processing.py
_to_mm_items
¶
_to_mm_items(
mm_data: MultiModalDataDict,
) -> MultiModalDataItems
Normalize
MultiModalDataDict
to MultiModalDataItems
before passing them to
_get_hf_mm_data
.
Source code in vllm/multimodal/processing.py
_validate_mm_kwargs
¶
_validate_mm_kwargs(
mm_kwargs: MultiModalKwargs,
mm_item_counts: Mapping[str, int],
) -> None
Source code in vllm/multimodal/processing.py
_validate_mm_placeholders
¶
_validate_mm_placeholders(
mm_placeholders: Mapping[
str, list[PlaceholderFeaturesInfo]
],
mm_item_counts: Mapping[str, int],
) -> None
Source code in vllm/multimodal/processing.py
apply
¶
apply(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
hf_processor_mm_kwargs: Mapping[str, object],
return_mm_hashes: bool = False,
) -> MultiModalInputs
Process multi-modal inputs to be used in vLLM.
The main steps are:
- Apply HF Processor on prompt text and multi-modal data together, outputting token IDs and processed tensors.
- Find and update sequences in the token IDs with placeholder tokens. The number of placeholder tokens equals the feature size of the multi-modal data outputted by the multi-modal encoder.
- Extract information about the placeholder tokens from the processed token IDs.
Source code in vllm/multimodal/processing.py
BaseProcessingInfo
¶
Base class to provide the information necessary for data processing.
Source code in vllm/multimodal/processing.py
__init__
¶
__init__(ctx: InputProcessingContext) -> None
get_allowed_mm_limits
¶
Return the maximum allowed number of items for each modality.
Source code in vllm/multimodal/processing.py
get_hf_config
¶
get_hf_processor
¶
get_hf_processor(**kwargs: object) -> ProcessorMixin
Subclasses can override this method to handle specific kwargs from model config or user inputs.
get_supported_mm_limits
abstractmethod
¶
Return the maximum supported number of items for each modality.
A value of None
means unlimited number of items.
Omitting a modality from the returned dictionary means that it is not supported at all.
Source code in vllm/multimodal/processing.py
get_tokenizer
¶
get_tokenizer() -> AnyTokenizer
BoundPromptUpdate
dataclass
¶
A PromptUpdate
bound
to a tokenizer to automatically convert
target
and the result of
get_content
between token sequence and text representations.
Source code in vllm/multimodal/processing.py
target
property
¶
target: Union[_BoundPromptSequence, PromptIndex]
The token sequence (or text) to update.
__post_init__
¶
get_content
¶
get_content(item_idx: int) -> _BoundPromptContent
Given the index of the processed item within
modality
,
output the token sequence (or text) to update.
Source code in vllm/multimodal/processing.py
EncDecMultiModalProcessor
¶
Bases: BaseMultiModalProcessor[_I]
Source code in vllm/multimodal/processing.py
1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 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 |
|
_get_enc_dec_inputs
¶
_get_enc_dec_inputs(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
encoder_inputs: MultiModalInputs,
)
Source code in vllm/multimodal/processing.py
apply
¶
apply(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
hf_processor_mm_kwargs: Mapping[str, object],
return_mm_hashes: bool = False,
) -> MultiModalEncDecInputs
Process multi-modal inputs to be used in vLLM. The main processing steps are modified to fit encoder-decoder model: 1. Create encoder prompt from input prompt text. 2. Apply the HF processor on encoder prompt. 3. Copy the input prompt text as decoder prompt inputs.
Source code in vllm/multimodal/processing.py
create_decoder_prompt
¶
create_encoder_prompt
abstractmethod
¶
create_encoder_prompt(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
) -> Union[str, list[int]]
Create input prompt for the encoder. HF processor will be applied on this prompt during profiling and generation.
Source code in vllm/multimodal/processing.py
PlaceholderFeaturesInfo
dataclass
¶
Source code in vllm/multimodal/processing.py
ProcessingCache
¶
Source code in vllm/multimodal/processing.py
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 |
|
_cache
instance-attribute
¶
_cache = get_lru_cache(
capacity_gb,
MultiModalKwargsItem,
debug=bool(debug_cache_hit_ratio_steps),
)
debug_cache_hit_ratio_steps
instance-attribute
¶
__init__
¶
Source code in vllm/multimodal/processing.py
_maybe_log_cache_stats
¶
Source code in vllm/multimodal/processing.py
get
¶
get(
model_id: str,
modality: str,
input_item: object,
input_kwargs: Mapping[str, object],
) -> Optional[MultiModalKwargsItem]
Get a processed multi-modal item from the cache according to its dependencies, including:
- The model ID
- The modality of the item
- The original data item passed to the HF processor
- The configuration options of the HF processor
Source code in vllm/multimodal/processing.py
get_item
¶
get_item(
model_id: str,
modality: str,
input_item: object,
input_kwargs: Mapping[str, object],
) -> ProcessingCacheOptionalItem
Source code in vllm/multimodal/processing.py
get_lru_cache
staticmethod
¶
get_lru_cache(
capacity_gb: float,
value_type: type[_V],
*,
debug: bool = False,
) -> LRUCache[str, _V]
Source code in vllm/multimodal/processing.py
put
¶
put(
model_id: str,
modality: str,
input_item: object,
input_kwargs: Mapping[str, object],
output_kwargs: MultiModalKwargsItem,
) -> None
Put a processed multi-modal item into the cache
according to its dependencies
(see get
).
Source code in vllm/multimodal/processing.py
put_item
¶
put_item(item: ProcessingCacheItem) -> None
ProcessingCacheItem
¶
ProcessingCacheOptionalItem
¶
PromptIndex
dataclass
¶
Resolves to an index in the prompt.
Source code in vllm/multimodal/processing.py
PromptIndexTargets
¶
Source code in vllm/multimodal/processing.py
end
staticmethod
¶
end() -> PromptIndex
Resolves to the end of the prompt (after the last token).
This results in a match even if the prompt is empty.
prefix
staticmethod
¶
prefix(seq: PromptSeq) -> PromptIndex
Resolves to a location in the prompt after the given prefix.
Source code in vllm/multimodal/processing.py
start
staticmethod
¶
start() -> PromptIndex
Resolves to the start of the prompt (before the first token).
This results in a match even if the prompt is empty.
PromptInsertion
dataclass
¶
Bases: PromptUpdate
Defines how to insert placeholder tokens into a prompt.
Example:
For each image, insert a number of <image>
feature placeholders
equal to the feature size of the vision encoder after the <s>
token:
Insert these tokens at the start of the prompt:
PromptInsertion(
modality="image",
target=PromptIndexTargets.start(),
insertion="<image>" * image_feature_size,
)
Insert these tokens after a prefix Images:
:
PromptInsertion(
modality="image",
target=PromptIndexTargets.prefix("Images:"),
insertion="<image>" * image_feature_size,
)
Insert these tokens at the end of the prompt:
PromptInsertion(
modality="image",
target=PromptIndexTargets.end(),
insertion="<image>" * image_feature_size,
)
Source code in vllm/multimodal/processing.py
insertion
class-attribute
instance-attribute
¶
insertion: PromptUpdateContent = field(repr=False)
PromptReplacement
dataclass
¶
Bases: PromptUpdate
Defines how to replace portions of an input prompt with placeholder tokens.
Example:
For each image, replace one <image>
input placeholder in the prompt
with a number of <image>
feature placeholders
equal to the feature size of the vision encoder:
PromptReplacement(
modality="image",
target="<image>",
replacement="<image>" * image_feature_size,
)
As above, but further pad the feature placeholders with <image_bos>
and `
PromptReplacement(
modality="image",
target="<image>",
replacement=PromptUpdateDetails(
full="".join([
"<image_bos>",
"<image>" * image_feature_size,
"<image_eos>",
]),
features="<image>" * image_feature_size,
),
)
To avoid unnecessary tokenization during prompt replacement, we recommended passing token sequences instead of text:
PromptReplacement(
modality="image",
target=[image_token_id],
replacement=PromptUpdateDetails(
full=([image_bos_id] + [image_token_id] * image_feature_size
+ [image_eos_id]),
features=[image_token_id] * image_feature_size,
),
)
Source code in vllm/multimodal/processing.py
replacement
class-attribute
instance-attribute
¶
replacement: PromptUpdateContent = field(repr=False)
__init__
¶
__init__(
modality: str,
target: PromptTarget,
replacement: PromptUpdateContent,
) -> None
PromptTargetMatch
dataclass
¶
Bases: ABC
Source code in vllm/multimodal/processing.py
PromptUpdate
dataclass
¶
Bases: ABC
Defines how to update a prompt with placeholder tokens.
Source code in vllm/multimodal/processing.py
content
abstractmethod
property
¶
content: PromptUpdateContent
The placeholder tokens that are part of the update.
bind
¶
bind(tokenizer: AnyTokenizer) -> BoundPromptUpdate
PromptUpdateDetails
dataclass
¶
Details about the token sequence or text that are part of the update.
Source code in vllm/multimodal/processing.py
is_embed
class-attribute
instance-attribute
¶
is_embed: Optional[
Callable[[_BoundPromptSequence], Tensor]
] = None
Given full
,
return a boolean mask of shape (len(full),)
indicating which positions
of full
to assign embeddings to.
None
(default) means to assign embeddings to all positions of full
.
The embeddings are obtained by calling
SupportsMultiModal.get_multimodal_embeddings
.
__init__
¶
__init__(
full: _S,
is_embed: Optional[
Callable[[_BoundPromptSequence], Tensor]
] = None,
) -> None
from_seq
staticmethod
¶
from_seq(seq: _S) -> PromptUpdateDetails[_S]
select_text
staticmethod
¶
select_text(
seq: _S, embed_text: str
) -> PromptUpdateDetails[_S]
Source code in vllm/multimodal/processing.py
select_token_id
staticmethod
¶
select_token_id(
seq: _S, embed_token_id: int
) -> PromptUpdateDetails[_S]
UpdateMode
¶
_BoundPromptContent
dataclass
¶
Source code in vllm/multimodal/processing.py
__init__
¶
__init__(
full: _BoundPromptSequence,
is_embed: Optional[
Callable[[_BoundPromptSequence], Tensor]
],
) -> None
_BoundPromptSequence
dataclass
¶
A _PromptSeq
bound
to a tokenizer to automatically
convert between token sequence and text representations.
Source code in vllm/multimodal/processing.py
__init__
¶
__post_init__
¶
from_seq
staticmethod
¶
from_seq(
tokenizer: AnyTokenizer, seq: PromptSeq
) -> _BoundPromptSequence
Source code in vllm/multimodal/processing.py
_HasModalityAttr
¶
_HasModalityProp
¶
_PromptTargetIndexMatch
dataclass
¶
Bases: PromptTargetMatch
Source code in vllm/multimodal/processing.py
_PromptTargetTextMatch
dataclass
¶
Bases: PromptTargetMatch
Source code in vllm/multimodal/processing.py
_PromptTargetTokenMatch
dataclass
¶
_TokenMatch
¶
_apply_matches
¶
_apply_matches(
prompt: _S,
mm_matches: Mapping[str, Sequence[PromptTargetMatch]],
mm_item_counts: Mapping[str, int],
) -> list[_S]
Apply the updates in mm_matches
to prompt
.
Source code in vllm/multimodal/processing.py
_cached_decode
cached
¶
_cached_decode(
tokenizer: AnyTokenizer,
token_ids: tuple[int, ...],
*,
skip_special_tokens: Optional[bool] = None,
) -> str
Source code in vllm/multimodal/processing.py
_cached_encode
cached
¶
_cached_encode(
tokenizer: AnyTokenizer,
text: str,
*,
add_special_tokens: Optional[bool] = None,
) -> list[int]
Source code in vllm/multimodal/processing.py
_iter_placeholders
¶
_iter_placeholders(
mm_prompt_updates: Mapping[
str, Sequence[BoundPromptUpdate]
],
prompt: list[int],
mm_item_counts: Mapping[str, int],
) -> Iterable[PlaceholderFeaturesInfo]
Yield each set of placeholder tokens found in prompt
.
Matches are exclusive even when multiple modalities share
the same placeholder tokens. In that case, the modality that
appears earlier in mm_prompt_updates
takes priority.
Note that empty matches are ignored.
Source code in vllm/multimodal/processing.py
_resolve_matches
¶
_resolve_matches(
prompt: PromptSeq,
mm_matches: Mapping[str, Sequence[PromptTargetMatch]],
) -> list[PromptTargetMatch]
Resolve mm_matches
to ensure that there are no overlapping matches,
and sort them such that earlier matches take priority over later ones.
Source code in vllm/multimodal/processing.py
apply_text_matches
¶
apply_text_matches(
prompt: str,
mm_matches: Mapping[str, Sequence[PromptTargetMatch]],
mm_item_counts: Mapping[str, int],
) -> str
Apply the updates in mm_matches
to prompt
.
Source code in vllm/multimodal/processing.py
apply_token_matches
¶
apply_token_matches(
prompt: list[int],
mm_matches: Mapping[str, Sequence[PromptTargetMatch]],
mm_item_counts: Mapping[str, int],
) -> list[int]
Apply the updates in mm_matches
to prompt
.
Source code in vllm/multimodal/processing.py
find_mm_placeholders
¶
find_mm_placeholders(
mm_prompt_updates: Mapping[
str, Sequence[BoundPromptUpdate]
],
prompt: list[int],
mm_item_counts: Mapping[str, int],
) -> Mapping[str, list[PlaceholderFeaturesInfo]]
Source code in vllm/multimodal/processing.py
find_text_matches
¶
find_text_matches(
prompt: str, prompt_updates: Sequence[BoundPromptUpdate]
) -> Sequence[PromptTargetMatch]
Return each target of prompt_updates
found in prompt
.
Source code in vllm/multimodal/processing.py
find_token_matches
¶
find_token_matches(
prompt: list[int],
prompt_updates: Sequence[BoundPromptUpdate],
) -> Sequence[PromptTargetMatch]
Return each target of prompt_updates
found in prompt
.
Source code in vllm/multimodal/processing.py
full_groupby_modality
¶
Convenience function to apply full_groupby
based on modality.
iter_token_matches
¶
Yield each occurrence of match_ids
in token_ids
.
Note that empty matches are ignored.
Source code in vllm/multimodal/processing.py
replace_token_matches
¶
replace_token_matches(
token_ids: list[int],
match_ids: list[int],
new_ids: list[int],
) -> list[int]
Replace each occurrence of match_ids
in token_ids
with new_ids
.
Note that empty matches are ignored.