Skip to content

[ENH] Add TSMixer v2 model - #2387

Open
seaic-mac-murchadha wants to merge 25 commits into
sktime:mainfrom
seaic-mac-murchadha:tsmixer-v2
Open

[ENH] Add TSMixer v2 model#2387
seaic-mac-murchadha wants to merge 25 commits into
sktime:mainfrom
seaic-mac-murchadha:tsmixer-v2

Conversation

@seaic-mac-murchadha

Copy link
Copy Markdown

Reference Issues/PRs

For issue #1992 which requires implementing "models to the v2 interface". This PR adds the TSMixer implementation for the v2 interface.

#1992

What does this implement/fix? Explain your changes.

Implements TSMixer model for the v2 interface, including:

  • temporal and channel mixing blocks
  • point forecasting
  • QuantileLoss support
  • model and input handling tests

What should a reviewer concentrate their feedback on?

The implementation is complete as an initial functional TSMixer v2 integration.

Quantile forecasting with multiple targets and inputs without target history will raise explicit errors. Feedback on methodology for resolving these cases without errors would be welcome if their support is required.

Did you add any tests for the change?

Yes, PR has corresponding tests implemented therein, covering:

  • model initialization
  • point forecasting
  • quantile forecasting
  • input preparation
  • error handling

Any other comments?

Only single-target quantile forecasting is currently supported, consistent with the current DLinear implementation.

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

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2387   +/-   ##
=======================================
  Coverage        ?   88.22%           
=======================================
  Files           ?      199           
  Lines           ?    11142           
  Branches        ?        0           
=======================================
  Hits            ?     9830           
  Misses          ?     1312           
  Partials        ?        0           
Flag Coverage Δ
cpu 88.22% <100.00%> (?)
pytest 88.22% <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.

@phoeenniixx phoeenniixx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!
Please add docstrings to the public classes and methods

Also, for the test file, i think most of those tests are already handled by the unified test framework no? Can you please de-duplicate the file

Also, can you please add the API reference for the model and pkg class as well?

class.
"""

import torch.nn as nn

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need this import?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’m using it for nn.MSELoss() within the test. Would it be preferable to remove this case, or perhaps move the import to the top of the file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, I missed it the last time

from pytorch_forecasting.models.base._tslib_base_model_v2 import TslibBaseModel


class TSMixerBlock(nn.Module):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please add docstrings here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Definitely, have added docstrings to the TSMixerBlock class and its forward function in the latest commit.

metadata=metadata,
)

warnings.warn(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the warning is already handled by BaseModel no? See here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @phoeenniixx, have removed the redundant warning now.

Comment thread tests/test_models/test_tsmixer_v2.py Outdated
assert model.n_quantiles is None


def test_tsmixer_forward(sample_dataset):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is already being tested by the test framework

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, it isn't adding a meaningful test, have removed it now. Thanks @phoeenniixx.

@phoeenniixx phoeenniixx added enhancement New feature or request module:models ptf-v2 Related to `pytorch-forecasting` v2 labels Aug 22, 2026
@seaic-mac-murchadha
seaic-mac-murchadha force-pushed the tsmixer-v2 branch 2 times, most recently from 8277cc0 to 9b7ab27 Compare August 23, 2026 22:03
@seaic-mac-murchadha

Copy link
Copy Markdown
Author

Hi @phoeenniixx,

Thank you for the review. Have attempted to address the four comments left. Additionally, the generic tests have been removed and TSMixer has been added to the API documentation.

@seaic-mac-murchadha

Copy link
Copy Markdown
Author

Hi @phoeenniixx,

The failure appears to be due to a network/DNS issue whilst downloading stallion.parquet, rather than the PR code changes. Would a re-run be possible?

from pytorch_forecasting.models.base._tslib_base_model_v2 import TslibBaseModel


class TSMixerBlock(nn.Module):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this be added to layers/_blocks? Sorry i didnt notice this earlier



@pytest.fixture
def sample_dataset():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can use examples.load_toydata as well here and then pass that to TimeSeries

@phoeenniixx phoeenniixx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! i think it is almost ready!
Just a few nit-picks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module:models ptf-v2 Related to `pytorch-forecasting` v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants