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 3d67982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 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

14 changes: 9 additions & 5 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,14 +1542,18 @@ def __len__(self):

class ClassRegistry(UserDict[type[T], _V]):

def __getitem__(self, key: type[T]) -> _V:
for cls in key.mro():
if cls in self.data:
return self.data[cls]
def __getitem__(self, key: object) -> _V:
if isinstance(key, type):
for cls in key.mro():
if cls in self.data:
return self.data[cls]

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 3d67982

Please sign in to comment.