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
95b6bef6
"git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "a46050d0f54b7c90aadcbde40da688625c1c1455"
Unverified
Commit
95b6bef6
authored
May 16, 2022
by
MichelBartels
Committed by
GitHub
May 16, 2022
Browse files
Align logits and labels in OPT (#17237)
parent
a5d18396
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
2 deletions
+5
-2
src/transformers/models/opt/modeling_opt.py
src/transformers/models/opt/modeling_opt.py
+5
-2
No files found.
src/transformers/models/opt/modeling_opt.py
View file @
95b6bef6
...
@@ -951,9 +951,12 @@ class OPTForCausalLM(OPTPreTrainedModel):
...
@@ -951,9 +951,12 @@ class OPTForCausalLM(OPTPreTrainedModel):
loss
=
None
loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
# Shift so that tokens < n predict n
shift_logits
=
logits
[...,
:
-
1
,
:].
contiguous
()
shift_labels
=
labels
[...,
1
:].
contiguous
()
# Flatten the tokens
loss_fct
=
CrossEntropyLoss
()
loss_fct
=
CrossEntropyLoss
()
loss
=
loss_fct
(
shift_logits
.
view
(
-
1
,
self
.
config
.
vocab_size
),
shift_labels
.
view
(
-
1
))
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
vocab_size
),
labels
.
view
(
-
1
))
if
not
return_dict
:
if
not
return_dict
:
output
=
(
logits
,)
+
outputs
[
1
:]
output
=
(
logits
,)
+
outputs
[
1
:]
...
...
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