Skip to content

Commit bda2f18

Browse files
committed
make modular pipeline work with model_index.json
1 parent 9c13f86 commit bda2f18

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/diffusers/modular_pipelines/modular_pipeline.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,18 +1876,38 @@ def __init__(
18761876

18771877
# update component_specs and config_specs from modular_repo
18781878
if pretrained_model_name_or_path is not None:
1879-
config_dict = self.load_config(pretrained_model_name_or_path, **kwargs)
1880-
1881-
for name, value in config_dict.items():
1882-
# all the components in modular_model_index.json are from_pretrained components
1883-
if name in self._component_specs and isinstance(value, (tuple, list)) and len(value) == 3:
1884-
library, class_name, component_spec_dict = value
1885-
component_spec = self._dict_to_component_spec(name, component_spec_dict)
1886-
component_spec.default_creation_method = "from_pretrained"
1887-
self._component_specs[name] = component_spec
1888-
1889-
elif name in self._config_specs:
1890-
self._config_specs[name].default = value
1879+
1880+
try:
1881+
config_dict = self.load_config(pretrained_model_name_or_path, **kwargs)
1882+
for name, value in config_dict.items():
1883+
# all the components in modular_model_index.json are from_pretrained components
1884+
if name in self._component_specs and isinstance(value, (tuple, list)) and len(value) == 3:
1885+
library, class_name, component_spec_dict = value
1886+
component_spec = self._dict_to_component_spec(name, component_spec_dict)
1887+
component_spec.default_creation_method = "from_pretrained"
1888+
self._component_specs[name] = component_spec
1889+
1890+
elif name in self._config_specs:
1891+
self._config_specs[name].default = value
1892+
1893+
except EnvironmentError as e:
1894+
logger.debug(e)
1895+
logger.debug(f" modular_model_index.json not found in the repo, trying to load from model_index.json")
1896+
from diffusers import DiffusionPipeline
1897+
config_dict = DiffusionPipeline.load_config(pretrained_model_name_or_path)
1898+
for name, value in config_dict.items():
1899+
if name in self._component_specs and isinstance(value, (tuple, list)) and len(value) == 2:
1900+
library, class_name = value
1901+
component_spec_dict = {
1902+
"repo": pretrained_model_name_or_path,
1903+
"subfolder": name,
1904+
"type_hint": (library, class_name),
1905+
}
1906+
component_spec = self._dict_to_component_spec(name, component_spec_dict)
1907+
component_spec.default_creation_method = "from_pretrained"
1908+
self._component_specs[name] = component_spec
1909+
elif name in self._config_specs:
1910+
self._config_specs[name].default = value
18911911

18921912
register_components_dict = {}
18931913
for name, component_spec in self._component_specs.items():

0 commit comments

Comments
 (0)