vllm.model_executor.models.transformers.fusers.base ¶
Base classes for the Transformers backend fusers.
Classes:
-
BaseFuser–A detected fusion and how to apply it.
-
StackedFuser–A fuser that merges sibling projections into one stacked linear and
BaseFuser dataclass ¶
Bases: ABC
A detected fusion and how to apply it.
match analyses the module class once (cached, see get_fuser); 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
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).
fuse(module, prefix, model_config, quant_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, model_config) abstractmethod ¶
StackedFuser dataclass ¶
Bases: BaseFuser
A fuser that merges sibling projections into one stacked linear and rewrites the forward to call it.
match and update_forward analyse the class once; fuse builds the merged submodule 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__). -
orig_to_new_stacked–WeightsMapper.orig_to_new_stackedentries for one fused instance. -
update_attrs–Replace
module's submodules with the merged module. -
update_forward–Rewrite and compile
type(module)'s forward source.
Attributes:
-
fused_forward(Callable) –The compiled rewritten forward, set by
update_forward. -
merged_cls(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_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.
merged_cls 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.
source_cls instance-attribute ¶
Class of the HF module the fused projections belonged to (for logging).
fuse(module, prefix, model_config, quant_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
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
update_attrs(module, prefix, model_config, quant_config) abstractmethod ¶
Replace module's submodules with the merged module.
Source code in vllm/model_executor/models/transformers/fusers/base.py
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).