Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: DarkLight1337 <[email protected]>
  • Loading branch information
DarkLight1337 committed Nov 29, 2024
1 parent f73282e commit 5ae9cad
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions vllm/model_executor/models/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
_T = TypeVar("_T", bound=type[nn.Module])


def _is_paramless(module: nn.Module):
# NOTE: all([]) returns True
return all(False for _ in module.parameters())


def as_embedding_model(cls: _T) -> _T:
"""Subclass an existing vLLM model to support embeddings."""
# Avoid modifying existing embedding models
Expand All @@ -40,10 +35,9 @@ def __init__(
super().__init__(vllm_config=vllm_config, prefix=prefix, **kwargs)

# These are not used in embedding models
if hasattr(self, "lm_head"):
del self.lm_head
if hasattr(self, "logits_processor"):
del self.logits_processor
for attr in ("lm_head", "logits_processor"):
if hasattr(self, attr):
delattr(self, attr)

pooler_config = vllm_config.model_config.pooler_config
assert pooler_config is not None
Expand Down Expand Up @@ -77,7 +71,7 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]):
if hasattr(self, "model") and hasattr(self.model, "load_weights"):
# Whether only `self.model` contains parameters
model_is_only_param = all(
name == "model" or _is_paramless(child)
name == "model" or next(child.parameters(), None) is None
for name, child in self.named_children())

if model_is_only_param:
Expand Down

0 comments on commit 5ae9cad

Please sign in to comment.