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
lm-evaluation-harness
Commits
e87c0838
Commit
e87c0838
authored
Apr 15, 2023
by
Benjamin Fattori
Browse files
compute multiple forward passes in autobatcher to improve robustness to OOMs
parent
d86de51d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
7 deletions
+5
-7
lm_eval/base.py
lm_eval/base.py
+5
-7
No files found.
lm_eval/base.py
View file @
e87c0838
...
@@ -197,14 +197,13 @@ class BaseLM(LM):
...
@@ -197,14 +197,13 @@ class BaseLM(LM):
@
find_executable_batch_size
(
starting_batch_size
=
512
)
# if OOM, then halves batch_size and tries again
@
find_executable_batch_size
(
starting_batch_size
=
512
)
# if OOM, then halves batch_size and tries again
def
forward_batch
(
batch_size
):
def
forward_batch
(
batch_size
):
test_batch
=
torch
.
ones
((
batch_size
,
self
.
max_length
),
device
=
self
.
device
).
long
()
test_batch
=
torch
.
ones
((
batch_size
,
self
.
max_length
),
device
=
self
.
device
).
long
()
out
=
F
.
log_softmax
(
self
.
_model_call
(
test_batch
),
dim
=
-
1
)
for
_
in
range
(
5
):
out
=
F
.
log_softmax
(
self
.
_model_call
(
test_batch
),
dim
=
-
1
).
cpu
()
return
batch_size
return
batch_size
batch_size
=
forward_batch
()
batch_size
=
forward_batch
()
print
(
f
"Determined Largest batch size:
{
batch_size
}
"
)
print
(
f
"Determined Largest batch size:
{
batch_size
}
"
)
adaptive_batch_size
=
batch_size
adaptive_batch_size
=
batch_size
torch
.
cuda
.
empty_cache
()
gc
.
collect
()
loglikelihoods
=
[]
loglikelihoods
=
[]
for
(
string
,)
in
tqdm
(
requests
):
for
(
string
,)
in
tqdm
(
requests
):
...
@@ -265,15 +264,14 @@ class BaseLM(LM):
...
@@ -265,15 +264,14 @@ class BaseLM(LM):
@
find_executable_batch_size
(
starting_batch_size
=
512
)
# if OOM, then halves batch_size and tries again
@
find_executable_batch_size
(
starting_batch_size
=
512
)
# if OOM, then halves batch_size and tries again
def
forward_batch
(
batch_size
):
def
forward_batch
(
batch_size
):
test_batch
=
torch
.
ones
((
batch_size
,
max_context
),
device
=
self
.
device
).
long
()
test_batch
=
torch
.
ones
((
batch_size
,
max_context
),
device
=
self
.
device
).
long
()
out
=
F
.
log_softmax
(
self
.
_model_call
(
test_batch
),
dim
=
-
1
)
for
_
in
range
(
5
):
out
=
F
.
log_softmax
(
self
.
_model_call
(
test_batch
),
dim
=
-
1
).
cpu
()
return
batch_size
return
batch_size
batch_size
=
forward_batch
()
batch_size
=
forward_batch
()
print
(
f
"Determined largest batch size:
{
batch_size
}
"
)
print
(
f
"Determined largest batch size:
{
batch_size
}
"
)
adaptive_batch_size
=
batch_size
adaptive_batch_size
=
batch_size
torch
.
cuda
.
empty_cache
()
gc
.
collect
()
else
:
else
:
adaptive_batch_size
=
override_bs
adaptive_batch_size
=
override_bs
...
...
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