vllm.model_executor.models.whisper ¶
ISO639_1_SUPPORTED_LANGS module-attribute
¶
ISO639_1_SUPPORTED_LANGS = {
"af": "Afrikaans",
"ar": "Arabic",
"hy": "Armenian",
"az": "Azerbaijani",
"be": "Belarusian",
"bs": "Bosnian",
"bg": "Bulgarian",
"ca": "Catalan",
"zh": "Chinese",
"hr": "Croatian",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"en": "English",
"et": "Estonian",
"fi": "Finnish",
"fr": "French",
"gl": "Galician",
"de": "German",
"el": "Greek",
"he": "Hebrew",
"hi": "Hindi",
"hu": "Hungarian",
"is": "Icelandic",
"id": "Indonesian",
"it": "Italian",
"ja": "Japanese",
"kn": "Kannada",
"kk": "Kazakh",
"ko": "Korean",
"lv": "Latvian",
"lt": "Lithuanian",
"mk": "Macedonian",
"ms": "Malay",
"mr": "Marathi",
"mi": "Maori",
"ne": "Nepali",
"no": "Norwegian",
"fa": "Persian",
"pl": "Polish",
"pt": "Portuguese",
"ro": "Romanian",
"ru": "Russian",
"sr": "Serbian",
"sk": "Slovak",
"sl": "Slovenian",
"es": "Spanish",
"sw": "Swahili",
"sv": "Swedish",
"tl": "Tagalog",
"ta": "Tamil",
"th": "Thai",
"tr": "Turkish",
"uk": "Ukrainian",
"ur": "Urdu",
"vi": "Vietnamese",
"cy": "Welsh",
}
WhisperAttention ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
attn instance-attribute
¶
attn = WhisperEncoderAttention(
num_heads, head_dim, scaling, num_kv_heads=num_kv_heads
)
out_proj instance-attribute
¶
out_proj = RowParallelLinear(
input_size=embed_dim,
output_size=embed_dim,
bias=bias,
quant_config=quant_config,
prefix=f"{prefix}.out_proj",
)
__init__ ¶
__init__(
embed_dim: int,
num_heads: int,
bias: bool = True,
attn_type: AttentionType = DECODER,
cache_config: Optional[CacheConfig] = None,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/whisper.py
_init_qkv ¶
_init_qkv(
embed_dim: int,
bias: bool = True,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/whisper.py
WhisperAudioInputs ¶
Bases: TensorSchema
Dimensions
- b: Batch size
- nmb: Number of mel bins
- t: Time frames (M)
Source code in vllm/model_executor/models/whisper.py
input_features instance-attribute
¶
input_features: Annotated[
Optional[NestedTensors], TensorShape(b, nmb, t)
]
WhisperCrossAttention ¶
Bases: WhisperAttention
Source code in vllm/model_executor/models/whisper.py
__init__ ¶
__init__(
embed_dim: int,
num_heads: int,
bias: bool = True,
cache_config: Optional[CacheConfig] = None,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/whisper.py
_init_qkv ¶
_init_qkv(
embed_dim: int,
bias: bool = True,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/models/whisper.py
forward ¶
Source code in vllm/model_executor/models/whisper.py
WhisperDecoder ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
embed_positions instance-attribute
¶
embed_positions = WhisperPositionalEmbedding(
max_target_positions, d_model
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/whisper.py
forward ¶
Source code in vllm/model_executor/models/whisper.py
WhisperDecoderLayer ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
encoder_attn instance-attribute
¶
encoder_attn = WhisperCrossAttention(
embed_dim=d_model,
num_heads=decoder_attention_heads,
cache_config=cache_config,
quant_config=quant_config,
prefix=f"{prefix}.encoder_attn",
)
mlp instance-attribute
¶
mlp = WhisperMLP(
embed_dim=d_model,
ffn_dim=decoder_ffn_dim,
act_fn=activation_function,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
)
self_attn instance-attribute
¶
self_attn = WhisperAttention(
embed_dim=d_model,
num_heads=decoder_attention_heads,
attn_type=DECODER,
cache_config=cache_config,
quant_config=quant_config,
prefix=f"{prefix}.self_attn",
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/whisper.py
forward ¶
Source code in vllm/model_executor/models/whisper.py
WhisperDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[WhisperProcessingInfo]
Source code in vllm/model_executor/models/whisper.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/whisper.py
WhisperEncoder ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
conv2 instance-attribute
¶
conv2 = Conv1d(
embed_dim, embed_dim, kernel_size=3, stride=2, padding=1
)
__init__ ¶
__init__(
*,
vllm_config: VllmConfig,
prefix: str = "",
init_in_fp32: bool = False,
)
Source code in vllm/model_executor/models/whisper.py
forward ¶
Source code in vllm/model_executor/models/whisper.py
WhisperEncoderAttention ¶
Bases: MultiHeadAttention
Multi-headed attention for Whisper encoder with 2D tensor support.
Source code in vllm/model_executor/models/whisper.py
forward ¶
batch_size x seq_len x hidden_size
or seq_len x hidden_size
Source code in vllm/model_executor/models/whisper.py
WhisperEncoderLayer ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
mlp instance-attribute
¶
mlp = WhisperMLP(
embed_dim=d_model,
ffn_dim=encoder_ffn_dim,
act_fn=activation_function,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
)
self_attn instance-attribute
¶
self_attn = WhisperAttention(
embed_dim=embed_dim,
num_heads=encoder_attention_heads,
attn_type=ENCODER,
cache_config=cache_config,
quant_config=quant_config,
prefix=f"{prefix}.self_attn",
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/whisper.py
forward ¶
forward(hidden_states: Tensor)
Source code in vllm/model_executor/models/whisper.py
WhisperForConditionalGeneration ¶
Bases: Module
, SupportsTranscription
, SupportsMultiModal
Source code in vllm/model_executor/models/whisper.py
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 |
|
hf_to_vllm_mapper class-attribute
instance-attribute
¶
hf_to_vllm_mapper = WeightsMapper(
orig_to_new_substr={
".fc1.": ".mlp.fc1.",
".fc2.": ".mlp.fc2.",
}
)
logits_processor instance-attribute
¶
logits_processor = LogitsProcessor(
unpadded_vocab_size, vocab_size, logit_scale
)
packed_modules_mapping class-attribute
instance-attribute
¶
packed_modules_mapping = {
"self_attn.qkv_proj": [
"self_attn.q_proj",
"self_attn.k_proj",
"self_attn.v_proj",
],
"encoder_attn.kv_proj": [
"encoder_attn.k_proj",
"encoder_attn.v_proj",
],
}
supported_languages class-attribute
instance-attribute
¶
supported_languages = ISO639_1_SUPPORTED_LANGS
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/whisper.py
_parse_and_validate_audio_input ¶
_parse_and_validate_audio_input(
**kwargs: object,
) -> WhisperAudioInputs
Source code in vllm/model_executor/models/whisper.py
compute_logits ¶
forward ¶
Source code in vllm/model_executor/models/whisper.py
get_generation_prompt classmethod
¶
get_generation_prompt(
audio: ndarray,
model_config: ModelConfig,
stt_config: SpeechToTextConfig,
language: Optional[str],
task_type: Literal["transcribe", "translate"],
request_prompt: str,
to_language: Optional[str],
) -> PromptType
Source code in vllm/model_executor/models/whisper.py
get_input_embeddings ¶
get_input_embeddings(
input_ids: Tensor,
multimodal_embeddings: Optional[
MultiModalEmbeddings
] = None,
*,
is_multimodal: Optional[Tensor] = None,
handle_oov_mm_token: bool = False,
) -> Tensor
Source code in vllm/model_executor/models/whisper.py
get_multimodal_embeddings ¶
get_multimodal_embeddings(
**kwargs: object,
) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/whisper.py
get_num_audio_tokens classmethod
¶
get_num_audio_tokens(
audio_duration_s: float,
stt_config: SpeechToTextConfig,
model_config: ModelConfig,
) -> Optional[int]
Source code in vllm/model_executor/models/whisper.py
get_placeholder_str classmethod
¶
get_speech_to_text_config classmethod
¶
get_speech_to_text_config(
model_config: ModelConfig, task_type: str
) -> SpeechToTextConfig
Source code in vllm/model_executor/models/whisper.py
load_weights ¶
Source code in vllm/model_executor/models/whisper.py
validate_language classmethod
¶
Source code in vllm/model_executor/models/whisper.py
WhisperMLP ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
fc1 instance-attribute
¶
fc1 = ColumnParallelLinear(
input_size=embed_dim,
output_size=ffn_dim,
quant_config=quant_config,
prefix=f"{prefix}.fc1",
)
fc2 instance-attribute
¶
fc2 = RowParallelLinear(
input_size=ffn_dim,
output_size=embed_dim,
quant_config=quant_config,
prefix=f"{prefix}.fc2",
)
__init__ ¶
__init__(
embed_dim: int,
ffn_dim: int,
act_fn: str,
quant_config: Optional[QuantizationConfig] = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/whisper.py
WhisperModel ¶
Bases: Module
Source code in vllm/model_executor/models/whisper.py
decoder instance-attribute
¶
decoder = WhisperDecoder(
vllm_config=vllm_config, prefix=f"{prefix}.decoder"
)
encoder instance-attribute
¶
encoder = WhisperEncoder(
vllm_config=vllm_config, prefix=f"{prefix}.encoder"
)
__init__ ¶
__init__(*, vllm_config: VllmConfig, prefix: str = '')
Source code in vllm/model_executor/models/whisper.py
forward ¶
forward(
input_features: Optional[Union[Tensor, list[Tensor]]],
input_ids: Optional[Tensor],
positions: Tensor,
) -> Tensor
Source code in vllm/model_executor/models/whisper.py
get_encoder_outputs ¶
load_weights ¶
Source code in vllm/model_executor/models/whisper.py
WhisperMultiModalProcessor ¶
Bases: EncDecMultiModalProcessor[WhisperProcessingInfo]
Source code in vllm/model_executor/models/whisper.py
_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/whisper.py
_get_data_parser ¶
_get_data_parser() -> MultiModalDataParser
_get_mm_fields_config ¶
_get_prompt_updates ¶
_get_prompt_updates(
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
out_mm_kwargs: MultiModalKwargsItems,
) -> Sequence[PromptUpdate]
Source code in vllm/model_executor/models/whisper.py
create_encoder_prompt ¶
create_encoder_prompt(
prompt: Union[str, list[int]],
mm_data: MultiModalDataDict,
) -> Union[str, list[int]]
Source code in vllm/model_executor/models/whisper.py
WhisperPositionalEmbedding ¶
WhisperProcessingInfo ¶
Bases: BaseProcessingInfo
Source code in vllm/model_executor/models/whisper.py
get_feature_extractor ¶
get_feature_extractor(
**kwargs: object,
) -> WhisperFeatureExtractor
Source code in vllm/model_executor/models/whisper.py
get_hf_config ¶
get_hf_processor ¶
get_hf_processor(**kwargs: object) -> WhisperProcessor
Source code in vllm/model_executor/models/whisper.py
_create_fake_bias_for_k_proj ¶
_create_fake_bias_for_k_proj(
weights: Iterable[tuple[str, Tensor]],
) -> Iterable[tuple[str, Tensor]]
Create full zeros bias for k_proj weight in self-attn and x-attn layers. So that the bias for k_proj in qkv_proj can be initialized with zeros.