vllm.model_executor.layers.mla ¶
MLAModules dataclass ¶
Modules used in MLA.
Source code in vllm/model_executor/layers/mla.py
__init__ ¶
__init__(
kv_a_layernorm: Module,
kv_b_proj: Module,
rotary_emb: Module,
o_proj: Module,
fused_qkv_a_proj: Module | None,
kv_a_proj_with_mqa: Module | None,
q_a_layernorm: Module | None,
q_b_proj: Module | None,
q_proj: Module | None,
indexer: Module | None,
is_sparse: bool,
topk_indices_buffer: Tensor | None,
indexer_rotary_emb: Module | None = None,
) -> None
MultiHeadLatentAttentionWrapper ¶
Bases: PluggableLayer
Pluggable MLA layer which allows OOT backends to add custom implementations of the outer MLA layer (including rope & o_proj). Note that currently oot platforms can still use CustomOp.register_oot to replace MLA layer entirly, although we use PluggableLayer to register this layer now.
This class takes positions and hidden_states as input. The input tensors can either contain prefill tokens or decode tokens. The class does the following:
- MLA Preprocess.
- Perform multi-head attention to prefill tokens and multi-query attention to decode tokens separately.
- Return the output tensor.
Source code in vllm/model_executor/layers/mla.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 | |
mla_attn instance-attribute ¶
mla_attn = MLAAttention(
num_heads=num_heads,
scale=scale,
qk_nope_head_dim=qk_nope_head_dim,
qk_rope_head_dim=qk_rope_head_dim,
v_head_dim=v_head_dim,
q_lora_rank=q_lora_rank,
kv_lora_rank=kv_lora_rank,
cache_config=cache_config,
quant_config=quant_config,
prefix=f"{prefix}.attn",
kv_b_proj=kv_b_proj,
use_sparse=is_sparse,
indexer=indexer,
)
__init__ ¶
__init__(
hidden_size: int,
num_heads: int,
scale: float,
qk_nope_head_dim: int,
qk_rope_head_dim: int,
v_head_dim: int,
q_lora_rank: int | None,
kv_lora_rank: int,
mla_modules: MLAModules,
cache_config: CacheConfig | None = None,
quant_config: QuantizationConfig | None = None,
prefix: str = "",
) -> None
Source code in vllm/model_executor/layers/mla.py
forward ¶
forward(
positions: Tensor,
hidden_states: Tensor,
llama_4_scaling: Tensor | None = None,
) -> Tensor