From 71fe30112ba793259e740981dcc21e59a2fd8b4f Mon Sep 17 00:00:00 2001 From: Isaac Chung Date: Wed, 18 Oct 2023 19:42:41 +0300 Subject: [PATCH] read config from dict --- optimum/exporters/onnx/__main__.py | 2 +- optimum/utils/normalized_config.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/optimum/exporters/onnx/__main__.py b/optimum/exporters/onnx/__main__.py index 6f9accb7539..1b601cdfb8d 100644 --- a/optimum/exporters/onnx/__main__.py +++ b/optimum/exporters/onnx/__main__.py @@ -351,7 +351,7 @@ def main_export( custom_architecture = False is_stable_diffusion = "stable-diffusion" in task - model_type = "stable-diffusion" if is_stable_diffusion else model.config.model_type.replace("_", "-") + model_type = "stable-diffusion" if is_stable_diffusion else model.config.model_type.replace("_", "-") if legacy and model_type in MODEL_TYPES_REQUIRING_POSITION_IDS and task.startswith("text-generation"): logger.warning( diff --git a/optimum/utils/normalized_config.py b/optimum/utils/normalized_config.py index 335bb4dabcf..8ed9746f7bd 100644 --- a/optimum/utils/normalized_config.py +++ b/optimum/utils/normalized_config.py @@ -58,6 +58,11 @@ def __getattr__(self, attr_name): for attr in attr_name[:-1]: config = getattr(config, attr) + # We cast potential dictionaries to PretrainedConfig for getattr to work for nested structures, where nested dictionaries + # may not always themselves be PretrainedConfig instances (e.g. timm, open_clip). + if isinstance(config, dict): + config = PretrainedConfig.from_dict(config) + attr = getattr(config, leaf_attr_name, None) # If the attribute was not specified manually, try to fallback on the attribute_map.