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
3f7edc5f
Unverified
Commit
3f7edc5f
authored
Nov 09, 2022
by
Duong A. Nguyen
Committed by
GitHub
Nov 09, 2022
Browse files
Fix layer names convert LDM script (#1206)
fix script convert LDM
parent
cd77a036
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
13 deletions
+14
-13
scripts/convert_ldm_original_checkpoint_to_diffusers.py
scripts/convert_ldm_original_checkpoint_to_diffusers.py
+14
-13
No files found.
scripts/convert_ldm_original_checkpoint_to_diffusers.py
View file @
3f7edc5f
...
@@ -112,9 +112,9 @@ def assign_to_checkpoint(
...
@@ -112,9 +112,9 @@ def assign_to_checkpoint(
continue
continue
# Global renaming happens here
# Global renaming happens here
new_path
=
new_path
.
replace
(
"middle_block.0"
,
"mid.resnets.0"
)
new_path
=
new_path
.
replace
(
"middle_block.0"
,
"mid
_block
.resnets.0"
)
new_path
=
new_path
.
replace
(
"middle_block.1"
,
"mid.attentions.0"
)
new_path
=
new_path
.
replace
(
"middle_block.1"
,
"mid
_block
.attentions.0"
)
new_path
=
new_path
.
replace
(
"middle_block.2"
,
"mid.resnets.1"
)
new_path
=
new_path
.
replace
(
"middle_block.2"
,
"mid
_block
.resnets.1"
)
if
additional_replacements
is
not
None
:
if
additional_replacements
is
not
None
:
for
replacement
in
additional_replacements
:
for
replacement
in
additional_replacements
:
...
@@ -175,15 +175,16 @@ def convert_ldm_checkpoint(checkpoint, config):
...
@@ -175,15 +175,16 @@ def convert_ldm_checkpoint(checkpoint, config):
attentions
=
[
key
for
key
in
input_blocks
[
i
]
if
f
"input_blocks.
{
i
}
.1"
in
key
]
attentions
=
[
key
for
key
in
input_blocks
[
i
]
if
f
"input_blocks.
{
i
}
.1"
in
key
]
if
f
"input_blocks.
{
i
}
.0.op.weight"
in
checkpoint
:
if
f
"input_blocks.
{
i
}
.0.op.weight"
in
checkpoint
:
new_checkpoint
[
f
"down
sample
_blocks.
{
block_id
}
.downsamplers.0.conv.weight"
]
=
checkpoint
[
new_checkpoint
[
f
"down_blocks.
{
block_id
}
.downsamplers.0.conv.weight"
]
=
checkpoint
[
f
"input_blocks.
{
i
}
.0.op.weight"
f
"input_blocks.
{
i
}
.0.op.weight"
]
]
new_checkpoint
[
f
"down
sample
_blocks.
{
block_id
}
.downsamplers.0.conv.bias"
]
=
checkpoint
[
new_checkpoint
[
f
"down_blocks.
{
block_id
}
.downsamplers.0.conv.bias"
]
=
checkpoint
[
f
"input_blocks.
{
i
}
.0.op.bias"
f
"input_blocks.
{
i
}
.0.op.bias"
]
]
continue
paths
=
renew_resnet_paths
(
resnets
)
paths
=
renew_resnet_paths
(
resnets
)
meta_path
=
{
"old"
:
f
"input_blocks.
{
i
}
.0"
,
"new"
:
f
"down
sample
_blocks.
{
block_id
}
.resnets.
{
layer_in_block_id
}
"
}
meta_path
=
{
"old"
:
f
"input_blocks.
{
i
}
.0"
,
"new"
:
f
"down_blocks.
{
block_id
}
.resnets.
{
layer_in_block_id
}
"
}
resnet_op
=
{
"old"
:
"resnets.2.op"
,
"new"
:
"downsamplers.0.op"
}
resnet_op
=
{
"old"
:
"resnets.2.op"
,
"new"
:
"downsamplers.0.op"
}
assign_to_checkpoint
(
assign_to_checkpoint
(
paths
,
new_checkpoint
,
checkpoint
,
additional_replacements
=
[
meta_path
,
resnet_op
],
config
=
config
paths
,
new_checkpoint
,
checkpoint
,
additional_replacements
=
[
meta_path
,
resnet_op
],
config
=
config
...
@@ -193,18 +194,18 @@ def convert_ldm_checkpoint(checkpoint, config):
...
@@ -193,18 +194,18 @@ def convert_ldm_checkpoint(checkpoint, config):
paths
=
renew_attention_paths
(
attentions
)
paths
=
renew_attention_paths
(
attentions
)
meta_path
=
{
meta_path
=
{
"old"
:
f
"input_blocks.
{
i
}
.1"
,
"old"
:
f
"input_blocks.
{
i
}
.1"
,
"new"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
"
,
"new"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
"
,
}
}
to_split
=
{
to_split
=
{
f
"input_blocks.
{
i
}
.1.qkv.bias"
:
{
f
"input_blocks.
{
i
}
.1.qkv.bias"
:
{
"key"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.key.bias"
,
"key"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.key.bias"
,
"query"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.query.bias"
,
"query"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.query.bias"
,
"value"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.value.bias"
,
"value"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.value.bias"
,
},
},
f
"input_blocks.
{
i
}
.1.qkv.weight"
:
{
f
"input_blocks.
{
i
}
.1.qkv.weight"
:
{
"key"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.key.weight"
,
"key"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.key.weight"
,
"query"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.query.weight"
,
"query"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.query.weight"
,
"value"
:
f
"down
sample
_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.value.weight"
,
"value"
:
f
"down_blocks.
{
block_id
}
.attentions.
{
layer_in_block_id
}
.value.weight"
,
},
},
}
}
assign_to_checkpoint
(
assign_to_checkpoint
(
...
...
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