-
-
Notifications
You must be signed in to change notification settings - Fork 816
Add support for Intel Gaudi/HPU backend #1662
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
Merged
matthewdouglas
merged 5 commits into
bitsandbytes-foundation:main
from
rsshaik1:Gaudi_support
Jun 5, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ccd3d7
supports hpu backend in main branch
rsshaik1 fff24d6
Update bitsandbytes/backends/hpu/ops.py
rsshaik1 805fb6b
Update bitsandbytes/backends/hpu/ops.py
rsshaik1 3900187
Update ops.py
matthewdouglas 1542c18
Update ops.py
matthewdouglas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from collections.abc import Sequence | ||
| import math | ||
|
|
||
| import torch | ||
|
|
||
| from bitsandbytes.utils import _reverse_4bit_compress_format | ||
|
|
||
| from ..._ops import register_kernel | ||
| from ..utils import GAUDI_SW_VER | ||
|
|
||
|
|
||
| @register_kernel("bitsandbytes::dequantize_4bit", "hpu") | ||
| def _( | ||
| A: torch.Tensor, | ||
| absmax: torch.Tensor, | ||
| blocksize: int, | ||
| quant_type: str, | ||
| shape: Sequence[int], | ||
| dtype: torch.dtype, | ||
| ) -> torch.Tensor: | ||
| torch._check_is_size(blocksize) | ||
| torch._check(quant_type == "nf4", lambda: f"quant_type must be nf4, got {quant_type}") | ||
| torch._check( | ||
| A.dtype in [torch.bfloat16, torch.uint8], | ||
| lambda: f"quant_storage supports uint8 or bfloat16, but got {A.dtype}", | ||
| ) | ||
|
|
||
| # Enable non uint8 dtype | ||
| if A.dtype != torch.uint8: | ||
| A = A.view(torch.uint8) | ||
|
|
||
| transpose = False if len(A.shape) == 2 and A.shape[0] == 1 else True | ||
|
|
||
| A = A.reshape(-1) | ||
|
|
||
| if GAUDI_SW_VER and (GAUDI_SW_VER.major < 1 or GAUDI_SW_VER.minor < 22): | ||
| A = _reverse_4bit_compress_format(A) | ||
|
|
||
| # HPU dequantization function for NF4 quantized tensors. | ||
| out_dq = torch.ops.hpu.dequantize_nf4( | ||
| A, | ||
| absmax.to(dtype), | ||
| blocksize, | ||
| out_shape=(math.prod(shape),), | ||
| out_dtype=dtype, | ||
| ) | ||
|
|
||
| output = out_dq.reshape(shape) | ||
|
|
||
| if transpose: | ||
| output = output.t() | ||
|
|
||
| return output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This change seems not related to hpu, did you met any block issues?
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.
@jiqing-feng Please check description in this PR #1623 . Issue which gets fixed with this change is described there.
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 see. Thanks!