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
gaoqiong
flash-attention
Commits
713bd3aa
Commit
713bd3aa
authored
Dec 16, 2023
by
Tri Dao
Browse files
[CrossEntropy] Test longer sequences
parent
08124c8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
4 deletions
+5
-4
tests/losses/test_cross_entropy.py
tests/losses/test_cross_entropy.py
+5
-4
No files found.
tests/losses/test_cross_entropy.py
View file @
713bd3aa
...
...
@@ -30,8 +30,8 @@ def test_cross_entropy_loss(
rtol
,
atol
=
(
1e-5
,
1e-6
)
if
dtype
==
torch
.
float32
else
(
1e-3
,
1e-4
)
# set seed
torch
.
random
.
manual_seed
(
0
)
batch_size
=
8
seqlen
=
128
batch_size
=
1
if
dtype
==
torch
.
float32
else
4
# Otherwise OOM
seqlen
=
4096
if
lse_square_scale
==
0.0
and
logit_scale
==
1.0
else
1024
# Otherwise OOM
x_pt
=
torch
.
randn
(
batch_size
*
seqlen
,
vocab_size
,
device
=
device
,
dtype
=
dtype
,
requires_grad
=
True
)
...
...
@@ -47,9 +47,10 @@ def test_cross_entropy_loss(
inplace_backward
=
inplace_backward
,
)
out
=
model
(
x
,
y
)
out_pt
=
model_pt
(
x_pt
.
float
()
*
logit_scale
,
y
)
x_pt_scaled
=
(
x_pt
.
float
()
*
logit_scale
)
if
logit_scale
!=
1.0
else
x_pt
.
float
()
out_pt
=
model_pt
(
x_pt_scaled
,
y
)
if
lse_square_scale
>
0.0
:
lse_pt
=
torch
.
logsumexp
(
x_pt
.
float
()
*
logit
_scale
,
dim
=-
1
)
lse_pt
=
torch
.
logsumexp
(
x_pt_scale
d
,
dim
=-
1
)
out_pt
+=
lse_square_scale
*
(
lse_pt
[
y
!=
-
100
]
**
2
).
mean
()
assert
torch
.
allclose
(
out
,
out_pt
,
rtol
=
1e-5
,
atol
=
1e-6
)
...
...
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