Skip to content

Commit

Permalink
read config from dict
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-chung committed Oct 18, 2023
1 parent b8c6230 commit 71fe301
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion optimum/exporters/onnx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions optimum/utils/normalized_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 71fe301

Please sign in to comment.