Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions xinference/model/llm/llm_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ def _resolve_architectures(self) -> Optional[List[str]]:
return self.architectures
if not self.model_family:
return None
for family in BUILTIN_LLM_FAMILIES:
if family.model_name == self.model_family:
return family.architectures
from .custom import get_user_defined_llm_families

user_defined = {f.model_name: f for f in get_user_defined_llm_families()}
all_families = {f.model_name: f for f in BUILTIN_LLM_FAMILIES}
all_families.update(user_defined)
if self.model_family in all_families:
return all_families[self.model_family].architectures
return None
Comment on lines +168 to 175

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Rebuilding dictionaries for all builtin and user-defined families on every call to _resolve_architectures introduces unnecessary performance overhead, especially since builtin families are static and represent the vast majority of lookups.

Instead, we can first check BUILTIN_LLM_FAMILIES using a simple loop. If not found, we can then lazily import and check the user-defined families. This avoids the overhead of dictionary creation and imports for builtin models.

Suggested change
from .custom import get_user_defined_llm_families
user_defined = {f.model_name: f for f in get_user_defined_llm_families()}
all_families = {f.model_name: f for f in BUILTIN_LLM_FAMILIES}
all_families.update(user_defined)
if self.model_family in all_families:
return all_families[self.model_family].architectures
return None
for family in BUILTIN_LLM_FAMILIES:
if family.model_name == self.model_family:
return family.architectures
from .custom import get_user_defined_llm_families
for family in get_user_defined_llm_families():
if family.model_name == self.model_family:
return family.architectures
return None


def has_architecture(self, *architectures: str) -> bool:
Expand Down
Loading