- Notifications
You must be signed in to change notification settings - Fork 370
support exlusion of params when using low bit optim #1225
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
base: main
Are you sure you want to change the base?
support exlusion of params when using low bit optim #1225
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1225
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit d0278ab with merge base 4f8021f ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| Hi @nighting0le01! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
| Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
gau-nernst 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.
Thank you for the PR! Left some small comments.
| self.exclude_low_bit_optim_params_ids = set( | ||
| id(p) for p in exclude_low_bit_optim_params | ||
| ) if exclude_low_bit_optim_params else set() |
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.
I think you can hash tensor directly (it will use object id internally). PyTorch optimizer already hashes tensors when it uses params as keys in self.state.
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.
Can you try this? I don't think you need to use id(p) explicitly.
| @gau-nernst shall i also add configurable min_8bit_size like https://github.com/bitsandbytes-foundation/bitsandbytes/blob/9568735b21b9325e4789d6a5004517f2287f47c8/bitsandbytes/optim/optimizer.py#L603 over here :
|
| @nighting0le01 Adding something like Do you mind rebase/merge from main and make sure the tests pass? |
| hi @gau-nernst !
|
|
stack-info: PR: pytorch#1228, branch: drisspg/stack/19
* support dcp.save * add test for dcp.load() * fix test * typo * implement aten.slice * skip test * fix checks * run ruff * fix formatting * remove add safe globals in test * sort some imports --------- Co-authored-by: Mark Saroufim <marksaroufim@meta.com>
stack-info: PR: pytorch#1228, branch: drisspg/stack/19
stack-info: PR: pytorch#1228, branch: drisspg/stack/19
8d7f968 to a0dc6a9 Compare | @gau-nernst hi, sorry i was OOO for the last month, can you please run CI/CD now? verified test case passing locally |
@gau-nernst ran ruff check also now |
| topic: new feature can you please add this @gau-nernst . or any other topic that is relevant |
gau-nernst 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.
Ruff lint is still failing. Can you double check?
Failing CUDA night seems to be unrelated.
Requested some changes because some of the code has been changed since you last opened this PR. Lmk if you have any questions.
| from torchao.utils import ( | ||
| TORCH_VERSION_AT_LEAST_2_3, | ||
| TORCH_VERSION_AT_LEAST_2_4, | ||
| TORCH_VERSION_AT_LEAST_2_6, | ||
| ) |
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.
Don't reimport these
| loss1, loss2, msg=lambda msg: f"Iteration {idx}. {msg}" | ||
| ) | ||
| | ||
| @pytest.mark.skipif(not TORCH_VERSION_AT_LEAST_2_3, reason="requires PyTorch >= 2.3") |
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.
In our CI, min PyTorch version is 2.3. We don't need to check >=2.3 anymore. You can remove this line
| self.exclude_low_bit_optim_params_ids = set( | ||
| id(p) for p in exclude_low_bit_optim_params | ||
| ) if exclude_low_bit_optim_params else set() |
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.
Can you try this? I don't think you need to use id(p) explicitly.
| | ||
| # follow bitsandbytes, only quantize tensors >= 4096 values | ||
| if local_p.numel() >= 4096 and local_p.numel() % self.block_size == 0: | ||
| if p.numel() >= 4096 and p.numel() % self.block_size == 0 and id(p) not in self.exclude_low_bit_optim_params_ids: |
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.
You should keep using local_p here for FSDP to work correctly (the check on divisibility should be done on local tensor, not the full tensor)
Furthermore, the check id(p) not in self.exclude_low_bit_optim_params_ids should be done before this. Just short-circuit it e.g. (if p in self.exclude_low_bit_optim_params: return torch.zeros_like(p))
| cc @nighting0le01 are you still planning on working on this? |
| Sure let me land it this week …On Wed, Mar 19, 2025 at 12:13 PM Jesse Cai ***@***.***> wrote: cc @nighting0le01 <https://github.com/nighting0le01> are you still planning on working on this? — Reply to this email directly, view it on GitHub <#1225 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ATO4RLPMNAL4LQ7JXTOYRKD2VG6WBAVCNFSM6AAAAABRHTVSCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZXG42TIOJQGE> . You are receiving this because you were mentioned.Message ID: ***@***.***> [image: jcaip]*jcaip* left a comment (pytorch/ao#1225) <#1225 (comment)> cc @nighting0le01 <https://github.com/nighting0le01> are you still planning on working on this? — Reply to this email directly, view it on GitHub <#1225 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ATO4RLPMNAL4LQ7JXTOYRKD2VG6WBAVCNFSM6AAAAABRHTVSCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZXG42TIOJQGE> . You are receiving this because you were mentioned.Message ID: ***@***.***> |
This PR allows, exclusion and inclusion of params layerwise when using low bit optimizers. this will allow for improving stability by running certain layers with 32 bit adam. https://huggingface.co/docs/bitsandbytes/main/en/optimizers