Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update convertodiffv1.py #2728

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Dreambooth/convertodiffv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ def shave_segments(path, n_shave_prefix_segments=1):
"""
Removes segments. Positive values shave the first segments, negative shave the last segments.
"""
if n_shave_prefix_segments >= 0:
return ".".join(path.split(".")[n_shave_prefix_segments:])
else:
return ".".join(path.split(".")[:n_shave_prefix_segments])

return ".".join(path.split(".")[n_shave_prefix_segments:]) if n_shave_prefix_segments > -1 else ".".join(path.split(".")[:n_shave_prefix_segments])


def renew_resnet_paths(old_list, n_shave_prefix_segments=0):
"""
Expand Down Expand Up @@ -183,11 +180,7 @@ def assign_to_checkpoint(
new_path = new_path.replace(replacement["old"], replacement["new"])

# proj_attn.weight has to be converted from conv 1D to linear
if "proj_attn.weight" in new_path:
checkpoint[new_path] = old_checkpoint[path["old"]][:, :, 0]
else:
checkpoint[new_path] = old_checkpoint[path["old"]]

checkpoint[new_path] = old_checkpoint[path["old"]][:, :, 0] if "proj_attn.weight" in new_path else old_checkpoint[path["old"]]

def conv_attn_to_linear(checkpoint):
keys = list(checkpoint.keys())
Expand Down