vllm.model_executor.models.transformers.causal
¶
Transformers modeling backend mixin for causal language models.
Classes:
-
CausalMixin– -
HeadKind–How the output head of a
ForCausalLMis run. -
OutputHead–What a
ForCausalLMapplies after its base model.
Functions:
-
probe_output_head–The
scaleandsoft_capofLogitsProcessorwhichoutput_headapplies -
stub_base_model–Make the class of
base_modelbuild_OpaqueBaseModel(base_model)instead, -
to_output_head–Turn
model, aForCausalLMbuilt withstub_base_model, into its output
CausalMixin
¶
Bases: VllmModelForTextGeneration, Base
Methods:
-
load_weights–A thin wrapper around
Base.load_weightsto handle the lm_head bias.
_create_output_head()
¶
The output head of the model's Transformers class, run as the first
HeadKind it supports, or lm_head with the config's logit scaling if it has
none or it cannot be run.
_project(hidden_states)
¶
The output embeddings, which give the logits on every TP rank.
load_weights(weights)
¶
A thin wrapper around Base.load_weights to handle the lm_head bias.
HeadKind
¶
Bases: Enum
How the output head of a ForCausalLM is run.
Attributes:
-
LM_HEAD–lm_headandLogitsProcessorwith the probedscaleandsoft_cap. -
OPAQUE–The whole
ForCausalLMincompute_logits, callinglm_headitself. -
PRE_HEAD–pre_headon every token inforward, thenLM_HEAD, so that
LM_HEAD = auto()
class-attribute
instance-attribute
¶
lm_head and LogitsProcessor with the probed scale and soft_cap.
OPAQUE = auto()
class-attribute
instance-attribute
¶
The whole ForCausalLM in compute_logits, calling lm_head itself.
PRE_HEAD = auto()
class-attribute
instance-attribute
¶
pre_head on every token in forward, then LM_HEAD, so that
LoRA can index its adapters by token.
OutputHead
dataclass
¶
What a ForCausalLM applies after its base model.
Attributes:
-
in_features(int) –The input size of the output embeddings.
-
model(PreTrainedModel | None) –The
ForCausalLMwith its base model stubbed out, untilkindis decided. -
output_embeddings(_OutputEmbeddings) –Stands in for the output embeddings in
model. -
weights_mapper(WeightsMapper) –Maps the checkpoint names of the head's weights and modules to vLLM's.
in_features
instance-attribute
¶
The input size of the output embeddings.
model
instance-attribute
¶
The ForCausalLM with its base model stubbed out, until kind is decided.
output_embeddings = field(default_factory=_OutputEmbeddings)
class-attribute
instance-attribute
¶
Stands in for the output embeddings in model.
weights_mapper = field(default_factory=WeightsMapper)
class-attribute
instance-attribute
¶
Maps the checkpoint names of the head's weights and modules to vLLM's.
_BaseModelOutput
¶
Bases: BaseModelOutputWithPast
Has every other output a ForCausalLM may read (e.g. cross_attentions),
as None.
_OpaqueBaseModel
¶
Bases: Module
Stands in for base_model and for its submodules (e.g. OPT's
model.decoder), returning inputs_embeds as its output.
_OutputEmbeddings
¶
Calls project in place of the output embeddings, or is the identity until
project is set. Not an nn.Module, so that the weights stay registered only
in lm_head.
_module_renames(renames)
¶
The largest modules whose weights all move together under renames, mapped
to where they move (e.g. decoder -> lm_head for Ettin's decoder.weight and
decoder.bias). Unlike weight names, these also rename names below them, such as
LoRA's decoder.lora_A.weight and quantization configs' module names.
probe_output_head(output_head, hidden_size)
¶
The scale and soft_cap of LogitsProcessor which output_head applies
after its output embeddings, which must still be the identity, or None if it
applies anything else.
stub_base_model(base_model)
¶
Make the class of base_model build _OpaqueBaseModel(base_model) instead,
so that a ForCausalLM can be built without building its base model again.
_new stays on the class afterwards and builds it as usual, because deleting
an assigned __new__ leaves CPython passing the class's arguments on to
object.__new__, which rejects them.
to_output_head(model)
¶
Turn model, a ForCausalLM built with stub_base_model, into its output
head in place.
The output embeddings are replaced with _OutputEmbeddings, so
model(inputs_embeds=h) applies everything the ForCausalLM applies after its
base model (e.g. a dense -> act -> norm transform, a soft cap, a scale).
Returns None (leaving model unchanged) if this is not possible.