--- pipeline_tag: time-series-forecasting library_name: pytorch license: mit tags: - time-series - forecasting - model-stitching - modular-deep-learning - continual-learning --- # STITCH **STITCH** (Shortest-path Transplantation of Interchangeable Time-series blocks with Calibrated Hedging) keeps a forecaster accurate on a drifting stream. When drift is detected, it rebuilds the served network from block segments of other pretrained models by a shortest-path search over a segment graph, fine-tunes the stitched network, and hedges it against the previous one. This repository hosts the **pretrained block pool** that STITCH searches over: **435 forecasting models** whose residual blocks share one interface, so that any block can be transplanted into any other model of the same shape. The source code is in the [GitHub repository](https://github.com/LeonStandford/STITCH). ## Model Details - **Architectures:** MLP (2.1M parameters), LSTM (2.5M), Attention (2.5M). - **Blocks:** 6 residual blocks per model on a shared 512-step stream, patch length 16, hidden size 64, 3 layers per block, linear head. - **Channel handling:** channel-independent, one variate per forward pass. - **Context lengths:** 64, 128, 256, 512, 1024, 2048. - **Horizons:** 96, 192, 336, 720. - **Training:** each model is trained on the train split of its own dataset only, then fine-tuned with MAE loss (20 epochs, early stopping with patience 3, learning rate 1e-4, batch size 256). - **Inference:** PyTorch on CPU or GPU. ## Pool Contents | Folder | Datasets | Architectures | Contexts | Horizons | Models | |---|---|---|---|---|---| | [`ett-weather/`](https://huggingface.co/leonpham1208/stitch/tree/main/ett-weather) | ETTh1, ETTh2, ETTm1, ETTm2, Weather | MLP, LSTM, Attention | 64 to 2048 | 96 to 720 | 360 | | [`time-mmd/`](https://huggingface.co/leonpham1208/stitch/tree/main/time-mmd) | Economy, Energy, Security, SocialGood, Traffic | MLP, LSTM, Attention | 64, 128 | 96 | 75 | Each `time-mmd/` model starts from one of the `ett-weather/` models and is adapted on the train split of one Time-MMD domain (up to 100 epochs, early stopping with patience 10, learning rate 1e-4, batch size 32). Every model folder is named `forecasting---c-h-p6` and holds: - `model.pt`: the state dict. - `record.json`: dataset, architecture, context, horizon, block settings and validation loss. ## Benchmarks MSE of the full STITCH system built on this pool, against published numbers (†). ETT/Weather is averaged over the horizons 96, 192, 336 and 720, Time-MMD over the horizons of ScenarioDiff. Each dataset is tested on its own test split. ### ETT and Weather, inference-time setting | Dataset | TimeBlocks† | **STITCH** | |---|---|---| | ETTh1 | 0.416 | **0.410** | | ETTh2 | **0.338** | 0.346 | | ETTm1 | 0.344 | **0.334** | | ETTm2 | **0.242** | 0.249 | | Weather | 0.220 | **0.219** | ### Time-MMD | Domain | ScenarioDiff† | **STITCH** | |---|---|---| | Economy | 0.216 | **0.193** | | Energy | 0.225 | **0.202** | | Security | 74.80 | **69.40** | | SocialGood | 1.313 | **0.731** | | Traffic | 0.099 | **0.032** | ## Usage ### Install ```bash git clone https://github.com/LeonStandford/STITCH.git && cd STITCH pip install -r requirements.txt # Python 3.10, PyTorch 2.3.1 ``` ### Load a pretrained model ```python from pathlib import Path import torch from huggingface_hub import snapshot_download from src.data.classes.settings import BackboneSettings from src.services.blockbase import load_backbone root = Path("weights") snapshot_download( repo_id="leonpham1208/stitch", allow_patterns=["ett-weather/forecasting-ETTh1-lstm-c512-h96-p6/*"], local_dir=root / "blockbase", ) model = load_backbone( settings=BackboneSettings( blockbase_name="ett-weather", source_dataset="ETTh1", architecture="lstm", context_length=512, horizon=96, ), weights_root=root, ) context = torch.randn(4, 512, 1) forecast = model(x=context) ``` `forecast` has shape `(4, 96, 1)`. Download the whole pool with `snapshot_download(repo_id="leonpham1208/stitch", local_dir="weights/blockbase")` to run STITCH itself, following the [GitHub repository](https://github.com/LeonStandford/STITCH). ## Additional Resources - [GitHub repository](https://github.com/LeonStandford/STITCH) - Paper: coming soon. ## License The models are released under the MIT license.