vllm.model_executor.models.ultravox
PyTorch Ultravox model.
UltravoxAudioInputs module-attribute
¶
UltravoxAudioInputs = Union[
UltravoxAudioFeatureInputs, UltravoxAudioEmbeddingInputs
]
ModifiedWhisperEncoder ¶
Bases: WhisperEncoder
Encoder portion of OpenAI's Whisper model.
This implementation is a slightly modified version of HF Transformers' Whisper Encoder, with only a few fixes: 1. base_model_prefix updated to allow for doing .from_pretrained
directly on the encoder 2. allow less than 30 second of audio padding to be passed in: - relaxed ValueError check for input_features
length to be less than or equal to expected_seq_length
instead of strictly equal - embed_pos is now sliced to match the length of inputs_embeds
Original: https://github.com/huggingface/transformers/blob/main/src/transformers/models/whisper/modeling_whisper.py See commentary: https://github.com/huggingface/transformers/issues/25744
Source code in vllm/model_executor/models/ultravox.py
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 |
|
__init__ ¶
forward ¶
Source code in vllm/model_executor/models/ultravox.py
get_attention_mask_by_audio_len ¶
Create attention mask based on audio lengths to mask out padding tokens For each sample in batch: - Convert raw audio length to feature length after convolutions - Create bool mask: True for valid positions and False for padding - Convert to attention mask format expected by transformer layers (1.0 for positions to attend to, large negative for positions to ignore) This masking ensures consistent behavior between training and inference by preventing the model from attending to padding tokens in both cases
Source code in vllm/model_executor/models/ultravox.py
StackAudioFrames ¶
Bases: Module
Stack the audio embedding frames to reduce the sequence length by a factor of stack_factor
.
Source code in vllm/model_executor/models/ultravox.py
forward ¶
Source code in vllm/model_executor/models/ultravox.py
UltravoxAudioEmbeddingInputs ¶
Bases: TypedDict
Source code in vllm/model_executor/models/ultravox.py
data instance-attribute
¶
data: NestedTensors
Shape: (batch_size, num_audios, audio_feature_size, hidden_size)
UltravoxAudioFeatureInputs ¶
Bases: TypedDict
Source code in vllm/model_executor/models/ultravox.py
data instance-attribute
¶
Shape: (batch_size, num_chunks, 80, M)
lens instance-attribute
¶
Length of the audio frames. Used for attention mask in WhisperEncoder. Shape: (batch_size, num_chunks)
token_len instance-attribute
¶
Length of the audio tokens. Used for flattening the audio features. Shape: (batch_size, num_chunks)
UltravoxDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[UltravoxProcessingInfo]
Source code in vllm/model_executor/models/ultravox.py
get_dummy_mm_data ¶
get_dummy_mm_data(
seq_len: int, mm_counts: Mapping[str, int]
) -> MultiModalDataDict
Source code in vllm/model_executor/models/ultravox.py
UltravoxModel ¶
Bases: Module
, SupportsMultiModal
, SupportsPP
, SupportsLoRA
Source code in vllm/model_executor/models/ultravox.py
386 387 388 389 390 391 392 393 394 395 396 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 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 |
|
hf_to_vllm_mapper class-attribute
instance-attribute
¶
hf_to_vllm_mapper = WeightsMapper(
orig_to_new_prefix={
"audio_tower.model.encoder.": "audio_tower."
}
)
language_model instance-attribute
¶
language_model = init_vllm_registered_model(
vllm_config=vllm_config,
hf_config=text_config,
prefix=maybe_prefix(prefix, "language_model"),
)
make_empty_intermediate_tensors instance-attribute
¶
packed_modules_mapping class-attribute
instance-attribute
¶
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
"gate_up_proj": ["gate_proj", "up_proj"],
}
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/ultravox.py
_audio_features_to_embeddings ¶
Source code in vllm/model_executor/models/ultravox.py
_parse_and_validate_audio_input ¶
_parse_and_validate_audio_input(
**kwargs: object,
) -> Optional[UltravoxAudioInputs]
Source code in vllm/model_executor/models/ultravox.py
_process_audio_input ¶
_process_audio_input(
audio_input: UltravoxAudioInputs,
) -> Union[NestedTensors, tuple[Tensor, ...]]
Source code in vllm/model_executor/models/ultravox.py
compute_logits ¶
compute_logits(
hidden_states: Tensor,
sampling_metadata: SamplingMetadata,
) -> Tensor
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: Optional[Tensor] = None,
inputs_embeds: Optional[Tensor] = None,
**kwargs,
) -> Union[Tensor, IntermediateTensors]
Run forward pass for Ultravox
One key thing to understand is the input_ids
already accounts for the positions of the to-be-inserted audio embeddings. The to-be-inserted audio has a size that is essentially 6.25 tokens per second of audio.
This way, the positions
and attn_metadata
are consistent with the input_ids
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio_features | A batch of audio input chunks [B, N, 80, M]. | required | |
audio_lens | Length of audio frames for each audio chunk [B]. | required | |
audio_token_len | Length of audio tokens for each audio chunk [B']. Note: batch dim is different from batch dim in audio chunks. | required |
Source code in vllm/model_executor/models/ultravox.py
get_input_embeddings ¶
get_input_embeddings(
input_ids: Tensor,
multimodal_embeddings: Optional[
MultiModalEmbeddings
] = None,
) -> Tensor
Source code in vllm/model_executor/models/ultravox.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
Get the module prefix in multimodal models
Source code in vllm/model_executor/models/ultravox.py
get_multimodal_embeddings ¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/ultravox.py
get_placeholder_str classmethod
¶
load_weights ¶
Source code in vllm/model_executor/models/ultravox.py
UltravoxMultiModalProcessor ¶
Bases: BaseMultiModalProcessor[UltravoxProcessingInfo]
Source code in vllm/model_executor/models/ultravox.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 |
|
_call_hf_processor ¶
_call_hf_processor(
prompt: str,
mm_data: Mapping[str, object],
mm_kwargs: Mapping[str, object],
tok_kwargs: Mapping[str, object],
) -> BatchFeature
Source code in vllm/model_executor/models/ultravox.py
_get_data_parser ¶
_get_data_parser() -> MultiModalDataParser
_get_mm_fields_config ¶
_get_mm_fields_config(
hf_inputs: BatchFeature,
hf_processor_mm_kwargs: Mapping[str, object],
) -> Mapping[str, MultiModalFieldConfig]
Source code in vllm/model_executor/models/ultravox.py
_get_prompt_updates ¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, Any],
out_mm_kwargs: MultiModalKwargsItems,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/ultravox.py
UltravoxProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/ultravox.py
get_feature_extractor ¶
get_feature_extractor(
**kwargs: object,
) -> WhisperFeatureExtractor
Source code in vllm/model_executor/models/ultravox.py
get_hf_processor ¶
get_hf_processor(**kwargs: object) -> ProcessorMixin
Source code in vllm/model_executor/models/ultravox.py
UltravoxProjector ¶
Bases: Module
Source code in vllm/model_executor/models/ultravox.py
__init__ ¶
__init__(config: UltravoxConfig)
Source code in vllm/model_executor/models/ultravox.py
forward ¶
Source code in vllm/model_executor/models/ultravox.py
pad_and_concat_to_dim3 ¶
Pad and concatenate a list of tensors.
output
Tensor of shape [B, C, M] where M is the maximum length of the input tensors, B is the sum of the batch sizes of the input tensors. C must be the same for all input tensors.