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
1c801d65
Unverified
Commit
1c801d65
authored
Mar 13, 2023
by
Sylvain Gugger
Committed by
GitHub
Mar 13, 2023
Browse files
Enforce same behavior as PyTorch 2.0 for older versions (#22136)
parent
e16cbe88
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
src/transformers/trainer.py
src/transformers/trainer.py
+2
-2
No files found.
src/transformers/trainer.py
View file @
1c801d65
...
@@ -1811,7 +1811,7 @@ class Trainer:
...
@@ -1811,7 +1811,7 @@ class Trainer:
# _total_loss_scalar is updated everytime .item() has to be called on tr_loss and stores the sum of all losses
# _total_loss_scalar is updated everytime .item() has to be called on tr_loss and stores the sum of all losses
self
.
_total_loss_scalar
=
0.0
self
.
_total_loss_scalar
=
0.0
self
.
_globalstep_last_logged
=
self
.
state
.
global_step
self
.
_globalstep_last_logged
=
self
.
state
.
global_step
model
.
zero_grad
()
model
.
zero_grad
(
set_to_none
=
True
)
self
.
control
=
self
.
callback_handler
.
on_train_begin
(
args
,
self
.
state
,
self
.
control
)
self
.
control
=
self
.
callback_handler
.
on_train_begin
(
args
,
self
.
state
,
self
.
control
)
...
@@ -1967,7 +1967,7 @@ class Trainer:
...
@@ -1967,7 +1967,7 @@ class Trainer:
if
optimizer_was_run
and
not
self
.
deepspeed
:
if
optimizer_was_run
and
not
self
.
deepspeed
:
self
.
lr_scheduler
.
step
()
self
.
lr_scheduler
.
step
()
model
.
zero_grad
()
model
.
zero_grad
(
set_to_none
=
True
)
self
.
state
.
global_step
+=
1
self
.
state
.
global_step
+=
1
self
.
state
.
epoch
=
epoch
+
(
step
+
1
+
steps_skipped
)
/
steps_in_epoch
self
.
state
.
epoch
=
epoch
+
(
step
+
1
+
steps_skipped
)
/
steps_in_epoch
self
.
control
=
self
.
callback_handler
.
on_step_end
(
args
,
self
.
state
,
self
.
control
)
self
.
control
=
self
.
callback_handler
.
on_step_end
(
args
,
self
.
state
,
self
.
control
)
...
...
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