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
fairscale
Commits
e4b2ffd4
Commit
e4b2ffd4
authored
Jul 17, 2020
by
Jun Ru Anderson
Committed by
Mandeep Singh Baines
Jul 31, 2020
Browse files
[test] switch benchmark to use Adam rather than SGD
parent
74181b08
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
benchmarks/transformer.py
benchmarks/transformer.py
+9
-8
No files found.
benchmarks/transformer.py
View file @
e4b2ffd4
...
...
@@ -5,6 +5,7 @@ import time
import
torch
import
torch.nn
as
nn
from
torch.optim.adam
import
Adam
import
torchtext
from
torchtext.data.utils
import
get_tokenizer
...
...
@@ -123,8 +124,8 @@ def make_model(device, ntokens):
model
=
TransformerLMSequntial
(
ntokens
,
ninp
,
nhead
,
nhid
,
dropout
,
initrange
).
to
(
device
)
criterion
=
nn
.
CrossEntropyLoss
()
lr
=
1
.0
# learning rate
optimizer
=
torch
.
optim
.
SGD
(
model
.
parameters
(),
lr
=
lr
)
lr
=
0
.0
1
# learning rate
optimizer
=
Adam
(
model
.
parameters
(),
lr
=
lr
)
return
model
,
criterion
,
optimizer
...
...
@@ -212,7 +213,7 @@ def benchmark_language_model(train_data, val_data, test_data, model, criterion,
if
len
(
model
.
balance
)
==
4
:
# Assert that words per second is within 3 standard deviations of the average
# of five golden runs
assert
wps
>
19
779.5
-
(
3
*
167.81
)
assert
wps
>
19
276.1
-
(
3
*
88
)
print
(
"Peak allocated bytes on cuda:0: {:1d}"
.
format
(
torch
.
cuda
.
memory_stats
(
0
)[
"allocated_bytes.all.peak"
]))
print
(
"Peak allocated bytes on cuda:1: {:1d}"
.
format
(
torch
.
cuda
.
memory_stats
(
1
)[
"allocated_bytes.all.peak"
]))
...
...
@@ -220,11 +221,11 @@ def benchmark_language_model(train_data, val_data, test_data, model, criterion,
print
(
"Peak allocated bytes on cuda:3: {:1d}"
.
format
(
torch
.
cuda
.
memory_stats
(
3
)[
"allocated_bytes.all.peak"
]))
# Assert that memory usage on each GPU is within 10% of golden run
# Right-hand-side is golden run
KB * KB to bytes conversion
* 110%
assert
torch
.
cuda
.
memory_stats
(
0
)[
"allocated_bytes.all.peak"
]
<
3
46094
*
1024
*
1.1
assert
torch
.
cuda
.
memory_stats
(
1
)[
"allocated_bytes.all.peak"
]
<
12
51
*
1024
*
1.1
assert
torch
.
cuda
.
memory_stats
(
2
)[
"allocated_bytes.all.peak"
]
<
2
595
*
102
4
*
1.1
assert
torch
.
cuda
.
memory_stats
(
3
)[
"allocated_bytes.all.peak"
]
<
1
74784
*
1024
*
1.1
# Right-hand-side is golden run
bytes
* 110%
assert
torch
.
cuda
.
memory_stats
(
0
)[
"allocated_bytes.all.peak"
]
<
3
65915648
*
1.1
assert
torch
.
cuda
.
memory_stats
(
1
)[
"allocated_bytes.all.peak"
]
<
12
8
1024
*
1.1
assert
torch
.
cuda
.
memory_stats
(
2
)[
"allocated_bytes.all.peak"
]
<
2
78886
4
*
1.1
assert
torch
.
cuda
.
memory_stats
(
3
)[
"allocated_bytes.all.peak"
]
<
1
90724608
*
1.1
print
(
"No regression detected"
)
...
...
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