You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support incomplete specification of MetricCollection compute_groups + inherit compute groups from child metric collections
Motivation
Currently, new instances of the MetricCollection class allow users to manually specify the compute_groups used to simplify update steps. However, if a user doesn't explicitly specify any metric in the compute groups lists, it simply won't be updated. It seems like the expected behavior would be for those additional metrics to simply be updated normally (or possibly automatically inherited by some of the manually specified groups).
Moreover, if a uses the supported behavior of a single level "recursion" of MetricCollection's (i.e. creating a MetricCollection of MetricCollection's), the compute_groups arguments of the child collections are simply ignored.
Pitch
It might be desirable to have any metrics which aren't included in the list of compute_groups to be automatically detected and put into their own single-item compute groups. Possibly we could also attempt to merge them into existing groups, but this might be overly complex and unnecessary.
The specified compute groups from child collections should be inherited by the parent (with the prefix's/postfix's updated appropriately). Admittedly, this introduces some complexities which may be more simply handled by just automatically creating the groups (as is currently done). If so, it should at least be documented that the child compute_groups arguments will be ignored.
Alternatives
As noted above, if the current behavior is intended, it should at least be documented what will happen in these "corner" cases.
Additional context
The text was updated successfully, but these errors were encountered:
Hi @alexrgilbert, thanks for reporting this issue.
I created PR #2979 which will fix the first issue you mention, namely that if a metric is not in the list of compute groups it will be automatically added still. For you second issue, I really tried to find a solution for that, but was unable for now to get it working because there are so many parts moving inside the metric collection. For now, i post my part-solution in this issue such that I can hopefully fix it in the future and in addition added this limitation to the description of the metric collection.
# add inside the _init_compute_groups() method# if nested metric collections, we need to respect the compute groups of child collectionsifself._groups:
flattened_dict= {}
counter=0forouter_dictinself._groups.values():
ifisinstance(outer_dict, dict):
forvaluesinouter_dict.values():
flattened_dict[counter] =valuescounter+=1# Increment the unique keyelse:
flattened_dict[counter] =outer_dictcounter+=1self._groups=flattened_dictfork, vinself.items(keep_base=False, copy_state=False):
ifhasattr(v, "_from_collection"):
ifhasattr(v, "_collection_name"):
kmatching=k.lstrip(v._collection_name)
forgroup_key, valuesinself._groups.items():
self._groups[group_key] = [kifval==kmatchingelsevalforvalinvalues]
else:
forgroup_key, valuesinself._groups.items():
self._groups[group_key] = [kifval==kelsevalforvalinvalues]
# add metrics not already added in group by child collectionsexisting_metrics= {metricforvaluesinself._groups.values() formetricinvalues}
new_metrics= [kforkinself.keys(keep_base=True) ifstr(k) notinexisting_metrics]
fori, metricinenumerate(new_metrics, start=len(self._groups)):
self._groups[i] = [str(metric)]
``
🚀 Feature
Support incomplete specification of MetricCollection
compute_groups
+ inherit compute groups from child metric collectionsMotivation
Currently, new instances of the
MetricCollection
class allow users to manually specify thecompute_groups
used to simplifyupdate
steps. However, if a user doesn't explicitly specify any metric in the compute groups lists, it simply won't be updated. It seems like the expected behavior would be for those additional metrics to simply be updated normally (or possibly automatically inherited by some of the manually specified groups).Moreover, if a uses the supported behavior of a single level "recursion" of MetricCollection's (i.e. creating a MetricCollection of MetricCollection's), the
compute_groups
arguments of the child collections are simply ignored.Pitch
It might be desirable to have any metrics which aren't included in the list of
compute_groups
to be automatically detected and put into their own single-item compute groups. Possibly we could also attempt to merge them into existing groups, but this might be overly complex and unnecessary.The specified compute groups from child collections should be inherited by the parent (with the prefix's/postfix's updated appropriately). Admittedly, this introduces some complexities which may be more simply handled by just automatically creating the groups (as is currently done). If so, it should at least be documented that the child
compute_groups
arguments will be ignored.Alternatives
As noted above, if the current behavior is intended, it should at least be documented what will happen in these "corner" cases.
Additional context
The text was updated successfully, but these errors were encountered: