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.
UltravoxAudioEmbeddingInputs
¶
Bases: TensorSchema
Dimensions: - b: batch size - na: number of audios - afs: audio feature size - hs: hidden size
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.
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.
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.
-
(**kwargs¶object, default:{}) –Multimodal inputs for this batch, forwarded to the multimodal embedding path.
get_mm_mapping()
¶
Get the module prefix in multimodal models.
UltravoxProcessingInfo
¶
Bases: BaseProcessingInfo
Methods:
-
get_target_channels–Return target audio channels for Ultravox models (mono).
get_target_channels()
¶
Return target audio channels for Ultravox models (mono).
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.
_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_mm_lora_token_counts. Queries at padding
positions produce (garbage) outputs, which are trimmed by audio_token_len
downstream.
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.