Skip to content

[ENH] Consistent 3D output for single-target point predictions in TimeXer v1. #1936

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

PranavBhatP
Copy link
Contributor

Reference Issues/PRs

What does this implement/fix? Explain your changes.

Small change in the code to provide a 3d output tensor for point predictions with 3rd dimension set to 1. With this change the output contract for TimeXer is

  • Point predictions: (batch_size, predictions, 1) where the 3rd dimension indicates a single target.
  • Quantile predicitons: (batch_size, predictions, num_quantiles) where the 3rd dimension indicates the number of quantiles for which the output is generated.

What should a reviewer concentrate their feedback on?

PR checklist

  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
  • Added/modified tests
  • Used pre-commit hooks when committing to ensure that code is compliant with hooks. Install hooks with pre-commit install.
    To run hooks independent of commit, execute pre-commit run --all-files

@PranavBhatP PranavBhatP changed the title [ENH] Consistent 3D output for single-target point predictions in TimeXer v1 and predict [ENH] Consistent 3D output for single-target point predictions in TimeXer v1. Aug 1, 2025
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1936   +/-   ##
=======================================
  Coverage        ?   87.07%           
=======================================
  Files           ?      136           
  Lines           ?     8612           
  Branches        ?        0           
=======================================
  Hits            ?     7499           
  Misses          ?     1113           
  Partials        ?        0           
Flag Coverage Δ
cpu 87.07% <100.00%> (?)
pytest 87.07% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

@fkiraly fkiraly moved this to PR in progress in May - Sep 2025 mentee projects Aug 1, 2025
@fkiraly fkiraly moved this from PR in progress to PR under review in May - Sep 2025 mentee projects Aug 1, 2025
@fkiraly fkiraly added the enhancement New feature or request label Aug 2, 2025
Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried that we are removing tests but not adding tests.

If we are removing an API stepout, then we should remove a stepout in the testes to match, no?

@PranavBhatP
Copy link
Contributor Author

PranavBhatP commented Aug 2, 2025

it was an unintended removal, happened by mistake, sorry. The code stays the same in test_timexer.py

@PranavBhatP PranavBhatP requested a review from fkiraly August 4, 2025 12:34
Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so it was a bug! Good that we do reviews.

Related question: is there a stepout we can remove now?

@PranavBhatP PranavBhatP requested a review from fkiraly August 9, 2025 17:17
@PranavBhatP
Copy link
Contributor Author

is there a stepout we can remove now?

with that question in mind, I tried tweaking with a few of the tensor shapes, and I was able to reduce the number of stepouts. now, the default return is a 3d tensor - (batch_size, prediction,_length, n_quantiles). For point predictions, n_quantiles = 1 by default, and for explicit quantiles we equate the n_quantiles=len(loss.quantiles) where loss has to be QuantileLoss

Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mention you reduced the number of stepouts, but I do not see a change in tests - did you forget to push them?

@PranavBhatP
Copy link
Contributor Author

PranavBhatP commented Aug 9, 2025

no i meant stepouts in the actual model code. We were handling quantile and non-quantile predictions separately inside the model. But with this PR, I have unified the handling to a single format for all types of metrics used (quantile or point).

The code for the tests ultimately remains the same, since we are testing the output shape of predict API for TimeXer, which is not the concern of this PR.

If there is a misunderstanding, please let me know.

@PranavBhatP PranavBhatP requested a review from fkiraly August 10, 2025 13:50
@fkiraly
Copy link
Collaborator

fkiraly commented Aug 10, 2025

Yes, I meant tests.

I think thta one of the following must be true:

  • there was a stepout in the tests that we can now remove
  • the tests were not complete or were faulty (e.g., they are not covering the API this was a stepout from)

@agobbifbk
Copy link

Seems that all the shape are well managed. Here you are using the self.n_quantiles as indicator of the number of output per channel. What if I want to use a distribution loss here? Should we rename it in a more general way?

Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating my review request:

  • if there was a stepout for the forecaster in tests, please remove the stepout
  • if there was no stepout, please review the tests why there was no stepout and/or why they still passed

@PranavBhatP
Copy link
Contributor Author

PranavBhatP commented Aug 14, 2025

Here you are using the self.n_quantiles as indicator of the number of output per channel. What if I want to use a distribution loss here? Should we rename it in a more general way?

I see a possibility of using DistributionLoss metrics with TimeXer, and it might need a few tweaks to get it working. I don't think it works in the current sense. I think we can maybe park this as an item for a separate PR, since we have to again add tests for its usage with distribution losses.

@PranavBhatP
Copy link
Contributor Author

PranavBhatP commented Aug 14, 2025

Repeating my review request:
if there was a stepout for the forecaster in tests, please remove the stepout
if there was no stepout, please review the tests why there was no stepout and/or why they still passed

I looked at the code, and I think there is missing test. Until now we were only testing the output for model.predict. The reason why the tests were passing was because the output of predict remains consistent, independent of the input format as it is dependent on the metric used in the model. However there is nothing to test the output of the model from its forward method. This is pending work and was missed previously, imo. I will add the test in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: PR under review
Development

Successfully merging this pull request may close these issues.

3 participants