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

exclude PLForecastingModule docs from custom rnn and blockrnn modules #2115

Merged
merged 1 commit into from
Dec 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions darts/models/forecasting/block_rnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ def __init__(
The fraction of neurons that are dropped in all-but-last RNN layers.
**kwargs
all parameters required for :class:`darts.model.forecasting_models.PLForecastingModule` base class.

Inputs
------
x of shape `(batch_size, input_chunk_length, input_size, nr_params)`
Tensor containing the features of the input sequence.

Outputs
-------
y of shape `(batch_size, output_chunk_length, target_size, nr_params)`
Tensor containing the prediction at the last time step of the sequence.
"""
super().__init__(**kwargs)

Expand All @@ -91,6 +81,21 @@ def __init__(
@io_processor
@abstractmethod
def forward(self, x_in: Tuple) -> torch.Tensor:
"""BlockRNN Module forward.

Parameters
----------
x_in
Tuple of Tensors containing the features of the input sequence. The tuple has elements
(past target, historic future covariates, future covariates, static covariates).
The shape of the past target is `(batch_size, input_length, input_size)`.

Returns
-------
torch.Tensor
The BlockRNN output Tensor with shape `(batch_size, output_chunk_length, target_size, nr_params)`.
It contains the prediction at the last time step of the sequence.
"""
pass


Expand Down
2 changes: 2 additions & 0 deletions darts/models/forecasting/pl_forecasting_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from abc import ABC, abstractmethod
from functools import wraps
from typing import Any, Dict, Optional, Sequence, Tuple, Union

import pytorch_lightning as pl
Expand Down Expand Up @@ -42,6 +43,7 @@ def forward(self, *args, **kwargs)
normalizes batch input target features, and inverse transform the forward output back to the original scale
"""

@wraps(forward)
def forward_wrapper(self, *args, **kwargs):
if not self.use_reversible_instance_norm:
return forward(self, *args, **kwargs)
Expand Down
31 changes: 19 additions & 12 deletions darts/models/forecasting/rnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ def __init__(
The fraction of neurons that are dropped in all-but-last RNN layers.
**kwargs
all parameters required for :class:`darts.model.forecasting_models.PLForecastingModule` base class.

Inputs
------
x of shape `(batch_size, input_length, input_size)`
Tensor containing the features of the input sequence. The `input_length` is not fixed.

Outputs
-------
y of shape `(batch_size, output_chunk_length, target_size, nr_params)`
Tensor containing the outputs of the RNN at every time step of the input sequence.
During training the whole tensor is used as output, whereas during prediction we only use y[:, -1, :].
However, this module always returns the whole Tensor.
"""
# RNNModule doesn't really need input and output_chunk_length for PLModule
super().__init__(**kwargs)
Expand All @@ -92,6 +80,25 @@ def __init__(
def forward(
self, x_in: Tuple, h: Optional[torch.Tensor] = None
) -> Tuple[torch.Tensor, torch.Tensor]:
"""RNN Module forward.

Parameters
----------
x_in
Tuple of Tensors containing the features of the input sequence. The tuple has elements (past target,
historic future covariates, future covariates, static covariates). The shape of the past target is
`(batch_size, input_length, input_size)`.
h
Optionally, the hidden state.

Returns
-------
Tuple[torch.Tensor, torch.Tensor]
Tuple of Tensors with elements (RNN output, hidden state). The RNN output Tensor has shape
`(batch_size, output_chunk_length, target_size, nr_params)`. It contains the outputs at every
time step of the input sequence. During training the whole tensor is used as output, whereas during
prediction we only use y[:, -1, :]. However, this module always returns the whole Tensor.
"""
pass

def _produce_train_output(self, input_batch: Tuple) -> torch.Tensor:
Expand Down
2 changes: 2 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
USERGUIDEDIR = userguide
GENAPIDIR = generated_api
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
Expand Down Expand Up @@ -50,6 +51,7 @@ generate-userguide:
generate-api:
@echo "[Makefile] generating API using sphinx-apidoc..."
@sphinx-apidoc -e -f --templatedir templates -o "$(SOURCEDIR)/generated_api" ../darts ../darts/logging.py ../darts/tests/*
@cp -r $(GENAPIDIR)/*.rst "$(SOURCEDIR)/generated_api/"

html:
# Note: this target has to be called "html" because its name is given as an argument to Sphinx
Expand Down
10 changes: 10 additions & 0 deletions docs/generated_api/darts.models.forecasting.block_rnn_model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Block Recurrent Neural Networks
-------------------------------

.. autoclass:: darts.models.forecasting.block_rnn_model.BlockRNNModel
:members:
:exclude-members:

.. autoclass:: darts.models.forecasting.block_rnn_model.CustomBlockRNNModule
:members:
:no-inherited-members:
10 changes: 10 additions & 0 deletions docs/generated_api/darts.models.forecasting.rnn_model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Recurrent Neural Networks
-------------------------

.. autoclass:: darts.models.forecasting.rnn_model.RNNModel
:members:
:exclude-members:

.. autoclass:: darts.models.forecasting.rnn_model.CustomRNNModule
:members:
:no-inherited-members:
1 change: 0 additions & 1 deletion docs/templates/module.rst_t
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.. automodule:: {{ qualname }}
:members:
:undoc-members: