Skip to content

vllm.model_executor.models.granite_speech

Inference-only IBM Granite speech model.

Classes:

GraniteSpeechAudioInputs

Bases: TensorSchema

Audio input features for Granite Speech model.

Dimensions
  • b: Batch size
  • fi: Number of input features from the Mel spectrogram.
  • fo: Number of output features, i.e. the embedding size.
  • 160: Fixed feature dimension for Mel spectrogram features

Attributes:

audio_embed_sizes instance-attribute

List of audio embedding sizes for each item in batch.

input_features instance-attribute

Audio input features.

input_features_mask instance-attribute

Mask for variable length audio features.

GraniteSpeechCTCEncoder

Bases: Module

CTC Encoder comprising conformer blocks and additional linear layers.

GraniteSpeechConformerAttention

Bases: Module

Attention for conformer blocks using Shaw's relative positional embeddings. See the following paper for more details.

GraniteSpeechConformerBlock

Bases: Module

Conformer block, consisting largely of linear layers, attention, and convolutional layers.

GraniteSpeechConformerConvModule

Bases: Module

Conformer conv module consisting of several 1D/depthwise 1D convolutional layers.

GraniteSpeechConformerDepthWiseConv1d

Bases: Module

Wrapper for padded 1D pointwise convolution.

GraniteSpeechConformerFeedForward

Bases: Module

Feedforward module for conformer encoder blocks.

GraniteSpeechForConditionalGeneration

Bases: Module, SupportsMultiModal, SupportsPP, SupportsLoRA, SupportsTranscription

Methods:

_build_input_features_mask(audio_embed_sizes)

Calculate the input features mask, which will generally be used to mask the padded features for all entries in the batch except for those with the most audio features.

Parameters:

  • audio_embed_sizes

    (Tensor) –

    torch.Tensor Tensor of num features in each seq in the batch.

Returns:

  • Tensor –

    torch.Tensor: Mask of shape (bsz, num_features) to be applied to

  • Tensor –

    the audio features prior to splitting the audio embeddings.

_pad_and_stack_input_features(input_features)

Given a list of input features of varying length, pad them to the same length and stack them into a torch.Tensor.

NOTE: Usually, padding is done in the input processor/feature extractor and zero padded prior to the computation of the Mel features; the resulting values are only constant within a batch and generally nonzero (i.e., slightly negative nums); we should validate that this is okay since we don't use a feature attention mask, but the more important thing is that we apply the input_features_mask with variable len batches.

Parameters:

  • input_features

    (list[Tensor]) –

    list[torch.Tensor] 3D Input features to be coerced into a tensor.

Returns:

  • Tensor –

    torch.Tensor: Tensor of shape [bsz, num_features, 160], where

  • Tensor –

    num_features is the max number of features of any entry in the

  • Tensor –

    batch.

_process_audio_input(audio_input)

Compute the audio features to be merged into the LLM embeddings.

Parameters:

  • audio_input

    (GraniteSpeechAudioInputs) –

    GraniteSpeechAudioInputs Audio inputs object containing Mel features, an input features mask, and the (flattened) number of audio tokens per instance.

Returns:

  • tuple[Tensor] –

    tuple[torch.Tensor]: List of length bsz.

embed_multimodal(**kwargs)

Compute the audio embeddings if audio inputs are present.

get_generation_prompt(stt_params) classmethod

Get the generation prompt to be used for transcription requests.

get_mm_mapping()

Get the module prefix in multimodal models.

get_num_audio_tokens(audio_duration_s, stt_config, model_config) classmethod

Get the number of audio tokens for an audio duration in sec.

get_speech_to_text_config(model_config, task_type) classmethod

Get the stt config for this model.