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
0e975e5f
Unverified
Commit
0e975e5f
authored
Feb 27, 2023
by
Patrick von Platen
Committed by
GitHub
Feb 27, 2023
Browse files
[Safetensors] Make sure metadata is saved (#2506)
* [Safetensors] Make sure metadata is saved * make style
parent
7f43f652
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
src/diffusers/models/modeling_utils.py
src/diffusers/models/modeling_utils.py
+6
-4
No files found.
src/diffusers/models/modeling_utils.py
View file @
0e975e5f
...
@@ -291,9 +291,6 @@ class ModelMixin(torch.nn.Module):
...
@@ -291,9 +291,6 @@ class ModelMixin(torch.nn.Module):
logger
.
error
(
f
"Provided path (
{
save_directory
}
) should be a directory, not a file"
)
logger
.
error
(
f
"Provided path (
{
save_directory
}
) should be a directory, not a file"
)
return
return
if
save_function
is
None
:
save_function
=
safetensors
.
torch
.
save_file
if
safe_serialization
else
torch
.
save
os
.
makedirs
(
save_directory
,
exist_ok
=
True
)
os
.
makedirs
(
save_directory
,
exist_ok
=
True
)
model_to_save
=
self
model_to_save
=
self
...
@@ -310,7 +307,12 @@ class ModelMixin(torch.nn.Module):
...
@@ -310,7 +307,12 @@ class ModelMixin(torch.nn.Module):
weights_name
=
_add_variant
(
weights_name
,
variant
)
weights_name
=
_add_variant
(
weights_name
,
variant
)
# Save the model
# Save the model
save_function
(
state_dict
,
os
.
path
.
join
(
save_directory
,
weights_name
))
if
safe_serialization
:
safetensors
.
torch
.
save_file
(
state_dict
,
os
.
path
.
join
(
save_directory
,
weights_name
),
metadata
=
{
"format"
:
"pt"
}
)
else
:
torch
.
save
(
state_dict
,
os
.
path
.
join
(
save_directory
,
weights_name
))
logger
.
info
(
f
"Model weights saved in
{
os
.
path
.
join
(
save_directory
,
weights_name
)
}
"
)
logger
.
info
(
f
"Model weights saved in
{
os
.
path
.
join
(
save_directory
,
weights_name
)
}
"
)
...
...
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