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
461e8cac
"docs/vscode:/vscode.git/clone" did not exist on "88735249da94266a433368d2b899e87dc33446c9"
Unverified
Commit
461e8cac
authored
Feb 22, 2021
by
Sylvain Gugger
Committed by
GitHub
Feb 22, 2021
Browse files
Fix evaluation with label smoothing in Trainer (#10338)
parent
622a8c59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
src/transformers/trainer.py
src/transformers/trainer.py
+8
-7
No files found.
src/transformers/trainer.py
View file @
461e8cac
...
@@ -1888,6 +1888,14 @@ class Trainer:
...
@@ -1888,6 +1888,14 @@ class Trainer:
else
:
else
:
ignore_keys
=
[]
ignore_keys
=
[]
# labels may be popped when computing the loss (label smoothing for instance) so we grab them first.
if
has_labels
:
labels
=
nested_detach
(
tuple
(
inputs
.
get
(
name
)
for
name
in
self
.
label_names
))
if
len
(
labels
)
==
1
:
labels
=
labels
[
0
]
else
:
labels
=
None
with
torch
.
no_grad
():
with
torch
.
no_grad
():
if
has_labels
:
if
has_labels
:
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
loss
,
outputs
=
self
.
compute_loss
(
model
,
inputs
,
return_outputs
=
True
)
...
@@ -1918,13 +1926,6 @@ class Trainer:
...
@@ -1918,13 +1926,6 @@ class Trainer:
if
len
(
logits
)
==
1
:
if
len
(
logits
)
==
1
:
logits
=
logits
[
0
]
logits
=
logits
[
0
]
if
has_labels
:
labels
=
nested_detach
(
tuple
(
inputs
.
get
(
name
)
for
name
in
self
.
label_names
))
if
len
(
labels
)
==
1
:
labels
=
labels
[
0
]
else
:
labels
=
None
return
(
loss
,
logits
,
labels
)
return
(
loss
,
logits
,
labels
)
def
floating_point_ops
(
self
,
inputs
:
Dict
[
str
,
Union
[
torch
.
Tensor
,
Any
]]):
def
floating_point_ops
(
self
,
inputs
:
Dict
[
str
,
Union
[
torch
.
Tensor
,
Any
]]):
...
...
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