Skip to content

Commit

Permalink
Merge branch 'master' into weight-size-bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jdb78 authored Sep 10, 2023
2 parents c266977 + b4ce1cf commit 01937ba
Show file tree
Hide file tree
Showing 9 changed files with 2,048 additions and 2,455 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ repos:
- id: check-yaml
- id: check-ast
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.9.0
hooks:
- id: black
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.4
rev: 1.7.0
hooks:
- id: nbqa-black
- id: nbqa-isort
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docutils
pydata-sphinx-theme
lightning>=2.0.0
cloudpickle
torch>=2.0
torch>=2.0,!=2.0.1
optuna>=3.1.0
scipy
pandas>=1.3
Expand Down
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ def setup(app: Sphinx):
"../../CHANGELOG.md",
"CHANGELOG.md",
)

intersphinx_mapping = {
"sklearn": ("https://scikit-learn.org/stable/", None),
}
11 changes: 6 additions & 5 deletions docs/source/tutorials/ar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@
],
"source": [
"# calculate baseline absolute error\n",
"actuals = torch.cat([y[0] for x, y in iter(val_dataloader)])\n",
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"actuals = torch.cat([y[0] for x, y in iter(val_dataloader)]).to(device)\n",
"baseline_predictions = Baseline().predict(val_dataloader)\n",
"SMAPE()(baseline_predictions, actuals)"
]
Expand Down Expand Up @@ -519,7 +520,7 @@
}
],
"source": [
"actuals = torch.cat([y[0] for x, y in iter(val_dataloader)])\n",
"actuals = torch.cat([y[0] for x, y in iter(val_dataloader)]).to(device)\n",
"predictions = best_model.predict(val_dataloader)\n",
"(actuals - predictions).abs().mean()"
]
Expand All @@ -538,7 +539,7 @@
"metadata": {},
"outputs": [],
"source": [
"raw_predictions, x = best_model.predict(val_dataloader, mode=\"raw\", return_x=True)"
"raw_predictions = best_model.predict(val_dataloader, mode=\"raw\", return_x=True)"
]
},
{
Expand Down Expand Up @@ -649,7 +650,7 @@
],
"source": [
"for idx in range(10): # plot 10 examples\n",
" best_model.plot_prediction(x, raw_predictions, idx=idx, add_loss_to_title=True)"
" best_model.plot_prediction(raw_predictions.x, raw_predictions.output, idx=idx, add_loss_to_title=True)"
]
},
{
Expand Down Expand Up @@ -797,7 +798,7 @@
],
"source": [
"for idx in range(10): # plot 10 examples\n",
" best_model.plot_interpretation(x, raw_predictions, idx=idx)"
" best_model.plot_interpretation(raw_predictions.x, raw_predictions.output, idx=idx)"
]
},
{
Expand Down
4,412 changes: 1,998 additions & 2,414 deletions poetry.lock

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ black = 1

[tool.poetry]
name = "pytorch_forecasting"
readme = "README.md" # Markdown files are supported
version = "0.0.0" # is being replaced automatically
readme = "README.md" # Markdown files are supported
version = "0.0.0" # is being replaced automatically

authors = ["Jan Beitner"]
classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License"]
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License",
]
description = "Forecasting timeseries with PyTorch - dataloaders, normalizers, metrics and models"
repository = "https://github.com/jdb78/pytorch-forecasting"
documentation = "https://pytorch-forecasting.readthedocs.io"
Expand All @@ -54,7 +55,7 @@ homepage = "https://pytorch-forecasting.readthedocs.io"
[tool.poetry.dependencies]
python = ">=3.8,<3.11"

torch = "^2.0.0"
torch = "^2.0.0,!=2.0.1"
lightning = "^2.0.0"
optuna = "^3.1.0"
scipy = "^1.8"
Expand All @@ -63,9 +64,9 @@ scikit-learn = "^1.2"
matplotlib = "*"
statsmodels = "*"

pytest-github-actions-annotate-failures = {version = "*", optional = true}
networkx = {version = "^3.0.0", optional = true}
cpflows = {version="^0.1.2", optional = true}
pytest-github-actions-annotate-failures = { version = "*", optional = true }
networkx = { version = "^3.0.0", optional = true }
cpflows = { version = "^0.1.2", optional = true }
fastapi = ">=0.80"
pytorch-optimizer = "^2.5.1"

Expand Down Expand Up @@ -104,7 +105,7 @@ tensorboard = "^2.12.1"
pandoc = "^2.3"


[tool.poetry.extras] # extras
[tool.poetry.extras] # extras
github-actions = ["pytest-github-actions-annotate-failures"]
graph = ["networkx"]
mqf2 = ["cpflows"]
Expand All @@ -113,8 +114,8 @@ mqf2 = ["cpflows"]
enable = true
vcs = "git"
dirty = false
style = "semver" # semantic versioning
style = "semver" # semantic versioning

