vllm.model_executor.models.ultravox ¶
PyTorch Ultravox model.
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
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 | |
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
UltravoxAudioEmbeddingInputs ¶
Bases: TensorSchema
Dimensions: - b: batch size - na: number of audios - afs: audio feature size - hs: hidden size
Source code in vllm/model_executor/models/ultravox.py
UltravoxAudioFeatureInputs ¶
Bases: TensorSchema
Dimensions: - b: batch size - n: number of chunks - t: Time frames (M) - nmb: Number of mel bins
Source code in vllm/model_executor/models/ultravox.py
lens instance-attribute ¶
lens: Annotated[Tensor, TensorShape(bn)]
Length of the audio frames per chunk. Used for attention mask in WhisperEncoder.
num_chunks instance-attribute ¶
num_chunks: Annotated[Tensor, TensorShape(n)]
Number of chunks per audio. Used for flattening the audio features.
token_len instance-attribute ¶
token_len: Annotated[Tensor, TensorShape(bn)]
Length of the audio tokens per chunk. Used for flattening the audio features.
UltravoxModel ¶
Bases: Module, SupportsMultiModal, SupportsPP, SupportsLoRA
Source code in vllm/model_executor/models/ultravox.py
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 | |
forward ¶
forward(
input_ids: Tensor | None,
positions: Tensor,
intermediate_tensors: Tensor | None = None,
inputs_embeds: Tensor | None = None,
**kwargs,
) -> 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 |
|---|---|---|---|
input_ids | Tensor | None | Flattened (concatenated) input_ids corresponding to a batch. | required |
positions | Tensor | Position indices for the input tokens. | required |
intermediate_tensors | Tensor | None | Intermediate tensors from prior forward pass. | None |
inputs_embeds | Tensor | None | Optional tensor of input embeddings. | None |
Source code in vllm/model_executor/models/ultravox.py
get_mm_mapping ¶
Get the module prefix in multimodal models
Source code in vllm/model_executor/models/ultravox.py
UltravoxProcessingInfo ¶
Bases: BaseProcessingInfo
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.