Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
bitsandbytes
Commits
1dbe6021
Commit
1dbe6021
authored
Aug 01, 2025
by
ved1beta
Browse files
Fix Params4bit tensor subclass handling
parent
e54dc125
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
bitsandbytes/nn/modules.py
bitsandbytes/nn/modules.py
+40
-0
No files found.
bitsandbytes/nn/modules.py
View file @
1dbe6021
...
@@ -356,6 +356,46 @@ class Params4bit(torch.nn.Parameter):
...
@@ -356,6 +356,46 @@ class Params4bit(torch.nn.Parameter):
return
new_param
return
new_param
@
classmethod
def
__torch_function__
(
cls
,
func
,
types
,
args
=
(),
kwargs
=
None
):
if
kwargs
is
None
:
kwargs
=
{}
if
func
in
[
torch
.
chunk
,
torch
.
split
]:
tensor
=
args
[
0
]
result
=
super
().
__torch_function__
(
func
,
types
,
args
,
kwargs
)
if
isinstance
(
result
,
tuple
):
return
tuple
(
cls
(
data
=
chunk
,
requires_grad
=
tensor
.
requires_grad
,
quant_state
=
tensor
.
quant_state
,
blocksize
=
tensor
.
blocksize
,
compress_statistics
=
tensor
.
compress_statistics
,
quant_type
=
tensor
.
quant_type
,
quant_storage
=
tensor
.
quant_storage
,
module
=
tensor
.
module
,
bnb_quantized
=
tensor
.
bnb_quantized
,
)
for
chunk
in
result
)
else
:
return
cls
(
data
=
result
,
requires_grad
=
tensor
.
requires_grad
,
quant_state
=
tensor
.
quant_state
,
blocksize
=
tensor
.
blocksize
,
compress_statistics
=
tensor
.
compress_statistics
,
quant_type
=
tensor
.
quant_type
,
quant_storage
=
tensor
.
quant_storage
,
module
=
tensor
.
module
,
bnb_quantized
=
tensor
.
bnb_quantized
,
)
return
super
().
__torch_function__
(
func
,
types
,
args
,
kwargs
)
def
fix_4bit_weight_quant_state_from_module
(
module
:
Union
[
"Embedding4bit"
,
"Linear4bit"
]):
def
fix_4bit_weight_quant_state_from_module
(
module
:
Union
[
"Embedding4bit"
,
"Linear4bit"
]):
if
getattr
(
module
.
weight
,
"quant_state"
,
None
)
is
not
None
:
if
getattr
(
module
.
weight
,
"quant_state"
,
None
)
is
not
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment