Skip to content
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

Fixed typo "monotone_constaints" #1516

Merged
merged 7 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pytorch_forecasting/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def __init__(
reduce_on_plateau_min_lr: float = 1e-5,
weight_decay: float = 0.0,
optimizer_params: Dict[str, Any] = None,
monotone_constaints: Dict[str, int] = None,
monotone_constraints: Dict[str, int] = {},
output_transformer: Callable = None,
optimizer=None,
):
Expand All @@ -508,7 +508,7 @@ def __init__(
Defaults to 1e-5
weight_decay (float): weight decay. Defaults to 0.0.
optimizer_params (Dict[str, Any]): additional parameters for the optimizer. Defaults to {}.
monotone_constaints (Dict[str, int]): dictionary of monotonicity constraints for continuous decoder
monotone_constraints (Dict[str, int]): dictionary of monotonicity constraints for continuous decoder
variables mapping
position (e.g. ``"0"`` for first position) to constraint (``-1`` for negative and ``+1`` for positive,
larger numbers add more weight to the constraint vs. the loss but are usually not necessary).
Expand All @@ -522,8 +522,8 @@ def __init__(
`"ranger" <https://pytorch-optimizers.readthedocs.io/en/latest/optimizer_api.html#ranger21>`_,
if pytorch_optimizer is installed, otherwise "adam".
""" # noqa: E501
if monotone_constaints is None:
monotone_constaints = {}
if monotone_constraints is None:
monotone_constraints = {}
super().__init__()
# update hparams
frame = inspect.currentframe()
Expand Down Expand Up @@ -883,7 +883,7 @@ def step(
y[1],
)

if self.training and len(self.hparams.monotone_constaints) > 0:
if self.training and len(self.hparams.monotone_constraints) > 0:
# calculate gradient with respect to continous decoder features
x["decoder_cont"].requires_grad_(True)
assert not torch._C._get_cudnn_enabled(), (
Expand Down Expand Up @@ -913,11 +913,11 @@ def step(
indices = torch.tensor(
[
self.hparams.x_reals.index(name)
for name in self.hparams.monotone_constaints.keys()
for name in self.hparams.monotone_constraints.keys()
]
)
monotonicity = torch.tensor(
list(self.hparams.monotone_constaints.values()),
list(self.hparams.monotone_constraints.values()),
dtype=gradient.dtype,
device=gradient.device,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_models/test_temporal_fusion_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def _integration(dataloader, tmp_path, loss=None, trainer_kwargs=None, **kwargs)
)
# test monotone constraints automatically
if "discount_in_percent" in train_dataloader.dataset.reals:
monotone_constaints = {"discount_in_percent": +1}
monotone_constraints = {"discount_in_percent": +1}
cuda_context = torch.backends.cudnn.flags(enabled=False)
else:
monotone_constaints = {}
monotone_constraints = {}
cuda_context = nullcontext()

kwargs.setdefault("learning_rate", 0.15)
Expand Down Expand Up @@ -175,7 +175,7 @@ def _integration(dataloader, tmp_path, loss=None, trainer_kwargs=None, **kwargs)
log_interval=5,
log_val_interval=1,
log_gradient_flow=True,
monotone_constaints=monotone_constaints,
monotone_constraints=monotone_constraints,
**kwargs,
)
net.size()
Expand Down
Loading