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
30d21d58
"vscode:/vscode.git/clone" did not exist on "c513ae59c32a2021aff404c6febcae1245df8069"
Commit
30d21d58
authored
Mar 31, 2023
by
Tim Dettmers
Browse files
Added triton test.
parent
a13a522c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
tests/test_triton.py
tests/test_triton.py
+44
-0
No files found.
tests/test_triton.py
0 → 100644
View file @
30d21d58
import
pytest
import
torch
from
bitsandbytes.nn.triton_based_modules
import
SwitchBackLinear
,
SwitchBackGlobalLinear
@
pytest
.
mark
.
parametrize
(
"triton_module"
,
[
SwitchBackGlobalLinear
,
SwitchBackLinear
])
def
test_switchbatch
(
triton_module
):
for
dim
in
[
83
,
17
,
128
]:
for
batch
in
[
13
,
128
,
256
]:
standard
=
torch
.
nn
.
Linear
(
dim
,
4
*
dim
).
cuda
().
half
()
switchback
=
triton_module
(
dim
,
4
*
dim
).
cuda
().
half
()
switchback
.
weight
.
data
.
copy_
(
standard
.
weight
)
switchback
.
bias
.
data
.
copy_
(
standard
.
bias
)
for
i
in
range
(
100
):
x1
=
torch
.
randn
(
batch
,
dim
).
cuda
().
half
().
requires_grad_
(
True
)
x2
=
x1
.
clone
().
detach
().
requires_grad_
(
True
)
print
(
'standard'
)
out_standard
=
standard
(
x1
)
print
(
'switchback'
)
out_sb
=
switchback
(
x1
)
(
out_standard
.
abs
().
mean
()).
backward
()
(
out_sb
.
abs
().
mean
()).
backward
()
err_sb
=
(
out_standard
-
out_sb
).
abs
().
mean
()
print
(
'OUT'
,
err_sb
)
err_sb
=
(
standard
.
bias
.
grad
-
switchback
.
bias
.
grad
).
abs
().
mean
()
print
(
'GW2'
,
err_sb
)
err_sb
=
(
standard
.
weight
.
grad
-
switchback
.
weight
.
grad
).
abs
().
mean
()
print
(
'GW1'
,
err_sb
)
#err_sb = (x1.grad - x2.grad).abs().mean()
#print('GX1', err_sb)
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