-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix RS-LoRA scaling in set_scale #2775
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
Fix RS-LoRA scaling in set_scale #2775
Conversation
|
Hey @BenjaminBossan! I have raised a PR to fix this issue. Please take a look when you have a moment and let me know if anything needs to be updated further. |
BenjaminBossan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this PR. Before we proceed, let's add some unit tests to ensure that everything works as expected. As a starting point, check these tests:
(
peft/tests/test_initialization.py
Lines 3857 to 3892 in 5d97453
| def test_scaling_simple(self, model): | |
| n_layers = 5 | |
| rank, lora_alpha = 8, 16 | |
| config = LoraConfig( | |
| r=rank, | |
| lora_alpha=lora_alpha, | |
| target_modules=["k_proj"], | |
| ) | |
| model = get_peft_model(model, config) | |
| scalings = self.get_scalings(model) | |
| expected = [lora_alpha / rank] * n_layers | |
| assert scalings == expected | |
| # double | |
| self.scale_layer(model, 2) | |
| scalings = self.get_scalings(model) | |
| expected = [4.0] * n_layers | |
| assert scalings == expected | |
| # back to original | |
| self.unscale_layer(model, None) | |
| scalings = self.get_scalings(model) | |
| expected = [2.0] * n_layers | |
| assert scalings == expected | |
| # triple | |
| self.set_scale(model, "default", 3) | |
| scalings = self.get_scalings(model) | |
| expected = [6.0] * n_layers | |
| assert scalings == expected | |
| # back to original | |
| self.unscale_layer(model, 3) | |
| scalings = self.get_scalings(model) | |
| expected = [2.0] * n_layers | |
| assert scalings == expected |
I would suggest that you create a copy of these tests with a new name, e.g. test_scaling_rslora, and then change the testing code to use rslora. Change the expected values accordingly. LMK if you have questions.
|
@
Thank you @BenjaminBossan, for reviewing it. I will add the test file as soon as possible. |
|
@tanuj-rai When the PR is ready for another review, please ping me. |
|
@BenjaminBossan I'm trying to run the test |
|
@tanuj-rai The reason why you cannot run your test is because you put it in a separate file. If you place it below the other tests I referenced above, it will work. Why? Because in that test class, a so called When you move your tests over there, you should give the function a unique name, e.g. |
Ahh, I see. Thank you @BenjaminBossan. That was my mistake. I’ve removed it now and added the new test function 'test_scaling_with_rslora' into test_initialization.py. |
|
When I am running the pytest. It got deselected. |
Strange, when I run the exact same command on your branch, the test runs as expected. It does, however, raise an error because |
@BenjaminBossan! As you said, it is running fine for you. But I don't know why it skips it when I run pytest. What should I do now to fix it? I have added |
BenjaminBossan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I am running the pytest. It got deselected.
Strange. What if you just run pytest tests/test_initialization.py -v? This runs all the tests and thus takes a bit longer, but the one you added should be on the list.
I checked the added tests and I think they need a few adjustments. Also, please run make style before pushing your code. Thanks.
BenjaminBossan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updated test. It revealed that there is actually another location in the code where rslora needs to be taken into account, check my comment.
What if you just run
pytest tests/test_initialization.py -v?
Could you make this run?
|
Hi @BenjaminBossan, I’ve updated unscale_layer to correctly handle rslora by resetting to lora_alpha / sqrt(r) when scale=None. Please take a look and let me know if anything needs to be updated. |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Thanks for the update @tanuj-rai. The tests are passing now. If the PR is ready from your side, please convert it from draft to "ready for review". |
Thanks, @BenjaminBossan for reviewing it. I have converted it from draft to "ready for review". |
BenjaminBossan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good, thanks for working on this issue.
This PR fixes a scaling mismatch for RS-LoRA adapters when calling set_scale
Fixes issue #2733
Who can review:
@BenjaminBossan