Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract metric_key_prefix during NotebookProgressCallback.on_evaluate #11347

Merged
merged 7 commits into from
Apr 21, 2021
14 changes: 9 additions & 5 deletions src/transformers/utils/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

import collections
import re
import time
from typing import Optional

Expand Down Expand Up @@ -308,7 +309,7 @@ def on_log(self, args, state, control, logs=None, **kwargs):

def on_evaluate(self, args, state, control, metrics=None, **kwargs):
if self.training_tracker is not None:
values = {"Training Loss": "No log"}
values = {"Training Loss": "No log", "Validation Loss": "No log"}
for log in reversed(state.log_history):
if "loss" in log:
values["Training Loss"] = log["loss"]
Expand All @@ -318,13 +319,16 @@ def on_evaluate(self, args, state, control, metrics=None, **kwargs):
values["Epoch"] = int(state.epoch)
else:
values["Step"] = state.global_step
values["Validation Loss"] = metrics["eval_loss"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line seemed to be redundant since we later loop over metrics.items(), so i removed it

metric_key_prefix = "eval"
for k in metrics:
if k.endswith("_loss"):
metric_key_prefix = re.sub(r"\_loss$", "", k)
_ = metrics.pop("total_flos", None)
_ = metrics.pop("epoch", None)
_ = metrics.pop("eval_runtime", None)
_ = metrics.pop("eval_samples_per_second", None)
_ = metrics.pop(f"{metric_key_prefix}_runtime", None)
_ = metrics.pop(f"{metric_key_prefix}_samples_per_second", None)
for k, v in metrics.items():
if k == "eval_loss":
if k == f"{metric_key_prefix}_loss":
values["Validation Loss"] = v
else:
splits = k.split("_")
Expand Down