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

evaluation can receive metric values from anywhere #877

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

AntonioCarta
Copy link
Collaborator

This PR adds a small feature to the EvaluationPlugin that allows to compute metrics outside MetricPlugins.
For example, let's assume that a strategy computes a loss function with many regularization terms, and we want to log each one separately. This is possible with the new API:

    # This is a strategy method, not a metric plugin.
    def criterion(self):
        if self.is_training:
            pred = self.teacher_targets.detach().max(dim=1)[1]
            loss_activation = -self.teacher_features.abs().mean()
            loss_ce = F.cross_entropy(self.teacher_targets, pred)
            loss = loss_ce * self.oh + loss_activation * self.a
            
           # Metric is logged here.
            xp = self.clock.train_iterations
            mval = MetricValue(origin=self, name='loss_ce', value=loss_ce.item(), x_plot=xp)
            self.evaluator.publish_metric_value(mval)
            mval = MetricValue(origin=self, name='loss_a', value=loss_activation.item(), x_plot=xp)
            self.evaluator.publish_metric_value(mval)

Doing the same with metric plugins is possible but much more verbose.

@AndreaCossu AndreaCossu merged commit 128491b into ContinualAI:master Jan 11, 2022
@AntonioCarta AntonioCarta deleted the oob_metrics branch January 19, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants