Skip to content

Commit

Permalink
Fix lint errors
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 954dd06 commit 769507a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 5 additions & 7 deletions vllm/model_executor/models/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def for_embedding(cls: _T) -> _T:
from .utils import AutoWeightsLoader, WeightsMapper

class ModelForEmbedding(cls, VllmModelForEmbedding):

def __init__(
self,
*,
Expand Down Expand Up @@ -63,17 +64,15 @@ def pooler(
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]):
# We have deleted this attribute, so don't load it
weights = ((name, data) for name, data in weights
if not name.startswith("lm_head."))

if not name.startswith("lm_head."))

# If `*ForCausalLM` defines `load_weights` on the inner model
# and there are no other inner modules with parameters,
# we support loading from both `*Model` and `*ForCausalLM`
if (hasattr(self, "model") and hasattr(self.model, "load_weights")
and all(
name == "model" or all(False for _ in child.parameters())
for name, child in self.named_children()
)):
and all(name == "model" or all(False
for _ in child.parameters())
for name, child in self.named_children())):
mapper = WeightsMapper(orig_to_new_prefix={"model.": ""})
weights = mapper.apply(weights)

Expand All @@ -91,4 +90,3 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]):
.removesuffix("ForConditionalGeneration") + "ForEmbedding"

return ModelForEmbedding # type: ignore

5 changes: 4 additions & 1 deletion vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,10 @@ def __getitem__(self, key: type[T]) -> _V:

raise KeyError(key)

def __contains__(self, key: type[T]) -> bool:
def __contains__(self, key: object) -> bool:
if not isinstance(key, type):
return False

return any(cls in self.data for cls in key.mro())


Expand Down

0 comments on commit 769507a

Please sign in to comment.