[build-system] # make the package pip installable
[build-system] # make the package pip installable
requires = ["poetry-core>=1.0.7", "poetry-dynamic-versioning>=0.13.1"]
build-backend = "poetry_dynamic_versioning.backend"
6 changes: 4 additions & 2 deletions pytorch_forecasting/data/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(
add_relative_time_idx: bool = False,
add_target_scales: bool = False,
add_encoder_length: Union[bool, str] = "auto",
target_normalizer: Union[NORMALIZER, str, List[NORMALIZER], Tuple[NORMALIZER]] = "auto",
target_normalizer: Union[NORMALIZER, str, List[NORMALIZER], Tuple[NORMALIZER], None] = "auto",
categorical_encoders: Dict[str, NaNLabelEncoder] = {},
scalers: Dict[str, Union[StandardScaler, RobustScaler, TorchNormalizer, EncoderNormalizer]] = {},
randomize_length: Union[None, Tuple[float, float], bool] = False,
Expand Down Expand Up @@ -291,7 +291,7 @@ def __init__(
the index will range from -encoder_length to prediction_length)
add_target_scales (bool): if to add scales for target to static real features (i.e. add the center and scale
of the unnormalized timeseries as features)
add_encoder_length (bool): if to add decoder length to list of static real variables.
add_encoder_length (bool): if to add encoder length to list of static real variables.
Defaults to "auto", i.e. ``True`` if ``min_encoder_length != max_encoder_length``.
target_normalizer (Union[TorchNormalizer, NaNLabelEncoder, EncoderNormalizer, str, list, tuple]):
transformer that take group_ids, target and time_idx to normalize targets.
Expand Down Expand Up @@ -1559,6 +1559,8 @@ def __getitem__(self, idx: int) -> Tuple[Dict[str, torch.Tensor], torch.Tensor]:
data_cat = data_cat[encoder_length - new_encoder_length : encoder_length + new_decoder_length]
data_cont = data_cont[encoder_length - new_encoder_length : encoder_length + new_decoder_length]
target = [t[encoder_length - new_encoder_length : encoder_length + new_decoder_length] for t in target]
if weight is not None:
weight = weight[encoder_length - new_encoder_length : encoder_length + new_decoder_length]
encoder_length = new_encoder_length
decoder_length = new_decoder_length

Expand Down
15 changes: 8 additions & 7 deletions pytorch_forecasting/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(
def _reset_data(self, result: bool = True):
# reset data objects to save results into
self._output = []
self._decode_lenghts = []
self._decode_lengths = []
self._x_list = []
self._index = []
self._y = []
Expand Down Expand Up @@ -267,8 +267,8 @@ def on_predict_batch_end(
self._index.append(trainer.predict_dataloaders.dataset.x_to_index(x))
out["index"] = self._index[-1]
if self.return_decoder_lengths:
self._decode_lenghts.append(lengths)
out["decoder_lengths"] = self._decode_lenghts[-1]
self._decode_lengths.append(lengths)
out["decoder_lengths"] = self._decode_lengths[-1]
if self.return_y:
self._y.append(batch[1])
out["y"] = self._y[-1]
Expand Down Expand Up @@ -312,7 +312,7 @@ def on_predict_epoch_end(self, trainer: "pl.Trainer", pl_module: "pl.LightningMo
if self.return_index:
output["index"] = pd.concat(self._index, axis=0, ignore_index=True)
if self.return_decoder_lengths:
output["decoder_lengths"] = torch.cat(self._decode_lenghts, dim=0)
output["decoder_lengths"] = torch.cat(self._decode_lengths, dim=0)
if self.return_y:
y = concat_sequences([yi[0] for yi in self._y])
if self._y[-1][1] is None:
Expand Down Expand Up @@ -1477,13 +1477,14 @@ def predict_dependency(
# set values
data.set_overwrite_values(variable=variable, values=value, target=target)
# predict
kwargs.setdefault("mode", "prediction")
pred_kwargs = deepcopy(kwargs)
pred_kwargs.setdefault("mode", "prediction")

if idx == 0 and mode == "dataframe": # need index for returning as dataframe
res = self.predict(data, return_index=True, **kwargs)
res = self.predict(data, return_index=True, **pred_kwargs)
results.append(res.output)
else:
results.append(self.predict(data, **kwargs))
results.append(self.predict(data, **pred_kwargs))
# increment progress
progress_bar.update()

Expand Down
2 changes: 1 addition & 1 deletion pytorch_forecasting/models/nhits/sub_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def forward(


def init_weights(module, initialization):
if type(module) == torch.nn.Linear:
if type(module) is torch.nn.Linear:
if initialization == "orthogonal":
torch.nn.init.orthogonal_(module.weight)
elif initialization == "he_uniform":
Expand Down

0 comments on commit 01937ba

Please sign in to comment.