Phi-Mamba: Adaptive Delay and Retrieval-Augmented State Space Models for Edge Time-Series Forecasting
Release version: v1.0 — This tag corresponds to the reference metrics and tables bundled under paper/tables/source/ and the minimal sample figures in artifacts/paper/.
Phi-Mamba is a research codebase for edge-oriented multivariate time-series forecasting. It implements a Phi-Mamba forecaster (adaptive delay, retrieval-augmented memory, gated fusion, Mamba-style backbone) alongside LSTM, Transformer, and Mamba baselines. The Python package name is phimamba (import path); the method and paper use the hyphenated name Phi-Mamba.
Naming: Use Phi-Mamba in prose and citations; use phimamba / PhiMamba in code and class names.
- Adaptive delay modeling — learnable temporal filtering before the sequence backbone.
- Retrieval-augmented temporal memory — attention-style readout over a bounded memory of past patterns.
- Efficient edge deployment — configs and scripts for latency/memory benchmarks on CPU-oriented setups.
Numbers below come from the bundled tables in paper/tables/source/final_results.csv (regenerate anytime with scripts/generate_paper_figures.py).
| Model | Test MSE | Avg latency (ms) |
|---|---|---|
| Transformer (best MSE here) | 0.703 | 15.0 |
| Mamba | 0.805 | 128.8 |
| LSTM | 0.823 | 27.4 |
| Phi-Mamba (Final) | 1.186 | 146.3 |
- Phi-Mamba (Final) vs Mamba: MSE 1.186 vs 0.805 on this snapshot (+47.4% relative MSE vs. Mamba; lower is better).
- Latency: Phi-Mamba (Final) 146.3 ms vs Mamba 128.8 ms (+13.6% slower in this run).
Your own training may differ; see Reproducing results below.
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtInstall PyTorch for your platform from pytorch.org if you need a specific CUDA or MPS build.
From the repository root, with PYTHONPATH set by running scripts (they prepend src/ automatically).
Place ETTh1 (or your dataset) where the dataset config expects it. Default config: configs/dataset/ett.yaml (paths under data/raw/).
python3 scripts/download_data.py
# or copy ETTh1.csv to data/raw/ett/ per configs/dataset/ett.yamlpython3 scripts/train.py \
--dataset-config configs/dataset/ett.yaml \
--model-config configs/model/mamba.yaml \
--training-config configs/training/default.yaml \
--device cpupython3 scripts/train_g_safe_gated.py \
--dataset-config configs/dataset/ett.yaml \
--experiment-config configs/experiment/production_ablation.yaml \
--device cpupython3 scripts/run_ablation.py \
--dataset-config configs/dataset/ett.yaml \
--experiment-config configs/experiment/ablation_phi_mamba.yaml \
--device cpuTrain checkpoints only (no CSV/plots):
python3 scripts/run_ablation.py --train-checkpoints-only --device cpupython3 scripts/run_robustness.py \
--dataset-config configs/dataset/ett.yaml \
--experiment-config configs/experiment/robustness_phi_mamba.yaml \
--lstm --transformer \
--device cpupython3 scripts/run_edge_benchmark.py \
--dataset-config configs/dataset/ett.yaml \
--experiment-config configs/experiment/edge_benchmark.yamlpython3 scripts/generate_paper_figures.pyOutputs: paper/tables/ (CSV + LaTeX + summary text), paper/figures/ (all plots), and a minimal copy under artifacts/paper/ for the public repo sample.
| Path | Role |
|---|---|
src/phimamba/ |
Library: data, models, training, evaluation, experiments |
configs/ |
YAML: datasets, models, training, experiments |
scripts/ |
CLI entrypoints |
tests/ |
Pytest tests |
paper/ |
Draft materials: draft.md, paper.tex, tables/, figures/ |
paper/tables/source/ |
Bundled reference CSVs for v1.0 figures |
artifacts/ |
Local outputs (checkpoints, plots); mostly gitignored |
- Dataset: Use the same split and preprocessing as
configs/dataset/ett.yaml(ETTh1, window length / horizon as specified). - Configs: Training hyperparameters live under
configs/training/andconfigs/experiment/*.yaml. Production-style ablation:configs/experiment/production_ablation.yaml. - Order of operations (typical):
- Download or place raw data.
- Run
scripts/train.py(or variants) to populateartifacts/checkpoints/. - Run
scripts/run_final_summary.py,scripts/run_ablation.py,scripts/run_robustness.py,scripts/run_edge_benchmark.pyas needed (many modes expect existing checkpoints — see each script’s--help).
- Expected outputs: Metrics CSVs under
artifacts/results/, plots underartifacts/plots/, checkpoints underartifacts/checkpoints/. - Paper bundle: Run
python3 scripts/generate_paper_figures.pyto refreshpaper/tables/andpaper/figures/frompaper/tables/source/(or fromartifacts/results/if source files are missing).
Evaluates LSTM, Transformer, Mamba, and Phi-Mamba (G) on ETT with strong regime shift, synthetic variable delay on test inputs, and a short forex-like synthetic fine-tune (see each script’s --help). Requires trained weights under artifacts/checkpoints/ (same layout as scripts/run_robustness.py).
python3 scripts/run_strong_regime_shift.py --device cpu
python3 scripts/run_synthetic_delay.py --device cpu
python3 scripts/run_forex_like.py --device cpu
python3 scripts/generate_paper_figures.py # copies delay plots + delay_benchmark_summary.csv- Draft:
paper/draft.md(Markdown) andpaper/paper.tex(LaTeX stub). - Citation: See
CITATION.cff(GitHub reads this for the “Cite this repository” widget). Replace the placeholder DOI and repository URL when the paper and archive record are public. - Paper PDF / venue: To appear — link will be added here:
https://doi.org/10.0000/PLACEHOLDER
pip install pytest
pytestpyproject.toml sets pythonpath = ["src"] so imports resolve without a manual PYTHONPATH.
MIT — see LICENSE.