vllm.model_executor.models.ultravox ¶
PyTorch Ultravox model.
Classes:
-
StackAudioFrames–Stack the audio embedding frames to reduce the sequence length by a factor
-
UltravoxAudioEmbeddingInputs–Dimensions:
-
UltravoxAudioFeatureInputs–Dimensions:
-
UltravoxModel– -
UltravoxProcessingInfo– -
UltravoxWhisperEncoder–Ultravox's
ModifiedWhisperEncoderon top of vLLM'sWhisperEncoder.
Functions:
-
pad_and_concat_to_dim3–Pad and concatenate a list of tensors.
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
Attributes:
-
lens(Annotated[Tensor, TensorShape(bn)]) –Length of the audio frames per chunk. Used for attention mask in WhisperEncoder.
-
num_chunks(Annotated[Tensor, TensorShape(n)]) –Number of chunks per audio. Used for flattening the audio features.
-
token_len(Annotated[Tensor, TensorShape(bn)]) –Length of the audio tokens per chunk. Used for flattening the audio features.
Source code in vllm/model_executor/models/ultravox.py
lens instance-attribute ¶
Length of the audio frames per chunk. Used for attention mask in WhisperEncoder.
num_chunks instance-attribute ¶
Number of chunks per audio. Used for flattening the audio features.
token_len instance-attribute ¶
Length of the audio tokens per chunk. Used for flattening the audio features.
UltravoxModel ¶
Bases: Module, SupportsMultiModal, SupportsPP, SupportsLoRA
Methods:
-
forward–Run forward pass for Ultravox
-
get_mm_mapping–Get the module prefix in multimodal models
Source code in vllm/model_executor/models/ultravox.py
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 | |
forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs) ¶
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:
-
(input_ids¶Tensor | None) –Flattened (concatenated) input_ids corresponding to a batch.
-
(positions¶Tensor) –Position indices for the input tokens.
-
(intermediate_tensors¶Tensor | None, default:None) –Intermediate tensors from prior forward pass.
-
(inputs_embeds¶Tensor | None, default:None) –Optional tensor of input embeddings.
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
Methods:
-
get_target_channels–Return target audio channels for Ultravox models (mono).
Source code in vllm/model_executor/models/ultravox.py
UltravoxWhisperEncoder ¶
Bases: WhisperEncoder
Ultravox's ModifiedWhisperEncoder on top of vLLM's WhisperEncoder.
Like the original (a modified HF whisper encoder, see https://github.com/huggingface/transformers/issues/25744), it accepts mel inputs shorter than 30s (positions are sliced to the input length) and confines attention to each chunk's valid frames based on audio_lens (via segmented cu_seqlens instead of a dense key-padding mask), so its outputs match the HF implementation for valid positions. The linears are vLLM-native so the tower can be wrapped for LoRA.
Source code in vllm/model_executor/models/ultravox.py
_build_chunk_attn_metadata(attn, feature_lens, seq_len, hidden_size, device) ¶
Segmented varlen attention metadata for a padded batch of audio chunks.
Each padded row contributes up to two sequences to cu_seqlens: its valid frames and its padding tail. Attention therefore never crosses a valid/padding boundary (equivalent to the key-padding mask the HF implementation uses), while every row still flows through the (potentially LoRA-wrapped) linears, keeping the per-chunk token counts constant as required by get_num_mm_encoder_tokens / get_num_mm_connector_tokens. Queries at padding positions produce (garbage) outputs, which are trimmed by audio_token_len downstream.
Source code in vllm/model_executor/models/ultravox.py
pad_and_concat_to_dim3(features) ¶
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.