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 bnb support for Ascend NPU #31512

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

statelesshz
Copy link
Contributor

@statelesshz statelesshz commented Jun 20, 2024

What does this PR do?

This PR can make bnb nf4 QLoRA out of the box on Ascend NPUs. 🤗

Related PR: bitsandbytes-foundation/bitsandbytes#1422

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@statelesshz statelesshz marked this pull request as draft June 20, 2024 07:15
@amyeroberts
Copy link
Collaborator

cc @younesbelkada @SunMarc

@younesbelkada
Copy link
Contributor

Thanks @statelesshz !
Let us know also with @Titus-von-Koeller once you have a WIP branch on bitsandbytes as well to add that in the multi-backend ongoing effort

@Titus-von-Koeller
Copy link
Contributor

Hey all!

I'm only aware of a backend stub that was added on the multi-backend-refactor branch by @statelesshz, no implementation logic. There wasn't much context given on the PR at the time, but since the implementation was yet to come, for me that was ok as is; as an incremental step.

@statelesshz Could you please elaborate a bit more what you mean by the following statement? Where does your implementation live right now?

internally we first added NPU support based on bitsandbytes-0.42.0

Generally, there've been quite a lot of changes in 0.43.0 and even 0.43.1 (the setup logic), so it would be really advisable to already take those changes into account.

Regarding the timeline: we'll go into public alpha/beta testing of the Intel/AMD backends, finalize the refactoring (integrating with the Torch dispatcher through the torch.library API) in the next weeks and do a full release soon after.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot closed this Jul 28, 2024
@SunMarc SunMarc reopened this Jul 29, 2024
@HuggingFaceDocBuilderDev

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.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@statelesshz
Copy link
Contributor Author

@younesbelkada @Titus-von-Koeller Good day! I have submitted a PR to add nf4 quant/dequant support to Ascend NPU. The corresponding end-to-end test results are as follows:
bitsandbytes-foundation/bitsandbytes#1422 (comment)
PTAL 🤗

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

+1 on @matthewdouglas comments ! LGTM otherwise

@statelesshz
Copy link
Contributor Author

@SunMarc I have deleted the changes of "Bnb4BitHfQuantizer". But CI has an error when executing check_repository_consistency. The specific error information is as follows:

Traceback (most recent call last):
  File "/root/transformers/utils/check_copies.py", line 1110, in <module>
    check_copies(args.fix_and_overwrite, args.file)
  File "/root/transformers/utils/check_copies.py", line 860, in check_copies
    raise Exception(
Exception: Found the following copy inconsistencies:
- src/transformers/quantizers/quantizer_bnb_4bit.py: copy does not match quantizers.quantizer_bnb_8bit.Bnb8BitHfQuantizer.update_device_map at line 271
Run `make fix-copies` or `python utils/check_copies.py --fix_and_overwrite` to fix them.

I tried to fix this problem locally based on the error message. After executing python utils/check_copies.py --fix_and_overwrite, it seemed that all the changes in this PR were rolled back. The specific result is shown in the figure below.
image

Any guidance would be appreciated.

@SunMarc
Copy link
Member

SunMarc commented Dec 9, 2024

Hey @statelesshz , this happens because this method have the following comment above:
# Copied from transformers.quantizers.quantizer_bnb_8bit.Bnb8BitHfQuantizer.update_device_map. So you just need to delete that line !

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM !

@statelesshz
Copy link
Contributor Author

Hey @statelesshz , this happens because this method have the following comment above: # Copied from transformers.quantizers.quantizer_bnb_8bit.Bnb8BitHfQuantizer.update_device_map. So you just need to delete that line !

Hey @SunMarc, thanks for your suggestion, it worked. CI reported that there was one test case failing, I think it's not caused by this PR.

@statelesshz
Copy link
Contributor Author

statelesshz commented Dec 11, 2024

The failing test case can pass in my local environment:
image

cc @SunMarc @younesbelkada

@SunMarc SunMarc requested a review from ArthurZucker December 11, 2024 14:11
@SunMarc
Copy link
Member

SunMarc commented Dec 11, 2024

The failing test case can pass in my local environment:

Indeed this is not related. Can you try to rebase the PR ? I've also pinged Arthur for a final check before merging

@statelesshz
Copy link
Contributor Author

@SunMarc done! 🤗

@statelesshz
Copy link
Contributor Author

Hey @ArthurZucker, could you help take a look at this PR, thanks :-)

@SlightwindSec
Copy link

Hey @ArthurZucker , this PR addresses a key issue I'm also facing, and I'm hoping it can be merged soon. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants