question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support custom events for metrics update

See original GitHub issue

Currently for ignite metrics, update function is called per iteration. In scenarios like multitasking, there can be metrics for different tasks, and each iteration might only have outputs for a subset of tasks. In this situation, only the metrics associated with those tasks having outputs can/should be updated.

To make it work, I need to overwrite the attach function like this:

class CustomRnningAverage(RunningAverage):
    def attach(self, engine, name, custom_event=None):
        if custom_event is None:
            super().attach(engine, name)
        else:
            if self.epoch_bound:
                # restart average every epoch
                engine.add_event_handler(Events.EPOCH_STARTED, self.started)
            # compute metric
            engine.add_event_handler(custom_event, self.iteration_completed)
            # apply running average
            engine.add_event_handler(custom_event, self.completed, name)

This is doable, but would be nice to have it by default in ignite. Also, this manual overwrite doesn’t work with DDP. The cause is related to _internal_attach in metrics_lambda.py.

I would like to propose

  1. Have update every iteration by default
  2. Support overwrite when to update by accepting custom events
  3. Make it work with DDP

Multitasking is one case where this can be very helpful. But I am sure there will be other use cases.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sdesroziscommented, Apr 26, 2020

Yes, MetricUsage should be the way to configure your metric.

Epoch-wise accuracy :

engine = ...
acc = Accuracy()
acc.attach(engine, "acc", usage="epoch_wise")  # default

It means reset of metric at Event.EPOCH_STARTED, update at Event.ITERATION_COMPLETED and complete at Event.EPOCH_COMPLETED

Batch-wise accuracy :

engine = ...
acc = Accuracy()
acc.attach(engine, "acc", usage="batch_wise")

It means reset of metric at Event.ITERATION_STARTED, update at Event.ITERATION_COMPLETED and complete at Event.ITERATION_COMPLETED

You can define a custom usage

my_usage = YourCustomUsage()
acc = Accuracy()
acc.attach(engine, "acc", usage= my_usage)

Here, YourCustomUsage must inherit from MetricUsage and you customize when reset, update and complete of metric occur.

HTH

1reaction
snie2012commented, Apr 26, 2020

@sdesrozis Would you mind showing an example of using the changes you made in sdesrozis:issue_874 to update on custom events? My understanding is that I can create a customized MetricUsage class to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application Insights API for custom events and metrics
Use the Application Insights core telemetry API to send custom events and metrics and your own versions of standard telemetry. This API is...
Read more >
Introduction to custom events and attributes
Two popular solutions for reporting custom data are reporting custom events and custom attributes. There are several ways to accomplish this, depending on...
Read more >
Using Custom Metrics and Events
Custom events and metrics will appear in the Campaign UI. In the left navigation, click All Recent Activity. If any custom events or...
Read more >
[GA4] Custom events - Analytics Help - Google Support
Before you create a custom event, review the list of automatically collected, enhanced measurement, and recommended events. These types of events automatically ...
Read more >
Custom events | Adobe Analytics - Experience League
This help page describes how custom events work as a metric. For information on how custom events work as an implementation variable, see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found