forecasting-models
Select, instantiate, train, checkpoint, predict, and interpret PyTorch Forecasting v1 model families from TimeSeriesDataSet datasets.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- forecasting-models
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Select, instantiate, train, checkpoint, predict, and interpret PyTorch Forecasting v1 model families from TimeSeriesDataSet datasets.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/model-selection.md9.5 KB
- 参考文档references/model-troubleshooting.md10.3 KB
- 参考文档references/training-prediction-workflows.md13.3 KB
- 脚本scripts/tiny_forecasting_smoke.py8.7 KB
03 SKILL.md 正文
Forecasting Models Sub-skill
Use this sub-skill when a PyTorch Forecasting 1.8.0 task already has, or is ready to build, v1 TimeSeriesDataSet train/validation/prediction objects and needs to choose a model family, instantiate it with .from_dataset(), run Lightning training, load a checkpoint, call predict(), or interpret model outputs.
Route here for
- Choosing among
Baseline,TemporalFusionTransformer,NBeats,NBeatsKAN,NHiTS,DeepAR,RecurrentNetwork,DecoderMLP,TiDEModel,TimeXer, andxLSTMTimefor a concrete forecasting task. - Using
.from_dataset(training_dataset, ...)to transferTimeSeriesDataSetmetadata into a v1 model. - Creating
lightning.pytorch.Trainerobjects with early stopping, learning-rate monitoring, CPU/GPU settings, debugging batch limits, checkpointing, and fast prediction. - Calling
BaseModel.predict()orDeepAR.predict()withreturn_index,return_decoder_lengths,return_x,return_y,mode,mode_kwargs,n_samples, andtrainer_kwargs. - Loading trained models with
ModelClass.load_from_checkpoint()and using model-specific interpretation or plotting helpers when optional plotting packages are available.
Route away
- Data schema design,
TimeSeriesDataSetconstruction, encoders, normalizers, missing timesteps, dataloaders, and dataset serialization belong in../data-pipeline/SKILL.md. - Loss choice, metric semantics, quantile/distribution details, Optuna tuning, and full learning-rate finder strategy belong in
../metrics-and-tuning/SKILL.md. - Experimental v2 package/data-module workflows, including the v2-only
SOFTSlayer, belong in../api-v2-workflows/SKILL.md.
Bundled references and scripts
- Use
references/model-selection.mdwhen deciding which model family matches target-only, covariate-rich, probabilistic, multivariate, long-horizon, or fixed-window requirements. - Use
references/training-prediction-workflows.mdfor concrete v1.from_dataset(),Trainer.fit(), checkpoint,predict(), and interpretation recipes. - Use
references/model-troubleshooting.mdwhen training freezes, diverges, LR finder stalls, plotting/logging fails, or a dataset/model compatibility assertion appears. - Use
scripts/tiny_forecasting_smoke.pyto run a dependency-light CPU smoke check that builds tiny pandas data, creates aTimeSeriesDataSet, and performs a defaultBaselineprediction without long training.
Minimal operating pattern
import lightning.pytorch as pl
from lightning.pytorch.callbacks import EarlyStopping, LearningRateMonitor
from pytorch_forecasting import TemporalFusionTransformer
from pytorch_forecasting.metrics import QuantileLoss
# `training`, `validation`, `train_loader`, and `val_loader` come from the data-pipeline sub-skill.
model = TemporalFusionTransformer.from_dataset(
training,
learning_rate=0.03,
hidden_size=16,
attention_head_size=1,
dropout=0.1,
hidden_continuous_size=8,
output_size=7, # 7 default quantiles for QuantileLoss()
loss=QuantileLoss(),
log_interval=-1, # avoid plotting/logging overhead while debugging
reduce_on_plateau_patience=4,
)
callbacks = [
EarlyStopping(monitor="val_loss", min_delta=1e-4, patience=5, mode="min"),
LearningRateMonitor(),
]
trainer = pl.Trainer(
max_epochs=20,
accelerator="auto",
devices="auto",
gradient_clip_val=0.1,
callbacks=callbacks,
enable_checkpointing=True,
)
trainer.fit(model, train_dataloaders=train_loader, val_dataloaders=val_loader)
best_path = trainer.checkpoint_callback.best_model_path
loaded = TemporalFusionTransformer.load_from_checkpoint(best_path)
preds = loaded.predict(
val_loader,
return_index=True,
return_decoder_lengths=True,
return_x=True,
return_y=True,
trainer_kwargs={"accelerator": "cpu"},
)
Safety and verification checklist
- Confirm the dataset shape and column roles in
../data-pipeline/SKILL.mdbefore blaming the model. - Start with
Baseline().predict(...)or the bundled smoke script to prove the installed package, dataloader, Lightning, pandas, torch, and CPU path work. - For neural models, instantiate with
.from_dataset()instead of manually copying feature-cardinality metadata. - Keep
num_workers=0,accelerator="cpu",limit_train_batches=1,limit_val_batches=1, and tiny model sizes while debugging. - Use
model.size()before training; unexpectedly huge parameter counts usually indicate an oversized architecture or too many high-cardinality categorical embeddings. - Treat v2-only or package-layer APIs as out of scope for this v1 model workflow unless the task explicitly routes to
../api-v2-workflows/SKILL.md.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).