[Model] Use context managers for encoder- and LM-only mode (#32605)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -70,12 +70,14 @@ from vllm.sequence import IntermediateTensors
|
||||
from vllm.utils.tensor_schema import TensorSchema, TensorShape
|
||||
|
||||
from .interfaces import (
|
||||
LMMissingLayer,
|
||||
MixtureOfExperts,
|
||||
MultiModalEmbeddings,
|
||||
SupportsEagle3,
|
||||
SupportsLoRA,
|
||||
SupportsMultiModal,
|
||||
SupportsPP,
|
||||
TowerMissingLayer,
|
||||
)
|
||||
from .llama4 import Llama4ForCausalLM
|
||||
from .utils import (
|
||||
@@ -773,7 +775,8 @@ class Llama4ForConditionalGeneration(
|
||||
self.config = config
|
||||
self.quant_config = quant_config
|
||||
self.multimodal_config = multimodal_config
|
||||
if multimodal_config.get_limit_per_prompt("image"):
|
||||
|
||||
with self._mark_tower_model(vllm_config, "image"):
|
||||
from vllm.compilation.backends import set_model_tag
|
||||
|
||||
with (
|
||||
@@ -792,16 +795,15 @@ class Llama4ForConditionalGeneration(
|
||||
quant_config=None,
|
||||
prefix=maybe_prefix(prefix, "multi_modal_projector"),
|
||||
)
|
||||
else:
|
||||
self.vision_model = None
|
||||
self.multi_modal_projector = None
|
||||
self.language_model = initialize_model(
|
||||
vllm_config=vllm_config.with_hf_config(
|
||||
config.text_config, ["LlamaForCausalLM"]
|
||||
),
|
||||
prefix=maybe_prefix(prefix, "language_model"),
|
||||
model_class=Llama4ForCausalLM,
|
||||
)
|
||||
|
||||
with self._mark_language_model(vllm_config):
|
||||
self.language_model = initialize_model(
|
||||
vllm_config=vllm_config.with_hf_config(
|
||||
config.text_config, ["LlamaForCausalLM"]
|
||||
),
|
||||
prefix=maybe_prefix(prefix, "language_model"),
|
||||
model_class=Llama4ForCausalLM,
|
||||
)
|
||||
|
||||
self.make_empty_intermediate_tensors = (
|
||||
self.language_model.make_empty_intermediate_tensors
|
||||
@@ -892,9 +894,6 @@ class Llama4ForConditionalGeneration(
|
||||
for img in vision_embeddings_flat.split(patches_per_image, dim=0)
|
||||
]
|
||||
|
||||
def get_language_model(self) -> torch.nn.Module:
|
||||
return self.language_model
|
||||
|
||||
def embed_multimodal(self, **kwargs) -> MultiModalEmbeddings:
|
||||
image_input = self._parse_and_validate_image_input(**kwargs)
|
||||
if image_input is None:
|
||||
@@ -1024,6 +1023,10 @@ class Llama4ForConditionalGeneration(
|
||||
for name, weight in weights:
|
||||
renamed = self._rename_weight_for_modelopt_checkpoint(name)
|
||||
|
||||
attr = renamed.split(".", 1)[0]
|
||||
if isinstance(getattr(self, attr), (LMMissingLayer, TowerMissingLayer)):
|
||||
continue
|
||||
|
||||
if renamed.startswith("language_model."):
|
||||
language_model_weights.append((renamed, weight))
|
||||
else:
|
||||
@@ -1133,10 +1136,6 @@ class Llama4ForConditionalGeneration(
|
||||
weights
|
||||
)
|
||||
|
||||
# Skip loading vision model and projector if they're not initialized.
|
||||
if self.vision_model is None and self.multi_modal_projector is None:
|
||||
other_weights = []
|
||||
|
||||
# Handle expert scale parameters
|
||||
regular_weights, expert_scale_weights, updated_params_from_experts = (
|
||||
self._handle_expert_scale_broadcasting(language_model_weights, params_dict)
|
||||
|
||||
Reference in New Issue
Block a user