P Layer (Package)#
Try the API v2 pre-release!
The Package layer (denoted by the _pkg suffix) is a private, internal structural component of the v1 architecture. It serves as a centralized container for model metadata, capability tags, dependency management, and testing fixtures.
If you are a standard user building forecasting models, you will typically interact directly with the core models (e.g., NBeats.from_dataset()) and bypass this layer entirely. However, if you are contributing a new model to the PyTorch Forecasting library, you must implement a corresponding Package class (see the extension templates here for more info on how to implement this class).
Responsibilities of a v1 Package#
A v1 Package class inherits from _BasePtForecaster and is strictly responsible for managing the model’s ecosystem integration:
Model Linkage (
get_cls): It acts as a lazy-loading proxy that returns the actual PyTorch Lightning model class without triggering heavy imports across the framework.Metadata & Capability Tags (
_tags): A comprehensive dictionary defining the model’s structural profile. This includes the target data types, supported prediction types (e.g.,point,quantile), exogenous variable support, multivariate capabilities, computational intensity, and author attribution. These tags dynamically populate the model overview tables and to understand the properties of the models.Dependency Management: Through the
python_dependenciestag, the package container declares any specific external packages required by the model, allowing the framework to manage optional imports gracefully.Testing Fixtures: Methods like
get_base_test_params()and_get_test_dataloaders_from()generate standard, valid configurations and train/validation dataloaders. These ensure the model can be seamlessly validated within the Continuous Integration (CI) pipeline.
Anatomy of a v1 Package#
By convention, the package container must be a private file (e.g., _nbeats_pkg.py) and its class name must exactly match the model name with a _pkg suffix (e.g., NBeats_pkg).
Below is the auto-generated documentation for the NBeats package. To see exactly how the tags and testing fixtures are implemented in the code, click the [source] button next to the class name:
- class pytorch_forecasting.models.nbeats._nbeats_pkg.NBeats_pkg[source]
Bases:
_BasePtForecasterNBeats package container.
Construct BaseObject.
- classmethod get_base_test_params()[source]
Return testing parameter settings for the trainer.
- Returns:
params – Parameters to create testing instances of the class Each dict are parameters to construct an “interesting” test instance, i.e., MyClass(**params) or MyClass(**params[i]) creates a valid test instance. create_test_instance uses the first (or only) dictionary in params
- Return type:
dict or list of dict, default = {}
- classmethod get_cls()[source]
Get model class.
API Reference#
See the detailed API documentation for the V1 Package classes below:
DeepAR package container. |
|
DecoderMLP package container. |
|
NBeats package container. |
|
NBeatsKAN package container. |
|
NHiTS package container. |
|
RecurrentNetwork package container. |
|
|
TemporalFusionTransformer package container. |
Package container for TiDE Model. |