vllm.model_executor.models.glmasr ¶
GlmAsrInputs module-attribute ¶
GlmAsrInputs: TypeAlias = (
GlmAsrFeatureInputs | GlmAsrEmbeddingInputs
)
GlmAsrDummyInputsBuilder ¶
Bases: BaseDummyInputsBuilder[GlmAsrProcessingInfo]
Builder for dummy inputs used in profiling and testing.
Generates dummy text prompts and audio data that match the expected format for GLM-ASR model inputs. Used for memory profiling and performance benchmarking.
Source code in vllm/model_executor/models/glmasr.py
get_dummy_mm_data ¶
get_dummy_mm_data(
seq_len: int,
mm_counts: Mapping[str, int],
mm_options: Mapping[str, BaseDummyOptions]
| None = None,
) -> MultiModalDataDict
Source code in vllm/model_executor/models/glmasr.py
get_dummy_text ¶
GlmAsrEmbeddingInputs ¶
Bases: TensorSchema
Dimensions
- bn: Batch size
- naf: Number of audio features
- hs: Hidden size (must match the hidden size of language model backbone)
Source code in vllm/model_executor/models/glmasr.py
GlmAsrEncoder ¶
Bases: Module
Optimized GLM-ASR Audio Encoder with vLLM native implementation.
This encoder processes audio features through convolutional layers followed by transformer layers with rotary position embeddings. Optimized for performance with: - QKVParallelLinear for fused attention projections - Tensor parallelism support via ColumnParallelLinear/RowParallelLinear - Quantization support - Flash Attention (SDPA)
Source code in vllm/model_executor/models/glmasr.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 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 519 520 521 522 523 524 525 526 | |
conv2 instance-attribute ¶
conv2 = Conv1d(
hidden_size,
hidden_size,
kernel_size=3,
stride=2,
padding=1,
)
layers instance-attribute ¶
layers = ModuleList(
[
(
GlmAsrEncoderLayer(
config,
quant_config=quant_config,
prefix=f"{prefix}.layers.{layer_idx}",
)
)
for layer_idx in (range(num_hidden_layers))
]
)
packed_modules_mapping class-attribute instance-attribute ¶
__init__ ¶
__init__(
config,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/glmasr.py
_get_feat_extract_output_lengths ¶
Compute the output length after convolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_lengths | Tensor | Input sequence lengths [batch_size] | required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor] | Tuple of (output after conv1, output after conv2) |
Source code in vllm/model_executor/models/glmasr.py
forward ¶
forward(input_features: Tensor) -> _GlmAsrEncoderOutput
Forward pass through the encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features | Tensor | [batch_size, num_mel_bins, seq_len] | required |
Returns:
| Name | Type | Description |
|---|---|---|
_GlmAsrEncoderOutput | _GlmAsrEncoderOutput | Object with .last_hidden_state attribute containing [batch_size, seq_len', hidden_size] where seq_len' is the sequence length after convolutions |
Source code in vllm/model_executor/models/glmasr.py
load_weights ¶
Custom weight loading to handle q_proj/k_proj/v_proj -> qkv_proj mapping.
Source code in vllm/model_executor/models/glmasr.py
GlmAsrEncoderAttention ¶
Bases: Module
Optimized Multi-headed Grouped Query Attention for GLM-ASR encoder.
Uses vLLM's QKVParallelLinear for fused projections, ApplyRotaryEmb for rotary position embeddings, and MMEncoderAttention for hardware-optimized attention computation with automatic backend selection.
Source code in vllm/model_executor/models/glmasr.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 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 | |
attn instance-attribute ¶
attn = MMEncoderAttention(
num_heads=num_heads_per_rank,
head_size=head_dim,
scale=head_dim**-0.5,
num_kv_heads=num_kv_heads_per_rank,
prefix=f"{prefix}.attn",
)
num_kv_heads instance-attribute ¶
num_kv_heads = getattr(
config, "num_key_value_heads", num_attention_heads
)
o_proj instance-attribute ¶
o_proj = RowParallelLinear(
hidden_size,
hidden_size,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.o_proj",
)
qkv_proj instance-attribute ¶
qkv_proj = QKVParallelLinear(
hidden_size,
head_dim,
num_heads,
num_kv_heads,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.qkv_proj",
)
__init__ ¶
__init__(
config,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/glmasr.py
forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | [batch_size, seq_len, hidden_size] | required |
rotary_pos_emb_cos | Tensor | [seq_len, rotary_dim/2] - cosine of rotary embeddings | required |
rotary_pos_emb_sin | Tensor | [seq_len, rotary_dim/2] - sine of rotary embeddings | required |
Returns:
| Type | Description |
|---|---|
Tensor | [batch_size, seq_len, hidden_size] |
Source code in vllm/model_executor/models/glmasr.py
GlmAsrEncoderLayer ¶
Bases: Module
Optimized Transformer encoder layer for GLM-ASR. Combines attention and MLP with residual connections and layer norms.
Source code in vllm/model_executor/models/glmasr.py
mlp instance-attribute ¶
mlp = GlmAsrEncoderMLP(
config,
quant_config=quant_config,
prefix=f"{prefix}.mlp",
)
post_attention_layernorm instance-attribute ¶
post_attention_layernorm = LayerNorm(
hidden_size, eps=layer_norm_eps
)
self_attn instance-attribute ¶
self_attn = GlmAsrEncoderAttention(
config,
quant_config=quant_config,
prefix=f"{prefix}.self_attn",
)
__init__ ¶
__init__(
config,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/glmasr.py
forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | [batch_size, seq_len, hidden_size] | required |
rotary_pos_emb_cos | Tensor | [seq_len, rotary_dim/2] - cosine of rotary embeddings | required |
rotary_pos_emb_sin | Tensor | [seq_len, rotary_dim/2] - sine of rotary embeddings | required |
Returns:
| Type | Description |
|---|---|
Tensor | [batch_size, seq_len, hidden_size] |
Source code in vllm/model_executor/models/glmasr.py
GlmAsrEncoderMLP ¶
Bases: Module
Optimized MLP for GLM-ASR encoder. Uses vLLM's parallel linear layers for better performance.
Source code in vllm/model_executor/models/glmasr.py
fc1 instance-attribute ¶
fc1 = ColumnParallelLinear(
hidden_size,
intermediate_size,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.fc1",
)
fc2 instance-attribute ¶
fc2 = RowParallelLinear(
intermediate_size,
hidden_size,
bias=True,
quant_config=quant_config,
prefix=f"{prefix}.fc2",
)
__init__ ¶
__init__(
config,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/glmasr.py
forward ¶
GlmAsrEncoderRotaryEmbedding ¶
Bases: Module
Rotary Position Embedding for GLM-ASR encoder.
Computes rotary position embeddings on-demand for efficiency. Only caches inv_freq as a buffer; cos/sin are computed during forward to avoid wasted computation during initialization and ensure correct device placement.
Source code in vllm/model_executor/models/glmasr.py
__init__ ¶
Source code in vllm/model_executor/models/glmasr.py
forward ¶
Compute rotary position frequencies for given sequence length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seq_len | int | The sequence length to compute embeddings for. | required |
Returns:
| Type | Description |
|---|---|
Tensor | Frequency tensor with shape [seq_len, dim/2]. Use .cos() and |
Tensor | .sin() to get the rotary embedding components. |
Source code in vllm/model_executor/models/glmasr.py
GlmAsrFeatureInputs ¶
Bases: TensorSchema
Dimensions
- num_chunks: Number of audio chunks (flattened)
- nmb: Number of mel bins
- num_audios: Number of original audio files
Source code in vllm/model_executor/models/glmasr.py
chunk_counts instance-attribute ¶
chunk_counts: Annotated[
Tensor | list[Tensor], TensorShape(num_audios)
]
feature_attention_mask instance-attribute ¶
feature_attention_mask: Annotated[
Tensor | list[Tensor],
TensorShape(
num_chunks,
chunk_length,
dynamic_dims={chunk_length},
),
]
GlmAsrForConditionalGeneration ¶
Bases: Module, SupportsMultiModal, SupportsPP, SupportsLoRA, SupportsTranscription
Source code in vllm/model_executor/models/glmasr.py
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 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 | |
audio_tower instance-attribute ¶
audio_tower = GlmAsrEncoder(
audio_config,
quant_config=quant_config,
prefix=maybe_prefix(prefix, "audio_tower"),
)
language_model instance-attribute ¶
language_model = init_vllm_registered_model(
vllm_config=vllm_config,
hf_config=text_config,
prefix=maybe_prefix(prefix, "language_model"),
architectures=["LlamaForCausalLM"],
)
make_empty_intermediate_tensors instance-attribute ¶
multi_modal_projector instance-attribute ¶
multi_modal_projector = GlmAsrMultiModalProjector(
config,
quant_config=quant_config,
prefix=maybe_prefix(prefix, "multi_modal_projector"),
)
packed_modules_mapping class-attribute instance-attribute ¶
packed_modules_mapping = {
"qkv_proj": ["q_proj", "k_proj", "v_proj"],
"gate_up_proj": ["gate_proj", "up_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/glmasr.py
_get_audio_token classmethod ¶
_get_audio_token(model_config: ModelConfig) -> str
Get the audio token from processor.
Similar to get_placeholder_str but returns single token.
Source code in vllm/model_executor/models/glmasr.py
_parse_and_validate_audio_input ¶
_parse_and_validate_audio_input(
**kwargs: object,
) -> GlmAsrInputs | None
Source code in vllm/model_executor/models/glmasr.py
_process_audio_input ¶
_process_audio_input(
audio_input: GlmAsrInputs,
) -> Tensor | tuple[Tensor, ...]
Source code in vllm/model_executor/models/glmasr.py
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | |
compute_logits ¶
embed_multimodal ¶
embed_multimodal(**kwargs: object) -> MultiModalEmbeddings
Source code in vllm/model_executor/models/glmasr.py
forward ¶
forward(
input_ids: Tensor,
positions: Tensor,
intermediate_tensors: IntermediateTensors | None = None,
inputs_embeds: Tensor | None = None,
**kwargs: object,
) -> Tensor | IntermediateTensors
Source code in vllm/model_executor/models/glmasr.py
get_generation_prompt classmethod ¶
get_generation_prompt(
audio: ndarray,
model_config: ModelConfig,
stt_config: SpeechToTextConfig,
language: str | None,
task_type: Literal["transcribe", "translate"],
request_prompt: str,
to_language: str | None,
) -> PromptType
Get the generation prompt to be used for transcription requests.
Source code in vllm/model_executor/models/glmasr.py
get_mm_mapping ¶
get_mm_mapping() -> MultiModelKeys
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/glmasr.py
load_weights ¶
GlmAsrMultiModalDataParser ¶
Bases: MultiModalDataParser
Custom parser for GLM-ASR multimodal data.
Extends the base parser to handle GLM-ASR specific audio data formats, including both pre-computed audio embeddings and raw audio features.
Source code in vllm/model_executor/models/glmasr.py
_parse_audio_data ¶
_parse_audio_data(
data: dict[str, Tensor] | ModalityData[Any],
) -> ModalityDataItems[Any, Any] | None
Source code in vllm/model_executor/models/glmasr.py
GlmAsrMultiModalProcessor ¶
Bases: BaseMultiModalProcessor['GlmAsrProcessingInfo']
GLM-ASR processor that inherits directly from BaseMultiModalProcessor for better performance and cleaner implementation.
Source code in vllm/model_executor/models/glmasr.py
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 | |
_calculate_chunk_counts ¶
_calculate_chunk_counts(
audio_list: list[Any],
feature_extractor: WhisperFeatureExtractor,
processor: GlmAsrProcessor,
) -> list[int]
Source code in vllm/model_executor/models/glmasr.py
_call_hf_processor ¶
_call_hf_processor(
prompt: str,
mm_data: dict[str, object],
mm_kwargs: Mapping[str, Any],
tok_kwargs: Mapping[str, object],
) -> BatchFeature
Source code in vllm/model_executor/models/glmasr.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/glmasr.py
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 | |
GlmAsrMultiModalProjector ¶
Bases: Module
Projects audio encoder outputs to language model hidden space.
This projector uses a two-layer MLP to map audio features from the encoder's intermediate size to the language model's hidden size. Uses vLLM's parallel linear layers for tensor parallelism support.
Architecture
- Linear layer: intermediate_size -> hidden_size * 2
- Activation function (e.g., GELU)
- Linear layer: hidden_size * 2 -> hidden_size
Source code in vllm/model_executor/models/glmasr.py
linear_1 instance-attribute ¶
linear_1 = ColumnParallelLinear(
input_size=intermediate_size,
output_size=hidden_size * 2,
quant_config=quant_config,
prefix=f"{prefix}.linear_1",
)
linear_2 instance-attribute ¶
linear_2 = RowParallelLinear(
input_size=hidden_size * 2,
output_size=hidden_size,
quant_config=quant_config,
prefix=f"{prefix}.linear_2",
)
__init__ ¶
__init__(
config: GlmAsrConfig,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
)
Source code in vllm/model_executor/models/glmasr.py
forward ¶
GlmAsrProcessingInfo ¶
Bases: BaseProcessingInfo
Processing information provider for GLM-ASR model.
Provides access to model configuration, processor, and feature extractor needed for audio preprocessing and multimodal integration.
Source code in vllm/model_executor/models/glmasr.py
_GlmAsrEncoderOutput ¶
Simple output container compatible with transformers' BaseModelOutput.
This lightweight container holds the encoder output and is compatible with the transformers library's output format while being more efficient than a full dataclass.
Attributes:
| Name | Type | Description |
|---|---|---|
last_hidden_state | Final layer hidden states from the encoder. Shape: [batch_size, seq_len, hidden_size] |
Source code in vllm/model_executor/models/glmasr.py
_glmasr_field_config ¶
Configure multimodal field batching strategy for GLM-ASR.
Determines how to batch audio inputs based on whether chunking is used. When chunk_counts is present, features are flattened across chunks; otherwise, they are batched normally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hf_inputs | Mapping[str, Tensor] | Dictionary of preprocessed inputs from HuggingFace processor. | required |
Returns:
| Type | Description |
|---|---|
dict[str, MultiModalFieldConfig] | Dictionary mapping field names to MultiModalFieldConfig objects that specify batching behavior. |