Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
bda825f9
"git@developer.sourcefind.cn:OpenDAS/fairscale.git" did not exist on "5be4817dc15e27c336b37e2c8d297cc4ff8dc6cc"
Commit
bda825f9
authored
Jun 12, 2022
by
Patrick von Platen
Browse files
load pipeline from source
parent
e83ff11f
Changes
1
Hide 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__)
...
@@ -34,6 +34,7 @@ logger = logging.get_logger(__name__)
LOADABLE_CLASSES
=
{
LOADABLE_CLASSES
=
{
"diffusers"
:
{
"diffusers"
:
{
"ModelMixin"
:
[
"save_pretrained"
,
"from_pretrained"
],
"ModelMixin"
:
[
"save_pretrained"
,
"from_pretrained"
],
"DiffusionPipeline"
:
[
"save_pretrained"
,
"from_pretrained"
],
"GaussianDDPMScheduler"
:
[
"save_config"
,
"from_config"
],
"GaussianDDPMScheduler"
:
[
"save_config"
,
"from_config"
],
"ClassifierFreeGuidanceScheduler"
:
[
"save_config"
,
"from_config"
],
"ClassifierFreeGuidanceScheduler"
:
[
"save_config"
,
"from_config"
],
"GlideDDIMScheduler"
:
[
"save_config"
,
"from_config"
],
"GlideDDIMScheduler"
:
[
"save_config"
,
"from_config"
],
...
@@ -74,7 +75,7 @@ class DiffusionPipeline(ConfigMixin):
...
@@ -74,7 +75,7 @@ class DiffusionPipeline(ConfigMixin):
# set models
# set models
setattr
(
self
,
name
,
module
)
setattr
(
self
,
name
,
module
)
register_dict
=
{
"_module"
:
self
.
__module__
.
split
(
"."
)[
-
1
]
+
".py"
}
register_dict
=
{
"_module"
:
self
.
__module__
.
split
(
"."
)[
-
1
]}
self
.
register
(
**
register_dict
)
self
.
register
(
**
register_dict
)
def
save_pretrained
(
self
,
save_directory
:
Union
[
str
,
os
.
PathLike
]):
def
save_pretrained
(
self
,
save_directory
:
Union
[
str
,
os
.
PathLike
]):
...
@@ -133,19 +134,21 @@ class DiffusionPipeline(ConfigMixin):
...
@@ -133,19 +134,21 @@ class DiffusionPipeline(ConfigMixin):
config_dict
=
cls
.
get_config_dict
(
cached_folder
)
config_dict
=
cls
.
get_config_dict
(
cached_folder
)
# 2. Get class name and module candidates to load custom models
# 2. Get class name and module candidates to load custom models
class_name_
=
config_dict
[
"_class_name"
]
module_candidate_name
=
config_dict
[
"_module"
]
module_candidate
=
config_dict
[
"_module"
]
module_candidate
=
module_candidate_name
+
".py"
module_candidate_name
=
module_candidate
.
replace
(
".py"
,
""
)
# 3. Load the pipeline class, if using custom module then load it from the hub
# 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 we load from explicit class, let's use it
if
cls
!=
DiffusionPipeline
:
if
cls
!=
DiffusionPipeline
:
pipeline_class
=
cls
pipeline_class
=
cls
else
:
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
# else we need to load the correct module from the Hub
class_name_
=
config_dict
[
"_class_name"
]
# module = module_candidate
module
=
module_candidate
# pipeline_class = get_class_from_dynamic_module(cached_folder, module, class_name_, cached_folder)
pipeline_class
=
get_class_from_dynamic_module
(
cached_folder
,
module
,
class_name_
,
cached_folder
)
init_dict
,
_
=
pipeline_class
.
extract_init_dict
(
config_dict
,
**
kwargs
)
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