Skip to content

[BUG] Propagate dtype conversion through composed and wrapped metrics - #2467

Open
AHMETHAKANBEZIR1 wants to merge 3 commits into
sktime:mainfrom
AHMETHAKANBEZIR1:fix/multiloss-set-dtype
Open

AHMETHAKANBEZIR1 wants to merge 3 commits into
sktime:mainfrom
AHMETHAKANBEZIR1:fix/multiloss-set-dtype

Conversation

@AHMETHAKANBEZIR1

@AHMETHAKANBEZIR1 AHMETHAKANBEZIR1 commented Oct 14, 2026 •

Copy link
Copy Markdown

LLM generated content, by OpenAI Codex

Reference Issues/PRs

Independent of #1897 (input dimensions) and #1754 (checkpoint device mapping).

What does this implement/fix? Explain your changes.

MultiLoss([MAE(), MAE()]).set_dtype(torch.float64) and (MAE() + MAE()).set_dtype(torch.float64) currently change the composite's dtype but leave constituent metrics and state in float32. These metrics are held in ordinary Python lists. For a third-party TorchMetrics metric accepted by the public coercion factory, converting its wrapper also leaves the underlying metric's state in the old dtype because TorchMetrics requires its own set_dtype call.

Delegate set_dtype through MultiLoss, CompositeMetric and TorchMetricWrapper, retaining the parent conversion and fluent return value. This preserves public list representation, registration/state-dict behavior, weights and each metric's conversion semantics. Device conversion and checkpoint loading are unchanged.

What should a reviewer concentrate their feedback on?

Explicit delegation through each composition boundary, including conversion after update/compute and defaults used by reset. No module-registration redesign is involved.

Did you add any tests for the change?

Twenty-five cases cover float32/float64 in both directions, no-op conversions, empty/populated state, cached compute results, reset defaults, third-party TorchMetrics wrapped through the public factory, and the string dtype API with adapted MSELoss, weighted results and analytic gradients. Clean main 6d0d18a has 13 failures and 12 passing controls; all twenty-five pass with the fix.

Complete tests/test_metrics.py: 95 passed, 6 existing optional cpflows skips. Configured pre-commit hooks pass across all files and at commit. CPU Python 3.12.14 / PyTorch 2.13.0. Full-package, GPU, distributed and training benchmarks were not run.

Any other comments?

Prepared autonomously with OpenAI Codex; no independent human review is claimed.

PR checklist

  • The PR title starts with [BUG].
  • Added/modified tests.
  • Used pre-commit hooks when committing.

@AHMETHAKANBEZIR1 AHMETHAKANBEZIR1 changed the title [BUG] Propagate MultiLoss dtype conversion to constituent metrics [BUG] Propagate composed metric dtype conversion to constituent metrics Oct 14, 2026
@AHMETHAKANBEZIR1 AHMETHAKANBEZIR1 changed the title [BUG] Propagate composed metric dtype conversion to constituent metrics [BUG] Propagate dtype conversion through composed and wrapped metrics Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@6d0d18a). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2467   +/-   ##
=======================================
  Coverage        ?   89.07%           
=======================================
  Files           ?      218           
  Lines           ?    11684           
  Branches        ?        0           
=======================================
  Hits            ?    10407           
  Misses          ?     1277           
  Partials        ?        0           
Flag Coverage Δ
cpu 89.07% <100.00%> (?)
pytest 89.07% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant