vllm.model_executor.models.transformers.fusers.base ¶
Base classes for the Transformers backend fusers.
Classes:
-
BaseFuser–A detected fusion and how to apply it.
-
RewriteFuser–A fuser that rewrites the module's forward and rebinds it.
-
StackedFuser–A fuser that merges sibling projections into one stacked linear and
Functions:
-
fused_head_size–The head size of
module, which head counts are derived from. -
local_output_sizes–Source for the per-rank widths of the merged linear
self.<merged_name>.
BaseFuser dataclass ¶
Bases: ABC
A detected fusion and how to apply it.
match analyses the module class once (cached, see get_fusers); fuse then applies the fusion to an instance in recursive_replace, returning the module to install in its place.
Methods:
-
fuse–Apply the fusion to an already-validated
module, returning the -
info–A human-readable description of the fusion at
name, for logging. -
match–Match the pattern in
graph, returning a fuser if found. -
orig_to_new_stacked–WeightsMapper.orig_to_new_stackedentries this fuser contributes -
validate–Whether this fuser can be applied to this
moduleinstance.
Attributes:
-
packed_modules_mapping(dict[str, list[str]]) –packed_modules_mappingentries this fuser contributes (none unless -
redefines_forward(bool) –Whether
fusegives the module a different forward,
Source code in vllm/model_executor/models/transformers/fusers/base.py
packed_modules_mapping property ¶
packed_modules_mapping entries this fuser contributes (none unless it stacks weights).
redefines_forward = True class-attribute ¶
Whether fuse gives the module a different forward, by rewriting its source or by returning a different module in its place.
fuse(module, prefix, vllm_config) abstractmethod ¶
Apply the fusion to an already-validated module, returning the module to install in its place (mutated in place, or freshly built).
Source code in vllm/model_executor/models/transformers/fusers/base.py
info(name) abstractmethod ¶
match(graph, module) abstractmethod classmethod ¶
Match the pattern in graph, returning a fuser if found.
orig_to_new_stacked(prefix) ¶
WeightsMapper.orig_to_new_stacked entries this fuser contributes (none unless it stacks weights).
validate(module, vllm_config) abstractmethod ¶
RewriteFuser dataclass ¶
Bases: BaseFuser
A fuser that rewrites the module's forward and rebinds it.
match and update_forward analyse the class once; fuse swaps the submodules and binds the compiled forward on an instance in place, so it keeps its class and any attribute the fusion does not consume.
Methods:
-
fuse–Fuse an already-validated
modulein place (seeFusers.__getitem__). -
update_attrs–Replace
module's submodules with their vLLM equivalents. -
update_forward–Rewrite and compile
type(module)'s forward source.
Attributes:
-
fused_forward(Callable) –The compiled rewritten forward, set by
update_forward. -
source_cls(str) –Class of the HF module the fused projections belonged to (for logging).
Source code in vllm/model_executor/models/transformers/fusers/base.py
fused_forward = field(init=False, repr=False) class-attribute instance-attribute ¶
The compiled rewritten forward, set by update_forward.
source_cls instance-attribute ¶
Class of the HF module the fused projections belonged to (for logging).
fuse(module, prefix, vllm_config) ¶
Fuse an already-validated module in place (see Fusers.__getitem__).
Builds the merged submodule and binds the compiled forward.
Source code in vllm/model_executor/models/transformers/fusers/base.py
update_attrs(module, prefix, vllm_config) abstractmethod ¶
Replace module's submodules with their vLLM equivalents.
update_forward(module) abstractmethod ¶
Rewrite and compile type(module)'s forward source.
Raises if the source does not admit the rewrite (fusion is then skipped).
StackedFuser dataclass ¶
Bases: RewriteFuser
A fuser that merges sibling projections into one stacked linear and rewrites the forward to call it.
Methods:
-
orig_to_new_stacked–WeightsMapper.orig_to_new_stackedentries for one fused instance.
Attributes:
-
merged_cls_name(str) –Name of the vLLM class the merged projection becomes (for logging).
-
merged_name(str) –Attribute name of the merged module created by
update_attrs. -
packed_modules_mapping(dict[str, list[str]]) –{merged_name: [projection names]}so quantization can unpack the -
shards(list[tuple[str, ShardId]]) –Each projection's original name and its shard id in the merged module.
Source code in vllm/model_executor/models/transformers/fusers/base.py
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 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 | |
merged_cls_name class-attribute ¶
Name of the vLLM class the merged projection becomes (for logging).
merged_name class-attribute ¶
Attribute name of the merged module created by update_attrs.
packed_modules_mapping property ¶
{merged_name: [projection names]} so quantization can unpack the fused layer into its per-shard configs.
shards abstractmethod property ¶
Each projection's original name and its shard id in the merged module.
Source for both orig_to_new_stacked and packed_modules_mapping.
_check_input_stable(funcdef, module, calls, block, indices) ¶
Raise unless hoisting the merged GEMM preserves what it reads.
Fusing moves every projection to one call at min(indices), so the merged GEMM reads the input once, up front, where the last of calls would have read it later. That holds only if nothing in between changes the input, and a change need not name it: writing any view that shares its storage changes it too. Both halves of the check over-approximate, since a false hit costs a fusion while a miss returns wrong numbers.
Source code in vllm/model_executor/models/transformers/fusers/base.py
_splice_merged_split(funcdef, calls, block, index) ¶
Insert temps = self.<merged_name>(arg).split(sizes, -1) at block[index] and replace each of calls with its temp name.
calls must share one input argument; block[index] must be where they are (or would be) evaluated. Raises if a generated temporary would shadow an existing name in funcdef.
Source code in vllm/model_executor/models/transformers/fusers/base.py
_unguarded_calls(funcdef, names) ¶
One self.<name>(arg) call per projection, existence guards folded.
update_attrs deletes the projections it merges, so any reference to one beyond its call site must be a guard on its existence; folding those to their constant value keeps the rewritten forward off a name that no longer exists. A reference that is not such a guard raises, so fusion is skipped.
Source code in vllm/model_executor/models/transformers/fusers/base.py
orig_to_new_stacked(prefix) ¶
WeightsMapper.orig_to_new_stacked entries for one fused instance.
Maps each checkpoint name to (merged_name, shard_id), keyed by qualname so only this exact layer is remapped, never a same-named projection elsewhere (e.g. an unfused MoE expert's gate_proj).
Source code in vllm/model_executor/models/transformers/fusers/base.py
fused_head_size(module, vllm_config) ¶
The head size of module, which head counts are derived from.
Prefer the module's own head_dim, which Transformers sets per instance: the model-wide value is the largest head size across layers, so on a heterogeneous checkpoint it would divide out the wrong number of heads, and it is the text head size, so it does not describe a vision tower at all.
Source code in vllm/model_executor/models/transformers/fusers/base.py
local_output_sizes(merged_name) ¶
Source for the per-rank widths of the merged linear self.<merged_name>.