{ "cells": [ { "cell_type": "markdown", "id": "da55dd6c", "metadata": {}, "source": [ "# Fine-Tuning PyTorch Models and Foundation Models\n", "\n", "This example notebook demonstrates how to train, save, load, and fine-tune PyTorch-based models in Darts. We cover two scenarios:\n", "\n", "- [**Regular PyTorch Models**](#1.-Regular-TorchForecastingModel:-Training-and-Fine-Tuning) (e.g., TiDE, N-BEATS, DLinear):\n", " - **(Pre-)Training** a model from scratch.\n", " - **Saving and loading** the model.\n", " - **Fine-tuning** the loaded model (updating weights on new data).\n", "\n", "- [**Foundation Models**](#2.-Foundation-Model:-Zero-Shot-Forecasting-and-Fine-Tuning) (e.g., Chronos 2, TimesFM 2.5):\n", " - **Zero-shot inference** for forecasting without any training.\n", " - **Fine-tuning** the foundation model." ] }, { "cell_type": "code", "execution_count": 1, "id": "bfa59f65", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "310fa52a", "metadata": {}, "outputs": [], "source": [ "# fix python path if working locally\n", "from utils import fix_pythonpath_if_working_locally\n", "\n", "fix_pythonpath_if_working_locally()\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 3, "id": "d510b54b", "metadata": {}, "outputs": [], "source": [ "import logging\n", "import os\n", "import warnings\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "from darts import set_option\n", "from darts.datasets import AirPassengersDataset, AusBeerDataset\n", "from darts.metrics import mae\n", "from darts.models import Chronos2Model, TiDEModel\n", "from darts.utils.callbacks import TFMProgressBar\n", "\n", "warnings.filterwarnings(\"ignore\")\n", "logging.disable(logging.CRITICAL)\n", "set_option(\"plotting.use_darts_style\", True)" ] }, { "cell_type": "markdown", "id": "6b82a07a", "metadata": {}, "source": [ "## Data Preparation\n", "\n", "For demonstration, we'll just load two short time series: The Air Passengers and Australian Beer Production datasets.\n", "We will pre-train a model only on the Air Passengers series and then fine-tune it on the Beer Production dataset. \n", "We also create training, evaluation and test sets for illustration.\n", "\n", "