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
792af5c8
Commit
792af5c8
authored
Apr 11, 2023
by
Tim Dettmers
Browse files
Fixed noisy tests for 8-bit Lion.
parent
0b2ebcda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
tests/test_optim.py
tests/test_optim.py
+13
-4
No files found.
tests/test_optim.py
View file @
792af5c8
...
...
@@ -18,6 +18,13 @@ import bitsandbytes.functional as F
k
=
20
def
assert_most_approx_close
(
a
,
b
,
rtol
=
1e-3
,
atol
=
1e-3
,
max_error_count
=
0
):
idx
=
torch
.
isclose
(
a
,
b
,
rtol
,
atol
)
error_count
=
(
idx
==
0
).
sum
().
item
()
if
error_count
>
max_error_count
:
print
(
f
"Too many values not close: assert
{
sumval
}
<
{
count
}
"
)
torch
.
testing
.
assert_allclose
(
a
,
b
,
rtol
,
atol
)
def
get_temp_dir
():
path
=
f
"/tmp/autoswap/
{
str
(
uuid
.
uuid4
())
}
"
...
...
@@ -306,7 +313,9 @@ def test_optimizer8bit(dim1, dim2, gtype, optim_name):
bnb_optimizer
.
step
()
torch_optimizer
.
step
()
torch
.
testing
.
assert_allclose
(
p1
,
p2
.
float
(),
atol
=
patol
,
rtol
=
prtol
)
# since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 5 errors for Lion
assert_most_approx_close
(
p1
,
p2
.
float
(),
patol
,
prtol
,
max_error_count
=
5
)
dequant_states
=
[]
for
name1
,
name2
,
qmap
,
max_val
in
str2statenames
[
optim_name
]:
...
...
@@ -388,9 +397,9 @@ def test_optimizer8bit(dim1, dim2, gtype, optim_name):
==
0
)
assert
num_not_close
.
sum
().
item
()
<
20
torch
.
testing
.
assert_allclose
(
p1
,
p2
.
float
(),
atol
=
patol
,
rtol
=
prtol
)
# since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 5 errors for Lion
assert_most_approx_close
(
p1
,
p2
.
float
(),
patol
,
prtol
,
max_error_count
=
5
)
# the parameters diverge quickly. Here we keep them close
# together so we can test against the Adam error
...
...
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