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
14cc50d0
"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "df7cd9e4e40a8c89f7570fd6cb3dbd30a803123a"
Commit
14cc50d0
authored
Dec 01, 2021
by
Stas Bekman
Browse files
fix autocast for older pytorch
parent
4c0dd199
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
src/transformers/trainer.py
src/transformers/trainer.py
+18
-6
No files found.
src/transformers/trainer.py
View file @
14cc50d0
...
@@ -1857,8 +1857,12 @@ class Trainer:
...
@@ -1857,8 +1857,12 @@ class Trainer:
return
loss_mb
.
reduce_mean
().
detach
().
to
(
self
.
args
.
device
)
return
loss_mb
.
reduce_mean
().
detach
().
to
(
self
.
args
.
device
)
if
self
.
use_amp
:
if
self
.
use_amp
:
with
autocast
(
dtype
=
self
.
amp_dtype
):
if
version
.
parse
(
torch
.
__version__
)
>=
version
.
parse
(
"1.10"
):
loss
=
self
.
compute_loss
(
model
,
inputs
)
with
autocast
(
dtype
=
self
.
amp_dtype
):
loss
=
self
.
compute_loss
(
model
,
inputs
)
else
:
with
autocast
():
loss
=
self
.
compute_loss
(
model
,
inputs
)
else
:
else
:
loss
=
self
.
compute_loss
(
model
,
inputs
)
loss
=
self
.
compute_loss
(
model
,
inputs
)
...
@@ -2501,8 +2505,12 @@ class Trainer:
...
@@ -2501,8 +2505,12 @@ class Trainer:
else
:
else
:
if
has_labels
:
if
has_labels
:
if
self
.
use_amp
:
if
self
.
use_amp
:
with
autocast
(
dtype
=
self
.
amp_dtype
):
if
version
.
parse
(
torch
.
__version__
)
>=
version
.
parse
(
"1.10"
):
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
with
autocast
(
dtype
=
self
.
amp_dtype
):
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
else
:
with
autocast
():
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
else
:
else
:
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
loss
=
loss
.
mean
().
detach
()
loss
=
loss
.
mean
().
detach
()
...
@@ -2514,8 +2522,12 @@ class Trainer:
...
@@ -2514,8 +2522,12 @@ class Trainer:
else
:
else
:
loss
=
None
loss
=
None
if
self
.
use_amp
:
if
self
.
use_amp
:
with
autocast
(
dtype
=
self
.
amp_dtype
):
if
version
.
parse
(
torch
.
__version__
)
>=
version
.
parse
(
"1.10"
):
outputs
=
model
(
**
inputs
)
with
autocast
(
dtype
=
self
.
amp_dtype
):
outputs
=
model
(
**
inputs
)
else
:
with
autocast
():
outputs
=
model
(
**
inputs
)
else
:
else
:
outputs
=
model
(
**
inputs
)
outputs
=
model
(
**
inputs
)
if
isinstance
(
outputs
,
dict
):
if
isinstance
(
outputs
,
dict
):
...
...
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