Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid library_name guessing if it is known in parameters standartization #2179

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,11 @@ def infer_library_from_model(
return library_name

@classmethod
def standardize_model_attributes(cls, model: Union["PreTrainedModel", "TFPreTrainedModel", "DiffusionPipeline"]):
def standardize_model_attributes(
cls,
model: Union["PreTrainedModel", "TFPreTrainedModel", "DiffusionPipeline"],
library_name: Optional[str] = None,
):
"""
Updates the model for export. This function is suitable to make required changes to the models from different
libraries to follow transformers style.
Expand All @@ -2078,7 +2082,8 @@ def standardize_model_attributes(cls, model: Union["PreTrainedModel", "TFPreTrai

"""

library_name = TasksManager.infer_library_from_model(model)
if library_name is None:
library_name = TasksManager.infer_library_from_model(model)

if library_name == "diffusers":
inferred_model_type = None
Expand Down Expand Up @@ -2295,7 +2300,7 @@ def get_model_from_task(
kwargs["from_pt"] = True
model = model_class.from_pretrained(model_name_or_path, **kwargs)

TasksManager.standardize_model_attributes(model)
TasksManager.standardize_model_attributes(model, library_name=library_name)

return model

Expand Down
2 changes: 1 addition & 1 deletion optimum/subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_namespace_modules(namespace: str, module: str):
"""
for dist in importlib_metadata.distributions():
dist_name = dist.metadata["Name"]
if not dist_name.startswith(f"{namespace}-"):
if dist_name is None or not dist_name.startswith(f"{namespace}-"):
continue
if dist_name == f"{namespace}-benchmark":
continue
IlyasMoutawwakil marked this conversation as resolved.
Show resolved Hide resolved
Expand Down