-
Notifications
You must be signed in to change notification settings - Fork 739
[ENH] Implementing the iTransformer model in PTFv2.
#1994
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
Draft
JATAYU000
wants to merge
7
commits into
sktime:main
Choose a base branch
from
JATAYU000:iTransformer
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.
+433
−45
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
302ec0f
Initial Implementation of iTransformer
JATAYU000 abeb908
Import modules from submodules
JATAYU000 4d9d809
Quantile preds
JATAYU000 48cb4ed
Added Docstrings, removed use_norm
JATAYU000 171326f
Unused imports
JATAYU000 8eccc2b
Update Encoder layer and output attention
JATAYU000 4fbaeea
Merge branch 'main' into iTransformer
JATAYU000 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
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
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,13 @@ | ||
| """ | ||
| iTransformer model for forecasting time series. | ||
| """ | ||
|
|
||
| from pytorch_forecasting.models.itransformer._itransformer_pkg_v2 import ( | ||
| iTransformer_pkg_v2, | ||
| ) | ||
| from pytorch_forecasting.models.itransformer._itransformer_v2 import iTransformer | ||
|
|
||
| __all__ = [ | ||
| "iTransformer", | ||
| "iTransformer_pkg_v2", | ||
| ] |
133 changes: 133 additions & 0 deletions
133
pytorch_forecasting/models/itransformer/_itransformer_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,133 @@ | ||
| """iTransformer package container v2.""" | ||
|
|
||
| from pytorch_forecasting.models.base._base_object import _BasePtForecasterV2 | ||
|
|
||
|
|
||
| class iTransformer_pkg_v2(_BasePtForecasterV2): | ||
| """iTransformer metadata container.""" | ||
|
|
||
| _tags = { | ||
| "info:name": "iTransformer", | ||
| "authors": ["JATAYU000"], | ||
| "capability:exogenous": True, | ||
| "capability:multivariate": True, | ||
| "capability:pred_int": True, | ||
| "capability:flexible_history_length": False, | ||
| "capability:cold_start": False, | ||
| } | ||
|
|
||
| @classmethod | ||
| def get_cls(cls): | ||
| """Get model class.""" | ||
| from pytorch_forecasting.models.itransformer._itransformer_v2 import ( | ||
| iTransformer, | ||
| ) | ||
|
|
||
| return iTransformer | ||
|
|
||
| @classmethod | ||
| def _get_test_datamodule_from(cls, trainer_kwargs): | ||
| """Create test dataloaders from trainer_kwargs - following v1 pattern.""" | ||
| from pytorch_forecasting.data._tslib_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", 12) | ||
| prediction_length = data_loader_kwargs.get("prediction_length", 4) | ||
| 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=1, | ||
| 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): | ||
| """Get test train params.""" | ||
| from pytorch_forecasting.metrics import QuantileLoss | ||
|
|
||
| return [ | ||
| {}, | ||
| dict(d_model=16, n_heads=2, e_layers=2, d_ff=64), | ||
| dict( | ||
| d_model=32, | ||
| n_heads=4, | ||
| e_layers=3, | ||
| d_ff=128, | ||
| dropout=0.1, | ||
| data_loader_kwargs=dict( | ||
| batch_size=4, context_length=8, prediction_length=4 | ||
| ), | ||
| ), | ||
| dict( | ||
| hidden_size=32, | ||
| n_heads=2, | ||
| e_layers=1, | ||
| d_ff=64, | ||
| factor=2, | ||
| activation="relu", | ||
| dropout=0.05, | ||
| data_loader_kwargs=dict( | ||
| context_length=16, | ||
| prediction_length=4, | ||
| ), | ||
| loss=QuantileLoss(quantiles=[0.1, 0.5, 0.9]), | ||
| ), | ||
| ] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a few more test cases here?