1
1
# SPDX-License-Identifier: Apache-2.0
2
-
3
2
from collections .abc import Iterable
4
- from dataclasses import dataclass
5
- from functools import cached_property
6
3
from typing import TYPE_CHECKING , Any , Generic , Literal , Optional , Union , cast
7
4
8
- import torch
9
- from typing_extensions import NotRequired , TypedDict , TypeVar , assert_never
5
+ from typing_extensions import NotRequired , TypedDict , TypeVar
10
6
11
7
if TYPE_CHECKING :
12
- from vllm .multimodal import (MultiModalDataDict , MultiModalKwargs ,
13
- MultiModalPlaceholderDict )
14
- from vllm .multimodal .inputs import MultiModalInputs
8
+ from vllm .multimodal .inputs import MultiModalDataDict , MultiModalInputs
15
9
16
10
17
11
class TextPrompt (TypedDict ):
@@ -147,46 +141,11 @@ class TokenInputs(TypedDict):
147
141
The original prompt text corresponding to the token IDs, if available.
148
142
"""
149
143
150
- multi_modal_data : NotRequired ["MultiModalDataDict" ]
151
- """
152
- Optional multi-modal data to pass to the model,
153
- if the model supports it.
154
- """
155
-
156
- multi_modal_inputs : NotRequired ["MultiModalKwargs" ]
157
- """
158
- Optional multi-modal inputs to pass to the model,
159
- if the model supports it.
160
- """
161
-
162
- multi_modal_placeholders : NotRequired ["MultiModalPlaceholderDict" ]
163
- """
164
- Placeholder ranges for the multi-modal data.
165
- """
166
-
167
- multi_modal_hashes : NotRequired [list [str ]]
168
- """
169
- The hashes of the multi-modal data.
170
- """
171
-
172
- mm_processor_kwargs : NotRequired [dict [str , Any ]]
173
- """
174
- Optional multi-modal processor kwargs to be forwarded to the
175
- multimodal input mapper & processor. Note that if multiple modalities
176
- have registered mappers etc for the model being considered, we attempt
177
- to pass the mm_processor_kwargs to each of them.
178
- """
179
-
180
144
181
145
def token_inputs (
182
146
prompt_token_ids : list [int ],
183
147
token_type_ids : Optional [list [int ]] = None ,
184
148
prompt : Optional [str ] = None ,
185
- multi_modal_data : Optional ["MultiModalDataDict" ] = None ,
186
- multi_modal_inputs : Optional ["MultiModalKwargs" ] = None ,
187
- multi_modal_hashes : Optional [list [str ]] = None ,
188
- multi_modal_placeholders : Optional ["MultiModalPlaceholderDict" ] = None ,
189
- mm_processor_kwargs : Optional [dict [str , Any ]] = None ,
190
149
) -> TokenInputs :
191
150
"""Construct :class:`TokenInputs` from optional values."""
192
151
inputs = TokenInputs (type = "token" , prompt_token_ids = prompt_token_ids )
@@ -195,16 +154,6 @@ def token_inputs(
195
154
inputs ["prompt" ] = prompt
196
155
if token_type_ids is not None :
197
156
inputs ["token_type_ids" ] = token_type_ids
198
- if multi_modal_data is not None :
199
- inputs ["multi_modal_data" ] = multi_modal_data
200
- if multi_modal_inputs is not None :
201
- inputs ["multi_modal_inputs" ] = multi_modal_inputs
202
- if multi_modal_hashes is not None :
203
- inputs ["multi_modal_hashes" ] = multi_modal_hashes
204
- if multi_modal_placeholders is not None :
205
- inputs ["multi_modal_placeholders" ] = multi_modal_placeholders
206
- if mm_processor_kwargs is not None :
207
- inputs ["mm_processor_kwargs" ] = mm_processor_kwargs
208
157
209
158
return inputs
210
159
@@ -237,112 +186,6 @@ class EncoderDecoderInputs(TypedDict):
237
186
:class:`vllm.sequence.Sequence`.
238
187
"""
239
188
240
-
241
- @dataclass
242
- class SingletonInputsAdapter :
243
- """
244
- Unified interface to access the components of :class:`SingletonInputs`.
245
- """
246
- inputs : SingletonInputs
247
-
248
- @cached_property
249
- def prompt (self ) -> Optional [str ]:
250
- inputs = self .inputs
251
-
252
- if inputs ["type" ] == "token" or inputs ["type" ] == "multimodal" :
253
- return inputs .get ("prompt" )
254
-
255
- assert_never (inputs ) # type: ignore[arg-type]
256
-
257
- @cached_property
258
- def prompt_token_ids (self ) -> list [int ]:
259
- inputs = self .inputs
260
-
261
- if inputs ["type" ] == "token" or inputs ["type" ] == "multimodal" :
262
- return inputs .get ("prompt_token_ids" , [])
263
-
264
- assert_never (inputs ) # type: ignore[arg-type]
265
-
266
- @cached_property
267
- def token_type_ids (self ) -> list [int ]:
268
- inputs = self .inputs
269
-
270
- if inputs ["type" ] == "token" or inputs ["type" ] == "multimodal" :
271
- return inputs .get ("token_type_ids" , [])
272
-
273
- assert_never (inputs ) # type: ignore[arg-type]
274
-
275
- @cached_property
276
- def prompt_embeds (self ) -> Optional [torch .Tensor ]:
277
- inputs = self .inputs
278
-
279
- if inputs ["type" ] == "token" or inputs ["type" ] == "multimodal" :
280
- return None
281
-
282
- assert_never (inputs ) # type: ignore[arg-type]
283
-
284
- @cached_property
285
- def multi_modal_data (self ) -> "MultiModalDataDict" :
286
- inputs = self .inputs
287
-
288
- if inputs ["type" ] == "token" :
289
- return inputs .get ("multi_modal_data" , {})
290
-
291
- if inputs ["type" ] == "multimodal" :
292
- return inputs .get ("mm_kwargs" , {})
293
-
294
- assert_never (inputs ) # type: ignore[arg-type]
295
-
296
- @cached_property
297
- def multi_modal_inputs (self ) -> Union [dict , "MultiModalKwargs" ]:
298
- inputs = self .inputs
299
-
300
- if inputs ["type" ] == "token" :
301
- return inputs .get ("multi_modal_inputs" , {})
302
-
303
- if inputs ["type" ] == "multimodal" :
304
- return inputs .get ("mm_kwargs" , {})
305
-
306
- assert_never (inputs ) # type: ignore[arg-type]
307
-
308
- @cached_property
309
- def multi_modal_hashes (self ) -> list [str ]:
310
- inputs = self .inputs
311
-
312
- if inputs ["type" ] == "token" :
313
- return inputs .get ("multi_modal_hashes" , [])
314
-
315
- if inputs ["type" ] == "multimodal" :
316
- # only the case when we use MultiModalInputs
317
- return inputs .get ("mm_hashes" , []) # type: ignore[return-value]
318
-
319
- assert_never (inputs ) # type: ignore[arg-type]
320
-
321
- @cached_property
322
- def multi_modal_placeholders (self ) -> "MultiModalPlaceholderDict" :
323
- inputs = self .inputs
324
-
325
- if inputs ["type" ] == "token" :
326
- return inputs .get ("multi_modal_placeholders" , {})
327
-
328
- if inputs ["type" ] == "multimodal" :
329
- return inputs .get ("mm_placeholders" , {})
330
-
331
- assert_never (inputs ) # type: ignore[arg-type]
332
-
333
- @cached_property
334
- def mm_processor_kwargs (self ) -> dict [str , Any ]:
335
- inputs = self .inputs
336
-
337
- if inputs ["type" ] == "token" :
338
- return inputs .get ("mm_processor_kwargs" , {})
339
-
340
- if inputs ["type" ] == "multimodal" :
341
- return {}
342
-
343
- assert_never (inputs ) # type: ignore[arg-type]
344
-
345
-
346
189
ProcessorInputs = Union [DecoderOnlyInputs , EncoderDecoderInputs ]
347
190
"""
348
191
The inputs to :data:`vllm.inputs.InputProcessor`.
0 commit comments