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 verbosity option for resize_lora.py #179

Merged
merged 2 commits into from
Feb 14, 2023

Conversation

mgz-dev
Copy link
Contributor

@mgz-dev mgz-dev commented Feb 11, 2023

  • add --verbose flag to print additional statistics in resize_lora_model function
  • correct device parameter reference in resize_lora_model function

The verbose print statement will give some additional metrics on the SVD reduction at each layer.

  • sum(S) retained is the sum of magnitudes for the resized LoRA's singular values compared against sum of magnitudes for the original LoRA's singular values (reported as a percentage).
  • max(S) ratio is the largest magnitude singular value compared against the largest magnitude singular value which was dropped during the resize.

General notes:

  • Losing some "information" during resize does not always mean lower quality results, as lowering rank can have a denoising effect.
  • Good target values for these metrics are domain specific, and to my knowledge, not known yet for this use case.
  • Initial recommendations are to pay more attention to the second metric (max s ratios) than the first. The closer the ratio is to 1, the less accurate the resized rank representation was able to represent that layer.
  • Visual inspection of final resulting outputs from LoRA is still the best way to check effectiveness of resized LoRA at this time.

Example of partial output from resizing rank 128 to rank 32:

lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn1_to_k           | sum(S) retained: 71.0%, max(S) ratio: 3.5
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn1_to_out_0       | sum(S) retained: 65.1%, max(S) ratio: 10.2
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn1_to_q           | sum(S) retained: 66.9%, max(S) ratio: 4.4
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn1_to_v           | sum(S) retained: 66.8%, max(S) ratio: 12.4
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn2_to_k           | sum(S) retained: 81.2%, max(S) ratio: 22.3
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn2_to_out_0       | sum(S) retained: 75.9%, max(S) ratio: 16.9
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn2_to_q           | sum(S) retained: 79.3%, max(S) ratio: 18.1
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_attn2_to_v           | sum(S) retained: 81.5%, max(S) ratio: 20.5
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_ff_net_0_proj        | sum(S) retained: 54.2%, max(S) ratio: 2.9
lora_unet_up_blocks_3_attentions_2_transformer_blocks_0_ff_net_2             | sum(S) retained: 66.7%, max(S) ratio: 6.6

add --verbose flag to print additional statistics during resize_lora function
correct some parameter references in resize_lora_model function
@kohya-ss
Copy link
Owner

Thank you for this! I am not familiar with SVD, so this PR is much appreciated. It will also help many users.

@kohya-ss kohya-ss changed the base branch from main to dev February 14, 2023 10:50
@kohya-ss kohya-ss merged commit f771396 into kohya-ss:dev Feb 14, 2023
@mgz-dev mgz-dev deleted the resize_lora-verbose-print branch March 10, 2023 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants