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
27d916b3
Unverified
Commit
27d916b3
authored
May 07, 2025
by
Egor
Committed by
GitHub
May 07, 2025
Browse files
Moved int8_mm_dequant to default backend (#1626)
parent
8b858e4e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
24 deletions
+23
-24
bitsandbytes/backends/cpu/ops.py
bitsandbytes/backends/cpu/ops.py
+0
-24
bitsandbytes/backends/default/ops.py
bitsandbytes/backends/default/ops.py
+23
-0
No files found.
bitsandbytes/backends/cpu/ops.py
View file @
27d916b3
from
collections.abc
import
Sequence
import
ctypes
as
ct
from
typing
import
Optional
import
torch
...
...
@@ -24,29 +23,6 @@ if torch.__version__ >= (2, 6):
).
reshape
(
*
A
.
shape
[:
-
1
],
B
.
shape
[
0
])
@
register_kernel
(
"bitsandbytes::int8_mm_dequant"
,
"cpu"
)
def
_
(
A
:
torch
.
Tensor
,
row_stats
:
torch
.
Tensor
,
col_stats
:
torch
.
Tensor
,
dtype
:
Optional
[
torch
.
dtype
]
=
None
,
bias
:
Optional
[
torch
.
Tensor
]
=
None
,
)
->
torch
.
Tensor
:
torch
.
_check
(
A
.
dtype
==
torch
.
int32
,
lambda
:
f
"A must be int32, got
{
A
.
dtype
}
"
)
torch
.
_check
(
row_stats
.
dtype
==
torch
.
float32
,
lambda
:
f
"row_stats must be float32, got
{
row_stats
.
dtype
}
"
)
torch
.
_check
(
col_stats
.
dtype
==
torch
.
float32
,
lambda
:
f
"col_stats must be float32, got
{
col_stats
.
dtype
}
"
)
A_calc
=
A
.
view
(
-
1
,
A
.
shape
[
-
1
])
row_stats
=
row_stats
.
reshape
(
-
1
).
unsqueeze
(
-
1
)
col_stats
=
col_stats
.
reshape
(
-
1
).
unsqueeze
(
0
)
out
=
A_calc
*
(
row_stats
*
col_stats
)
*
6.200124e-05
if
bias
is
not
None
:
out
+=
bias
return
out
.
to
(
dtype
or
torch
.
float16
)
@
register_kernel
(
"bitsandbytes::quantize_blockwise"
,
"cpu"
)
def
_
(
A
:
torch
.
Tensor
,
code
:
torch
.
Tensor
,
blocksize
:
int
)
->
tuple
[
torch
.
Tensor
,
torch
.
Tensor
]:
torch
.
_check_is_size
(
blocksize
)
...
...
bitsandbytes/backends/default/ops.py
View file @
27d916b3
...
...
@@ -6,6 +6,29 @@ import torch
from
..._ops
import
register_kernel
@
register_kernel
(
"bitsandbytes::int8_mm_dequant"
,
"default"
)
def
_
(
A
:
torch
.
Tensor
,
row_stats
:
torch
.
Tensor
,
col_stats
:
torch
.
Tensor
,
dtype
:
Optional
[
torch
.
dtype
]
=
None
,
bias
:
Optional
[
torch
.
Tensor
]
=
None
,
)
->
torch
.
Tensor
:
torch
.
_check
(
A
.
dtype
==
torch
.
int32
,
lambda
:
f
"A must be int32, got
{
A
.
dtype
}
"
)
torch
.
_check
(
row_stats
.
dtype
==
torch
.
float32
,
lambda
:
f
"row_stats must be float32, got
{
row_stats
.
dtype
}
"
)
torch
.
_check
(
col_stats
.
dtype
==
torch
.
float32
,
lambda
:
f
"col_stats must be float32, got
{
col_stats
.
dtype
}
"
)
A_calc
=
A
.
view
(
-
1
,
A
.
shape
[
-
1
])
row_stats
=
row_stats
.
reshape
(
-
1
).
unsqueeze
(
-
1
)
col_stats
=
col_stats
.
reshape
(
-
1
).
unsqueeze
(
0
)
out
=
A_calc
*
(
row_stats
*
col_stats
)
*
6.200124e-05
if
bias
is
not
None
:
out
+=
bias
return
out
.
to
(
dtype
or
torch
.
float16
)
@
register_kernel
(
"bitsandbytes::int8_mixed_scaled_mm"
,
"default"
)
def
_
(
A
:
torch
.
Tensor
,
...
...
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