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
47a73d94
Commit
47a73d94
authored
Jul 26, 2022
by
Tim Dettmers
Browse files
Matmullt with direct outlier extraction for 8-bit inference.
parent
32fa459e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
18 deletions
+34
-18
bitsandbytes/autograd/_functions.py
bitsandbytes/autograd/_functions.py
+34
-18
No files found.
bitsandbytes/autograd/_functions.py
View file @
47a73d94
...
@@ -191,24 +191,24 @@ class MatMul8bitLt(torch.autograd.Function):
...
@@ -191,24 +191,24 @@ class MatMul8bitLt(torch.autograd.Function):
# B in in 8-bit row-major, we can transform it back to 16-bit to extract outlier dimensions
# B in in 8-bit row-major, we can transform it back to 16-bit to extract outlier dimensions
# we also need to convert it to the turing/ampere format
# we also need to convert it to the turing/ampere format
state
.
CxB
,
state
.
SB
=
F
.
transform
(
state
.
CB
,
to_order
=
formatB
)
state
.
CxB
,
state
.
SB
=
F
.
transform
(
state
.
CB
,
to_order
=
formatB
)
if
state
.
threshold
>
0.0
and
coo_tensorA
is
not
None
and
state
.
idx
is
None
and
state
.
CB
is
not
None
:
#
if state.threshold > 0.0 and coo_tensorA is not None and state.idx is None and state.CB is not None:
# generate outlier index and subB
#
# generate outlier index and subB
outlier_idx
=
torch
.
unique
(
coo_tensorA
.
colidx
).
long
()
#
outlier_idx = torch.unique(coo_tensorA.colidx).long()
state
.
outlier_pool
.
add_outliers
(
outlier_idx
,
A
.
shape
[
-
1
])
#
state.outlier_pool.add_outliers(outlier_idx, A.shape[-1])
if
state
.
use_pool
and
state
.
outlier_pool
.
model_dim
==
A
.
shape
[
-
1
]:
#
if state.use_pool and state.outlier_pool.model_dim == A.shape[-1]:
# do not use pool for 2nd FFN layer
#
# do not use pool for 2nd FFN layer
state
.
idx
=
state
.
outlier_pool
.
get_current_outlier_idx
().
to
(
A
.
device
)
#
state.idx = state.outlier_pool.get_current_outlier_idx().to(A.device)
else
:
#
else:
state
.
idx
=
outlier_idx
#
state.idx = outlier_idx
state
.
subB
=
(
state
.
CB
[:,
state
.
idx
].
float
().
t
().
contiguous
()
*
(
state
.
SCB
/
127
)).
half
()
#
state.subB = (state.CB[:, state.idx].float().t().contiguous()*(state.SCB/127)).half()
if
state
.
idx
is
not
None
:
#
if state.idx is not None:
# extract outliers
#
# extract outliers
CA
[:,
state
.
idx
]
=
0
#
CA[:, state.idx] = 0
CAt
[:,
state
.
idx
]
=
0
#
CAt[:, state.idx] = 0
subA
=
A
[:,
state
.
idx
]
#
subA = A[:, state.idx]
else
:
#
else:
subA
=
None
#
subA = None
else
:
else
:
if
not
state
.
has_fp16_weights
and
state
.
CxB
is
None
:
if
not
state
.
has_fp16_weights
and
state
.
CxB
is
None
:
state
.
CxB
,
state
.
SB
=
F
.
transform
(
state
.
CB
,
to_order
=
formatB
)
state
.
CxB
,
state
.
SB
=
F
.
transform
(
state
.
CB
,
to_order
=
formatB
)
...
@@ -229,6 +229,22 @@ class MatMul8bitLt(torch.autograd.Function):
...
@@ -229,6 +229,22 @@ class MatMul8bitLt(torch.autograd.Function):
else
:
else
:
has_grad
=
False
has_grad
=
False
if
coo_tensorA
is
not
None
and
not
state
.
has_fp16_weights
:
# extract outliers
outlier_idx
=
torch
.
unique
(
coo_tensorA
.
colidx
)
state
.
outlier_pool
.
add_outliers
(
outlier_idx
,
A
.
shape
[
-
1
])
if
state
.
use_pool
and
state
.
outlier_pool
.
model_dim
==
A
.
shape
[
-
1
]:
# do not use pool for 2nd FFN layer
state
.
idx
=
state
.
outlier_pool
.
get_current_outlier_idx
().
to
(
A
.
device
)
else
:
state
.
idx
=
outlier_idx
outliers
=
F
.
extract_outliers
(
state
.
CxB
,
state
.
SB
,
outlier_idx
).
half
()
state
.
subB
=
(
outliers
*
state
.
SCB
.
view
(
-
1
,
1
).
half
()
/
127.0
).
t
().
contiguous
()
CA
[:,
state
.
idx
.
long
()]
=
0
CAt
[:,
state
.
idx
.
long
()]
=
0
subA
=
A
[:,
state
.
idx
.
long
()]
shapeB
=
state
.
SB
[
0
]
shapeB
=
state
.
SB
[
0
]
if
len
(
input_shape
)
==
3
:
if
len
(
input_shape
)
==
3
:
...
...
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