Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
diffusers
Commits
bda825f9
Commit
bda825f9
authored
Jun 12, 2022
by
Patrick von Platen
Browse files
load pipeline from source
parent
e83ff11f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
src/diffusers/pipeline_utils.py
src/diffusers/pipeline_utils.py
+10
-7
No files found.
src/diffusers/pipeline_utils.py
View file @
bda825f9
...
...
@@ -34,6 +34,7 @@ logger = logging.get_logger(__name__)
LOADABLE_CLASSES
=
{
"diffusers"
:
{
"ModelMixin"
:
[
"save_pretrained"
,
"from_pretrained"
],
"DiffusionPipeline"
:
[
"save_pretrained"
,
"from_pretrained"
],
"GaussianDDPMScheduler"
:
[
"save_config"
,
"from_config"
],
"ClassifierFreeGuidanceScheduler"
:
[
"save_config"
,
"from_config"
],
"GlideDDIMScheduler"
:
[
"save_config"
,
"from_config"
],
...
...
@@ -74,7 +75,7 @@ class DiffusionPipeline(ConfigMixin):
# set models
setattr
(
self
,
name
,
module
)
register_dict
=
{
"_module"
:
self
.
__module__
.
split
(
"."
)[
-
1
]
+
".py"
}
register_dict
=
{
"_module"
:
self
.
__module__
.
split
(
"."
)[
-
1
]}
self
.
register
(
**
register_dict
)
def
save_pretrained
(
self
,
save_directory
:
Union
[
str
,
os
.
PathLike
]):
...
...
@@ -133,19 +134,21 @@ class DiffusionPipeline(ConfigMixin):
config_dict
=
cls
.
get_config_dict
(
cached_folder
)
# 2. Get class name and module candidates to load custom models
class_name_
=
config_dict
[
"_class_name"
]
module_candidate
=
config_dict
[
"_module"
]
module_candidate_name
=
module_candidate
.
replace
(
".py"
,
""
)
module_candidate_name
=
config_dict
[
"_module"
]
module_candidate
=
module_candidate_name
+
".py"
# 3. Load the pipeline class, if using custom module then load it from the hub
# if we load from explicit class, let's use it
if
cls
!=
DiffusionPipeline
:
pipeline_class
=
cls
else
:
diffusers_module
=
importlib
.
import_module
(
cls
.
__module__
.
split
(
"."
)[
0
])
pipeline_class
=
getattr
(
diffusers_module
,
config_dict
[
"_class_name"
])
# (TODO - we should allow to load custom pipelines
# else we need to load the correct module from the Hub
class_name_
=
config_dict
[
"_class_name"
]
module
=
module_candidate
pipeline_class
=
get_class_from_dynamic_module
(
cached_folder
,
module
,
class_name_
,
cached_folder
)
# module = module_candidate
# pipeline_class = get_class_from_dynamic_module(cached_folder, module, class_name_, cached_folder)
init_dict
,
_
=
pipeline_class
.
extract_init_dict
(
config_dict
,
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment