"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "04ab2ca639ee6fd1002ce0a498d892245f0c9093"
Unverified Commit 566b0f1f authored by Keith Stevens's avatar Keith Stevens Committed by GitHub
Browse files

Fix progress callback deepcopy (#32070)

* Replacing ProgressCallbacks deepcopy with a shallowcopy

* Using items instead of entries

* code cleanup for copy in trainer callback

* Style fix for ProgressCallback
parent e316c521
......@@ -16,7 +16,6 @@
Callbacks to use with the Trainer class and customize the training loop.
"""
import copy
import dataclasses
import json
from dataclasses import dataclass
......@@ -617,13 +616,16 @@ class ProgressCallback(TrainerCallback):
def on_log(self, args, state, control, logs=None, **kwargs):
if state.is_world_process_zero and self.training_bar is not None:
# avoid modifying the logs object as it is shared between callbacks
logs = copy.deepcopy(logs)
_ = logs.pop("total_flos", None)
# make a shallow copy of logs so we can mutate the fields copied
# but avoid doing any value pickling.
shallow_logs = {}
for k, v in logs.items():
shallow_logs[k] = v
_ = shallow_logs.pop("total_flos", None)
# round numbers so that it looks better in console
if "epoch" in logs:
logs["epoch"] = round(logs["epoch"], 2)
self.training_bar.write(str(logs))
if "epoch" in shallow_logs:
shallow_logs["epoch"] = round(shallow_logs["epoch"], 2)
self.training_bar.write(str(shallow_logs))
def on_train_end(self, args, state, control, **kwargs):
if state.is_world_process_zero:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment