Skip to content

Commit

Permalink
Merge branch 'main' into release-1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fkiraly committed Nov 19, 2024
2 parents e844929 + 3ff4ba7 commit 3aa3906
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypi_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ Maintenance update widening compatibility ranges and consolidating dependencies:

### Dependency changes

* the following are no longer core dependencies and have been changed to optional dependencies : `optuna`, `statsmodels`, `pytorch-optimize`, `matplotlib`. Environments relying on functionality requiring these dependencies need to be updated to instlal these explicitly.
* the following are no longer core dependencies and have been changed to optional dependencies : `optuna`, `statsmodels`, `pytorch-optimize`, `matplotlib`. Environments relying on functionality requiring these dependencies need to be updated to install these explicitly.
* `optuna` bounds have been updated to `optuna >=3.1.0,<4.0.0`
* `optuna-integrate` is now an additional soft dependency, in case of `optuna >=3.3.0`

### Deprecations and removals

* from 1.2.0, the default optimizer will be changed from `"ranger"` to `"adam"` to avoid non-`torch` dependencies in defaults. `pytorch-optimize` optimizers can still be used. Users should set the optimizer explicitly to continue using `"ranger"`.
* from 1.1.0, the loggers do not log figures if soft dependency `matplotlib` is not present, but will raise no exceptions in this case. To log figures, ensure tha `matplotlib` is installed.
* from 1.1.0, the loggers do not log figures if soft dependency `matplotlib` is not present, but will raise no exceptions in this case. To log figures, ensure that `matplotlib` is installed.

## v1.0.0 Update to pytorch 2.0 (10/04/2023)

Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The file specifies framework level core developers for automated review requests

* @benheid @fkiraly @fnhirwa @geetu040 @jdb78 @pranavvp16 @XinyuWuu @yarnabrina
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ version = "1.2.0" # is being replaced automatically
authors = [
{name = "Jan Beitner"},
]
requires-python = ">=3.8,<3.13"
requires-python = ">=3.9,<3.13"
classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down Expand Up @@ -115,14 +114,14 @@ dependencies = [
all_extras = [
"cpflows",
"matplotlib",
"optuna >=3.1.0,<4.0.0",
"optuna >=3.1.0,<5.0.0",
"optuna-integration",
"pytorch_optimizer >=2.5.1,<4.0.0",
"statsmodels",
]

tuning = [
"optuna >=3.1.0,<4.0.0",
"optuna >=3.1.0,<5.0.0",
"optuna-integration",
"statsmodels",
]
Expand Down
19 changes: 18 additions & 1 deletion pytorch_forecasting/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,18 @@ def log_interval(self) -> float:
else:
return self.hparams.log_val_interval

def _logger_supports(self, method: str) -> bool:
"""Whether logger supports method.
Returns
-------
supports_method : bool
True if attribute self.logger.experiment.method exists, False otherwise.
"""
if not hasattr(self, "logger") or not hasattr(self.logger, "experiment"):
return False
return hasattr(self.logger.experiment, method)

def log_prediction(
self, x: Dict[str, torch.Tensor], out: Dict[str, torch.Tensor], batch_idx: int, **kwargs
) -> None:
Expand All @@ -981,6 +993,10 @@ def log_prediction(
if not mpl_available:
return None # don't log matplotlib plots if not available

# Don't log figures if add_figure is not available
if not self._logger_supports("add_figure"):
return None

for idx in log_indices:
fig = self.plot_prediction(x, out, idx=idx, add_loss_to_title=True, **kwargs)
tag = f"{self.current_stage} prediction"
Expand Down Expand Up @@ -1156,7 +1172,8 @@ def log_gradient_flow(self, named_parameters: Dict[str, torch.Tensor]) -> None:

mpl_available = _check_matplotlib("log_gradient_flow", raise_error=False)

if not mpl_available:
# Don't log figures if matplotlib or add_figure is not available
if not mpl_available or not self._logger_supports("add_figure"):
return None

import matplotlib.pyplot as plt
Expand Down
3 changes: 2 additions & 1 deletion pytorch_forecasting/models/nbeats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ def log_interpretation(self, x, out, batch_idx):
"""
mpl_available = _check_matplotlib("log_interpretation", raise_error=False)

if not mpl_available:
# Don't log figures if matplotlib or add_figure is not available
if not mpl_available or not self._logger_supports("add_figure"):
return None

label = ["val", "train"][self.training]
Expand Down
3 changes: 2 additions & 1 deletion pytorch_forecasting/models/nhits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ def log_interpretation(self, x, out, batch_idx):
"""
mpl_available = _check_matplotlib("log_interpretation", raise_error=False)

if not mpl_available:
# Don't log figures if matplotlib or add_figure is not available
if not mpl_available or not self._logger_supports("add_figure"):
return None

label = ["val", "train"][self.training]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,8 @@ def log_interpretation(self, outputs):

mpl_available = _check_matplotlib("log_interpretation", raise_error=False)

if not mpl_available:
# Don't log figures if matplotlib or add_figure is not available
if not mpl_available or not self._logger_supports("add_figure"):
return None

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -885,6 +886,11 @@ def log_embeddings(self):
"""
Log embeddings to tensorboard
"""

# Don't log embeddings if add_embedding is not available
if not self._logger_supports("add_embedding"):
return None

for name, emb in self.input_embeddings.items():
labels = self.hparams.embedding_labels[name]
self.logger.experiment.add_embedding(
Expand Down

0 comments on commit 3aa3906

Please sign in to comment.