Repository navigation
[gguf] load BF16 tensors as plain bfloat16 tensors #15406
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,6 @@ | |
| else: | ||
| ops = None | ||
|
|
||
| UNQUANTIZED_TYPES = {gguf.GGMLQuantizationType.F32, gguf.GGMLQuantizationType.F16, gguf.GGMLQuantizationType.BF16} | ||
| STANDARD_QUANT_TYPES = { | ||
| gguf.GGMLQuantizationType.Q4_0, | ||
| gguf.GGMLQuantizationType.Q4_1, | ||
|
|
@@ -87,11 +86,6 @@ | |
|
|
||
|
|
||
| def _fused_mul_mat_gguf(x: torch.Tensor, qweight: torch.Tensor, qweight_type: int) -> torch.Tensor: | ||
| # there is no need to call any kernel for fp16/bf16 | ||
| if qweight_type in UNQUANTIZED_TYPES: | ||
| weight = dequantize_gguf_tensor(qweight) | ||
| return x @ weight.to(x.dtype).T | ||
|
|
||
| # TODO(Isotr0py): GGUF's MMQ and MMVQ implementation are designed for | ||
| # contiguous batching and inefficient with diffusers' batching, | ||
| # so we disabled it now. | ||
|
|
@@ -440,10 +434,6 @@ def dequantize_blocks_Q2_K(blocks, block_size, type_size, dtype=None): | |
| return qs.reshape((n_blocks, -1)) | ||
|
|
||
|
|
||
| def dequantize_blocks_BF16(blocks, block_size, type_size, dtype=None): | ||
| return (blocks.view(torch.int16).to(torch.int32) << 16).view(torch.float32) | ||
|
Comment on lines
-443
to
-444
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this removal not be version-guarded?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaict this is basically an internal helper that was used exclusively in dequantize_functions that, frankly, I don't know why you'd want to reach into diffusers.quantizers.gguf.utils to import. We can leave/deprecate it if we think someone might be depending on it, but I don't think it's a documented interface or anything. |
||
|
|
||
|
|
||
| # this part from calcuis (gguf.org) | ||
| # more info: https://github.com/calcuis/gguf-connector/blob/main/src/gguf_connector/quant2c.py | ||
|
|
||
|
|
@@ -502,7 +492,6 @@ def dequantize_blocks_IQ4_XS(blocks, block_size, type_size, dtype=None): | |
| dequantize_functions = { | ||
| gguf.GGMLQuantizationType.IQ4_NL: dequantize_blocks_IQ4_NL, | ||
| gguf.GGMLQuantizationType.IQ4_XS: dequantize_blocks_IQ4_XS, | ||
| gguf.GGMLQuantizationType.BF16: dequantize_blocks_BF16, | ||
| gguf.GGMLQuantizationType.Q8_0: dequantize_blocks_Q8_0, | ||
| gguf.GGMLQuantizationType.Q5_1: dequantize_blocks_Q5_1, | ||
| gguf.GGMLQuantizationType.Q5_0: dequantize_blocks_Q5_0, | ||
|
|
||
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.
Is this sufficiently available from the minimum gguf version we require in diffusers?
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.
Not sure what there is not to be available in a removal, but I checked the behavior against gguf 0.10.0, the bf16 treatment seems to be the same and the test reproduces.