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
d73e6ad0
Unverified
Commit
d73e6ad0
authored
Sep 08, 2023
by
Will Berman
Committed by
GitHub
Sep 08, 2023
Browse files
guard save model hooks to only execute on main process (#4929)
parent
d0cf681a
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
147 additions
and
133 deletions
+147
-133
examples/controlnet/train_controlnet.py
examples/controlnet/train_controlnet.py
+8
-7
examples/controlnet/train_controlnet_sdxl.py
examples/controlnet/train_controlnet_sdxl.py
+8
-7
examples/dreambooth/train_dreambooth.py
examples/dreambooth/train_dreambooth.py
+6
-5
examples/dreambooth/train_dreambooth_lora.py
examples/dreambooth/train_dreambooth_lora.py
+20
-19
examples/dreambooth/train_dreambooth_lora_sdxl.py
examples/dreambooth/train_dreambooth_lora_sdxl.py
+24
-23
examples/instruct_pix2pix/train_instruct_pix2pix.py
examples/instruct_pix2pix/train_instruct_pix2pix.py
+7
-6
examples/instruct_pix2pix/train_instruct_pix2pix_sdxl.py
examples/instruct_pix2pix/train_instruct_pix2pix_sdxl.py
+7
-6
examples/research_projects/controlnet/train_controlnet_webdataset.py
...search_projects/controlnet/train_controlnet_webdataset.py
+8
-7
examples/research_projects/onnxruntime/text_to_image/train_text_to_image.py
...projects/onnxruntime/text_to_image/train_text_to_image.py
+7
-6
examples/research_projects/onnxruntime/unconditional_image_generation/train_unconditional.py
...ime/unconditional_image_generation/train_unconditional.py
+7
-6
examples/text_to_image/train_text_to_image.py
examples/text_to_image/train_text_to_image.py
+7
-6
examples/text_to_image/train_text_to_image_lora_sdxl.py
examples/text_to_image/train_text_to_image_lora_sdxl.py
+24
-23
examples/text_to_image/train_text_to_image_sdxl.py
examples/text_to_image/train_text_to_image_sdxl.py
+7
-6
examples/unconditional_image_generation/train_unconditional.py
...les/unconditional_image_generation/train_unconditional.py
+7
-6
No files found.
examples/controlnet/train_controlnet.py
View file @
d73e6ad0
...
...
@@ -785,6 +785,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
i
=
len
(
weights
)
-
1
while
len
(
weights
)
>
0
:
...
...
examples/controlnet/train_controlnet_sdxl.py
View file @
d73e6ad0
...
...
@@ -840,6 +840,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
i
=
len
(
weights
)
-
1
while
len
(
weights
)
>
0
:
...
...
examples/dreambooth/train_dreambooth.py
View file @
d73e6ad0
...
...
@@ -920,6 +920,7 @@ def main(args):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
for
model
in
models
:
sub_dir
=
"unet"
if
isinstance
(
model
,
type
(
accelerator
.
unwrap_model
(
unet
)))
else
"text_encoder"
model
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
sub_dir
))
...
...
examples/dreambooth/train_dreambooth_lora.py
View file @
d73e6ad0
...
...
@@ -894,6 +894,7 @@ def main(args):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
# there are only two options here. Either are just the unet attn processor layers
# or there are the unet and text encoder atten layers
unet_lora_layers_to_save
=
None
...
...
examples/dreambooth/train_dreambooth_lora_sdxl.py
View file @
d73e6ad0
...
...
@@ -798,6 +798,7 @@ def main(args):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
# there are only two options here. Either are just the unet attn processor layers
# or there are the unet and text encoder atten layers
unet_lora_layers_to_save
=
None
...
...
examples/instruct_pix2pix/train_instruct_pix2pix.py
View file @
d73e6ad0
...
...
@@ -485,6 +485,7 @@ def main():
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_unet
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/instruct_pix2pix/train_instruct_pix2pix_sdxl.py
View file @
d73e6ad0
...
...
@@ -528,6 +528,7 @@ def main():
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_unet
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/research_projects/controlnet/train_controlnet_webdataset.py
View file @
d73e6ad0
...
...
@@ -1010,6 +1010,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
i
=
len
(
weights
)
-
1
while
len
(
weights
)
>
0
:
...
...
examples/research_projects/onnxruntime/text_to_image/train_text_to_image.py
View file @
d73e6ad0
...
...
@@ -552,6 +552,7 @@ def main():
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_unet
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/research_projects/onnxruntime/unconditional_image_generation/train_unconditional.py
View file @
d73e6ad0
...
...
@@ -313,6 +313,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_model
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/text_to_image/train_text_to_image.py
View file @
d73e6ad0
...
...
@@ -629,6 +629,7 @@ def main():
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_unet
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/text_to_image/train_text_to_image_lora_sdxl.py
View file @
d73e6ad0
...
...
@@ -669,6 +669,7 @@ def main(args):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
# there are only two options here. Either are just the unet attn processor layers
# or there are the unet and text encoder atten layers
unet_lora_layers_to_save
=
None
...
...
examples/text_to_image/train_text_to_image_sdxl.py
View file @
d73e6ad0
...
...
@@ -651,6 +651,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_unet
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
examples/unconditional_image_generation/train_unconditional.py
View file @
d73e6ad0
...
...
@@ -309,6 +309,7 @@ def main(args):
if
version
.
parse
(
accelerate
.
__version__
)
>=
version
.
parse
(
"0.16.0"
):
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
def
save_model_hook
(
models
,
weights
,
output_dir
):
if
accelerator
.
is_main_process
:
if
args
.
use_ema
:
ema_model
.
save_pretrained
(
os
.
path
.
join
(
output_dir
,
"unet_ema"
))
...
...
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