Commit a246a6a
committed
Fix MetricGroup requiring (y_pred, y) keys on mapping outputs
MetricGroup.update() already applies each child metric's own
output_transform to pull what it needs out of the group's output, per the
documented contract ("output_transform of each metric in the group is also
called upon its update"). But MetricGroup inherited Metric.iteration_completed
unchanged, which enforces required_output_keys == ("y_pred", "y") whenever
the (group-transformed) engine output is a mapping -- and unconditionally
raises if the group's own required_output_keys is None. That check only
makes sense for a single "leaf" metric consuming (y_pred, y) directly; a
MetricGroup wrapping heterogeneous child metrics with their own
output_transforms has no business requiring specific keys on the raw output.
As a result, any engine returning a dict with keys other than 'y_pred'/'y'
(e.g. a multi-output model returning {"outputs_1": ..., "masks": ...}) broke
as soon as it was wrapped in a MetricGroup, even though attaching the same
child metric directly worked fine. Manually setting required_output_keys on
the group didn't help either: it triggered MetricGroup's inherited
multi-output "unrolling" logic, which reinterpreted the mapping as a
(y_pred, y)-shaped tuple and unrolled it into mismatched per-metric updates.
Fixes #3806.
MetricGroup.iteration_completed is now overridden to pass a mapping output
straight through to update() without the required_output_keys check, while
preserving the existing multi-output unrolling behavior (skip_unrolling) for
non-mapping outputs. Added a regression test that attaches the same Loss
metric directly and via a MetricGroup and asserts they produce identical
results, which fails with the original ValueError on the pre-fix code.1 parent 563adbe commit a246a6a
2 files changed
Lines changed: 63 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
61 | 93 | | |
62 | 94 | | |
63 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
51 | 79 | | |
52 | 80 | | |
53 | 81 | | |
| |||
0 commit comments