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
chenpangpang
transformers
Commits
bf14ef75
Unverified
Commit
bf14ef75
authored
May 18, 2020
by
Julien Chaumond
Committed by
GitHub
May 18, 2020
Browse files
[Trainer] move model to device before setting optimizer (#4450)
parent
5e7fe8b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
3 deletions
+1
-3
src/transformers/trainer.py
src/transformers/trainer.py
+1
-3
No files found.
src/transformers/trainer.py
View file @
bf14ef75
...
...
@@ -188,7 +188,7 @@ class Trainer:
prediction_loss_only:
(Optional) in evaluation and prediction, only return the loss
"""
self
.
model
=
model
self
.
model
=
model
.
to
(
args
.
device
)
self
.
args
=
args
if
data_collator
is
not
None
:
self
.
data_collator
=
data_collator
...
...
@@ -393,7 +393,6 @@ class Trainer:
scheduler
.
load_state_dict
(
torch
.
load
(
os
.
path
.
join
(
model_path
,
"scheduler.pt"
)))
model
=
self
.
model
model
.
to
(
self
.
args
.
device
)
if
self
.
args
.
fp16
:
if
not
is_apex_available
():
raise
ImportError
(
"Please install apex from https://www.github.com/nvidia/apex to use fp16 training."
)
...
...
@@ -726,7 +725,6 @@ class Trainer:
prediction_loss_only
=
prediction_loss_only
if
prediction_loss_only
is
not
None
else
self
.
prediction_loss_only
model
=
self
.
model
model
.
to
(
self
.
args
.
device
)
# multi-gpu eval
if
self
.
args
.
n_gpu
>
1
:
model
=
torch
.
nn
.
DataParallel
(
model
)
...
...
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