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

Add parameter to control rank of decomposition #28

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Training script accepts lora_rank
  • Loading branch information
brian6091 committed Dec 13, 2022
commit f1acfca9af9dbf7e7fae6188bdd4d04520dc460c
11 changes: 9 additions & 2 deletions train_lora_dreambooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ def parse_args(input_args=None):
action="store_true",
help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.",
)
parser.add_argument(
"--lora_rank",
type=int,
default=4,
help="Rank of LoRA approximation.",
)
parser.add_argument(
"--learning_rate",
type=float,
Expand Down Expand Up @@ -570,7 +576,7 @@ def main(args):
revision=args.revision,
)
unet.requires_grad_(False)
unet_lora_params, _ = inject_trainable_lora(unet)
unet_lora_params, _ = inject_trainable_lora(unet, r=args.lora_rank)

for _up, _down in extract_lora_ups_down(unet):
print("Before training: Unet First Layer lora up", _up.weight.data)
Expand All @@ -582,7 +588,8 @@ def main(args):

if args.train_text_encoder:
text_encoder_lora_params, _ = inject_trainable_lora(
text_encoder, target_replace_module=["CLIPAttention"]
text_encoder, target_replace_module=["CLIPAttention"],
r=args.lora_rank,
)
for _up, _down in extract_lora_ups_down(
text_encoder, target_replace_module=["CLIPAttention"]
Expand Down