-
Notifications
You must be signed in to change notification settings - Fork 885
[ENH] Integrate Autoformer model into V2 architecture #2303
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
harshsomankar123-tech
wants to merge
16
commits into
sktime:main
Choose a base branch
from
harshsomankar123-tech:add-autoformer-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
df37645
feat: Add Autoformer model to V2 interface
harshsomankar123-tech 82d5d65
style: Fix ruff code quality format issues
harshsomankar123-tech 0162332
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 1e4a2b8
fix: Correct TslibDataModule import path for Autoformer
harshsomankar123-tech 14c0379
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech c3afeb7
refactor: move Autoformer layers to shared layers module and address …
harshsomankar123-tech 2193b99
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 30d496d
refactor: remove old my_Layernorm alias from sub_modules.py
harshsomankar123-tech 0514006
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 22b70ba
refactor: address review - delete sub_modules.py, add missing y_type …
harshsomankar123-tech 9a566ba
fix: remove incompatible logging_metrics from QuantileLoss test params
harshsomankar123-tech 562cc27
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech cd13277
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 2ba5cbe
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 72e5373
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech 630230a
Merge branch 'main' into add-autoformer-v2
harshsomankar123-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| """ | ||
| Autoformer model for time series forecasting. | ||
| """ | ||
|
|
||
| from pytorch_forecasting.models.autoformer._autoformer_pkg_v2 import Autoformer_pkg_v2 | ||
| from pytorch_forecasting.models.autoformer._autoformer_v2 import Autoformer | ||
|
|
||
| __all__ = ["Autoformer", "Autoformer_pkg_v2"] |
155 changes: 155 additions & 0 deletions
155
pytorch_forecasting/models/autoformer/_autoformer_pkg_v2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| """ | ||
| Packages container for Autoformer model. | ||
| """ | ||
|
|
||
| from pytorch_forecasting.base._base_pkg import Base_pkg | ||
|
|
||
|
|
||
| class Autoformer_pkg_v2(Base_pkg): | ||
| """Autoformer package container.""" | ||
|
|
||
| _tags = { | ||
| "info:name": "Autoformer", | ||
| "info:compute": 2, | ||
| "authors": ["harshsomankar123-tech"], | ||
| "capability:exogenous": True, | ||
| "capability:multivariate": True, | ||
| "capability:pred_int": True, | ||
| "capability:flexible_history_length": True, | ||
| "capability:cold_start": False, | ||
| } | ||
|
|
||
| @classmethod | ||
| def get_cls(cls): | ||
| """Get model class.""" | ||
| from pytorch_forecasting.models.autoformer._autoformer_v2 import Autoformer | ||
|
|
||
| return Autoformer | ||
|
|
||
| @classmethod | ||
| def get_datamodule_cls(cls): | ||
| """Get the underlying DataModule class.""" | ||
| from pytorch_forecasting.data.data_module import TslibDataModule | ||
|
|
||
| return TslibDataModule | ||
|
|
||
| @classmethod | ||
| def _get_test_datamodule_from(cls, trainer_kwargs): | ||
|
harshsomankar123-tech marked this conversation as resolved.
Outdated
|
||
| """Create test dataloaders from trainer_kwargs - following v1/v2 pattern.""" | ||
| from pytorch_forecasting.data.data_module import TslibDataModule | ||
| from pytorch_forecasting.tests._data_scenarios import ( | ||
| data_with_covariates_v2, | ||
| make_datasets_v2, | ||
| ) | ||
|
|
||
| data_with_covariates = data_with_covariates_v2() | ||
| data_loader_default_kwargs = dict( | ||
| target="target", | ||
| group_ids=["agency_encoded", "sku_encoded"], | ||
| add_relative_time_idx=True, | ||
| ) | ||
|
|
||
| data_loader_kwargs = trainer_kwargs.get("data_loader_kwargs", {}) | ||
| data_loader_default_kwargs.update(data_loader_kwargs) | ||
|
|
||
| datasets_info = make_datasets_v2( | ||
| data_with_covariates, **data_loader_default_kwargs | ||
| ) | ||
|
|
||
| training_dataset = datasets_info["training_dataset"] | ||
| validation_dataset = datasets_info["validation_dataset"] | ||
|
|
||
| context_length = data_loader_kwargs.get("context_length", 8) | ||
| prediction_length = data_loader_kwargs.get("prediction_length", 2) | ||
| batch_size = data_loader_kwargs.get("batch_size", 2) | ||
|
|
||
| train_datamodule = TslibDataModule( | ||
| time_series_dataset=training_dataset, | ||
| context_length=context_length, | ||
| prediction_length=prediction_length, | ||
| add_relative_time_idx=data_loader_kwargs.get("add_relative_time_idx", True), | ||
| batch_size=batch_size, | ||
| train_val_test_split=(0.8, 0.2, 0.0), | ||
| ) | ||
|
|
||
| val_datamodule = TslibDataModule( | ||
| time_series_dataset=validation_dataset, | ||
| context_length=context_length, | ||
| prediction_length=prediction_length, | ||
| add_relative_time_idx=data_loader_kwargs.get("add_relative_time_idx", True), | ||
| batch_size=batch_size, | ||
| train_val_test_split=(0.0, 1.0, 0.0), | ||
| ) | ||
|
|
||
| test_datamodule = TslibDataModule( | ||
| time_series_dataset=validation_dataset, | ||
| context_length=context_length, | ||
| prediction_length=prediction_length, | ||
| add_relative_time_idx=data_loader_kwargs.get("add_relative_time_idx", True), | ||
| batch_size=batch_size, | ||
| train_val_test_split=(0.0, 0.0, 1.0), | ||
| ) | ||
|
|
||
| train_datamodule.setup("fit") | ||
| val_datamodule.setup("fit") | ||
| test_datamodule.setup("test") | ||
|
|
||
| train_dataloader = train_datamodule.train_dataloader() | ||
| val_dataloader = val_datamodule.val_dataloader() | ||
| test_dataloader = test_datamodule.test_dataloader() | ||
|
|
||
| return { | ||
| "train": train_dataloader, | ||
| "val": val_dataloader, | ||
| "test": test_dataloader, | ||
| "data_module": train_datamodule, | ||
| } | ||
|
|
||
| @classmethod | ||
| def get_test_train_params(cls): | ||
| """ | ||
| Return testing parameter settings for the trainer. | ||
| """ | ||
| from pytorch_forecasting.metrics import SMAPE | ||
|
|
||
| params = [ | ||
| # First set: smaller network params for fast testing | ||
| dict( | ||
| hidden_size=16, | ||
| n_heads=2, | ||
| e_layers=1, | ||
| d_layers=1, | ||
| d_ff=32, | ||
|
harshsomankar123-tech marked this conversation as resolved.
|
||
| ), | ||
| # Second set: custom moving_avg and logging metrics | ||
| dict( | ||
| hidden_size=8, | ||
| n_heads=2, | ||
| e_layers=1, | ||
| d_layers=1, | ||
| d_ff=16, | ||
| moving_avg=5, | ||
| logging_metrics=[SMAPE()], | ||
| ), | ||
| # Third set: custom scheduler | ||
| dict( | ||
| hidden_size=8, | ||
| n_heads=2, | ||
| e_layers=1, | ||
| d_layers=1, | ||
| d_ff=16, | ||
| optimizer="adamw", | ||
| lr_scheduler="cosine_annealing", | ||
| lr_scheduler_params={"T_max": 5}, | ||
| ), | ||
| ] | ||
|
|
||
| default_dm_cfg = {"context_length": 8, "prediction_length": 2} | ||
|
|
||
| for param in params: | ||
| current_dm_cfg = param.get("datamodule_cfg", {}) | ||
| default_dm_cfg.update(current_dm_cfg) | ||
|
|
||
| param["datamodule_cfg"] = default_dm_cfg | ||
|
|
||
| return params | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.