Skip to content

Conversation

felipemello1
Copy link
Contributor

@felipemello1 felipemello1 commented Nov 19, 2024

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

In this PR we removed apply_lora_to_output from vision encoder, but forgot to remove it from some places. This raises the error:

  File "/data/users/felipemello/torchtune/torchtune/models/llama3_2_vision/_model_builders.py", line 170, in lora_llama3_2_vision_11b
    encoder = lora_llama3_2_vision_encoder(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/users/felipemello/torchtune/torchtune/models/llama3_2_vision/_component_builders.py", line 439, in lora_llama3_2_vision_encoder
    clip = lora_clip_vision_encoder(**clip_options, **lora_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/users/felipemello/torchtune/torchtune/models/clip/_component_builders.py", line 289, in lora_clip_vision_encoder
    self_attn = lora_clip_attention(
                ^^^^^^^^^^^^^^^^^^^^
  File "/data/users/felipemello/torchtune/torchtune/models/clip/_component_builders.py", line 437, in lora_clip_attention
    adapter_cls(
  File "/data/users/felipemello/torchtune/torchtune/modules/peft/lora.py", line 78, in __init__
    else to_nf4(linear.weight, **quantization_kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: to_nf4() got an unexpected keyword argument 'apply_lora_to_output'

Additionally, in 4.0 we added a check for quantize_kwargs and quantize_base. This raises the error:
image

Test plan

image

Copy link

pytorch-bot bot commented Nov 19, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2028

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit c4d155f with merge base d5c54f3 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 19, 2024
Copy link
Contributor

@pbontrager pbontrager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. I think "apply_lora_to_output" still makes sense for the encoder, just not the CLIP model itself but still in the projection head.

num_hidden_inputs: int,
# LoRA args
apply_lora_to_mlp: bool,
apply_lora_to_output: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stay in the projection head, it just doesn't make sense in the CLIP model

lora_options = {
"lora_modules": lora_attn_modules,
"apply_lora_to_mlp": apply_lora_to_mlp,
"apply_lora_to_output": apply_lora_to_output,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed from here and manually added to the projection head call

self._quantize_base = quantize_base

if not self._quantize_base and quantization_kwargs:
if not self._quantize_base and any([v for v in quantization_kwargs.values()]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did and quantization_kwargs not work for a dictionary? you could also just check for length

Copy link
Contributor Author

@felipemello1 felipemello1 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question! it outputs something like: {use_lora_on_output: None}. Even though the value is None, it has a key, which fails the check

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In [1]: any([None])
Out[1]: False

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry {use_lora_on_output: None} should fail the check?

Copy link
Contributor Author

@felipemello1 felipemello1 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If quantize_base is false, then we should NOT have any quantization args, right? If no quantization is happenning, then why have these args?

So this assertion was failing, because quantize_base WAS false (not False --> True), but we have {use_lora_on_output: None}, which returns True.

So if True and True: raise error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Rafi here, there shouldn't be any kwargs passed in if quantize_base is False. {use_lora_on_output: None} should not be passed in when quantize_base = False.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

@pbontrager pbontrager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 24.88%. Comparing base (d0aa871) to head (c4d155f).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
torchtune/modules/peft/dora.py 0.00% 1 Missing ⚠️
torchtune/modules/peft/lora.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2028       +/-   ##
===========================================
- Coverage   67.27%   24.88%   -42.40%     
===========================================
  Files         318      318               
  Lines       17648    17631       -17     
===========================================
- Hits        11873     4387     -7486     
- Misses       5775    13244     +7469     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@felipemello1 felipemello1 merged commit d9b6c79 into meta-pytorch:main Nov 20, 2024
17 checks passed
@felipemello1 felipemello1 deleted the fix_vision_lora branch November 20, 2024 20:38
@ebsmothers ebsmothers mentioned this pull request Nov 26, 2024
44 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants