From a04654d26ff485eef76cffd183d41197e37c0fba Mon Sep 17 00:00:00 2001 From: Moya Chen <72097364+moyapchen@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:24:44 -0700 Subject: [PATCH] Add ability for Metrics to add metrics from another Metrics object (#3145) * Add notion of metrics collections, which can have other Metrics of multiple metrics be added to it See https://github.com/facebookresearch/ParlAI/pull/3138 for context and use * right, having different arguments for the same function aren't a thing in python... (alas, that's what I get for mostly coding in C++ for the past few years. :P) * fixed a bug while integrating into taskmaster2 * address comments (get rid of separate class, add func to Metrics directly) * actually do the things the last comment --- parlai/core/metrics.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parlai/core/metrics.py b/parlai/core/metrics.py index ec9f9fb11aa..75d510cb849 100644 --- a/parlai/core/metrics.py +++ b/parlai/core/metrics.py @@ -642,6 +642,16 @@ def clear(self): def share(self): return {'data': self._data} + def add_metrics(self, other: "Metrics") -> None: + """ + Aggregate another Metrics objects metrics into this one. + + Note that it is assumed that the keys for metrics are disjoint between Metrics + objects. + """ + for k, v in other._data.items(): + self.add(k, v) + class TeacherMetrics(Metrics): """