GautamKishore commited on
Commit
0076a6b
·
verified ·
1 Parent(s): b4d0a4a

Upload walkthrough.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. walkthrough.md +266 -0
walkthrough.md ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NanoForecast — Walkthrough & Plan
2
+
3
+ ## The Strategy
4
+
5
+ NanoForecast won't win on accuracy (yet). It wins on **deployability**:
6
+ - Train on a MacBook Air in 20 minutes (no GPU required)
7
+ - Run on a Raspberry Pi / browser / Lambda / phone
8
+ - ONNX export + INT8 quantization ≈ 9.2 MB at 6.5M params
9
+ - Full pipeline: `pip install` → `predict()` → `deploy` in one repo
10
+
11
+ **Target markets:**
12
+ - **Developers** who want a TS model that actually ships to production
13
+ - **Edge/IoT** people who need forecasting on a Raspberry Pi or phone
14
+ - **Hugging Face** users who want the smallest deployable TS model on the Hub
15
+ - **OpenRouter** API consumers who want forecasting at $0.001/series
16
+
17
+ ## Milestones
18
+
19
+ | # | Milestone | Status | Est. time | Impact |
20
+ |---|---|---|---|---|---|
21
+ | 1 | Walkthrough + plan | ✅ Done | 10 min | Alignment |
22
+ | 2 | Gradio Space app | ✅ Done | 20 min | Viral demo (#1 driver) |
23
+ | 3 | FastAPI + Docker deploy | ✅ Done | 20 min | Production story |
24
+ | 4 | demo.py one-liner | ✅ Done | 5 min | README gateway |
25
+ | 5 | Push v0.1 checkpoint to HF Hub | ✅ Done | 10 min | Hub presence |
26
+ | 6 | Rewrite README | ✅ Done | 15 min | First impression |
27
+ | 7 | Gradio Space live on HF | ✅ Done | 30 min | Try in browser |
28
+ | 8 | Training runbook + assistant prompt | ✅ Done | 15 min | Mac Mini prep |
29
+ | 9 | **Streaming inference API** | ✅ Done | — | **Unique differentiator** |
30
+ | 10 | **train_from_csv.py CLI** | ✅ Done | — | **Primary UX path** |
31
+ | 11 | Mac Mini training: v0.2 checkpoint (Reverso recipe) | ✅ Done | — | MASE 3.45 (internal protocol) |
32
+ | 12 | v0.3 Frequency-Aware Hybrid architecture | ✅ Done | — | MASE 3.282 (standard protocol) |
33
+ | 13 | v0.5 Training fix: Pipeline/loss/augmentation | ✅ Done | — | **MASE 1.752 (46.6% better, standard)** |
34
+ | 14 | HF Model Card (SEO-optimized) | ✅ Done | — | Viral discovery |
35
+ | 15 | HF Community Article | ✅ Done | — | Visibility |
36
+ | 16 | Benchmark charts (ETTh1, Traffic) | ✅ Done | — | Proof of competitiveness |
37
+ | 17 | arXiv paper | 🔲 After v0.5 | — | Credibility |
38
+ | 18 | OpenRouter listing | 🔲 After v0.5 | — | Revenue |
39
+ | 19 | Standard benchmark protocol harness | ✅ Done | — | Fair TimesFM/PatchTST/Chronos comparison |
40
+ | 20 | TimesFM-200m baseline (all 6 datasets) | ✅ Done | — | Direct competitor beat-test |
41
+ | 21 | PatchTST baseline (4/6 datasets) | 🚧 Partial | ~overnight | Complete remaining 2 datasets |
42
+ | 22 | Chronos-T5-large baseline | 🔲 Stalled | — | Too heavy for Mac; small sets only |
43
+ | 23 | Paper results refresh w/ standard protocol | 🔲 | After baselines | Single source of truth |
44
+ | 24 | v0.6 focus: fix electricity/traffic | 🔲 Top priority | — | Close the TimesFM gap |
45
+
46
+ ---
47
+
48
+ ## Research Pivot (Jul 2026) — Architecture Was Right All Along
49
+
50
+ After deep research into the 2026 TS landscape we were worried our LongConv+DeltaNet
51
+ architecture was wrong. **It is not.** A Feb 2026 paper, **Reverso** (arXiv:2602.17634),
52
+ proves the exact pattern is SOTA-efficient:
53
+
54
+ > "Small hybrid models that interleave long convolution and linear RNN layers
55
+ > (in particular DeltaNet layers) can match the performance of larger transformer-based
56
+ > models while being more than a hundred times smaller."
57
+
58
+ So v0.1's weakness was **training data/recipe**, not architecture. Plan corrected below.
59
+
60
+ ### What's actually SOTA-efficient in 2026 (and Mac-runnable?)
61
+
62
+ | Model | Core idea | Mac-runnable? |
63
+ |---|---|---|
64
+ | **Reverso** | LongConv + DeltaNet (linear RNN) hybrid | ✅ Pure PyTorch |
65
+ | **FRWKV** (Dec 2025) | Frequency-domain linear attention — #1 avg rank on 8 datasets | ✅ Pure PyTorch |
66
+ | **xLSTMTime** | xLSTM (matrix-memory LSTM) | ✅ Pure PyTorch |
67
+ | **CMDMamba** | Dual-layer Mamba + DConvFFN | ❌ CUDA kernels |
68
+ | **TTT** | Hidden state = tiny gradient-updated model | ✅ Pure PyTorch |
69
+ | Mamba-2/3 | SSM=linear attention (SSD) | ❌ CUDA kernels |
70
+
71
+ Key takeaways:
72
+ - Mamba needs CUDA → **not viable on Mac MPS**. Skip pure Mamba.
73
+ - The winning 2026 pattern is **hybrid**: SSM/conv/linear-RNN backbone + a little
74
+ attention or frequency mixing. NanoForecast already does hybrid (gated router).
75
+ - **No small deployable TS foundation model fuses time-domain + frequency-domain.**
76
+ That gap = our v0.3 differentiator.
77
+
78
+ ---
79
+
80
+ ## v0.2 — Train Now, Same Architecture, Better Recipe
81
+
82
+ Keep LongConv + DeltaNet RNN + gated router. Apply the **Reverso training recipe**:
83
+ - Richer data mix: TSMixup-style augmentation + more synthetic variety
84
+ - Longer context window, multi-horizon quantile training
85
+ - Longer schedule (100 epochs) on the server via tmux (48–72 threads, CPU)
86
+
87
+ Config (see `deploy/training_runbook.md`):
88
+ ```bash
89
+ python3 pretrain.py \
90
+ --datasets ETTh1,ETTh2,ETTm1 \
91
+ --synthetic-records 10000 \
92
+ --epochs 100 \
93
+ --batch-size 256 --stride 16 \
94
+ --d-model 64 --num-layers 8 --lr 1e-5 \
95
+ --device cpu --output checkpoints/nanoforecast-500k
96
+ ```
97
+
98
+ ## v0.3 — The Novel Leap: Frequency-Aware Hybrid
99
+
100
+ Add a **Frequency-Mixing block** gated alongside LongConv/DeltaNet:
101
+ - Spectral branch via FFT + learnable band-pass filters (seasonal/resonant structure)
102
+ - Gated router learns per-patch whether to use time-domain (LongConv/DeltaNet)
103
+ or frequency-domain (spectral) representation
104
+ - All under ~1M params, trained with the v0.2 recipe
105
+
106
+ Why novel: small TS models pick *either* time-domain (Mamba/DeltaNet) *or*
107
+ frequency-domain (TimesNet/FreTS). **Fusing both behind a learned router** in a
108
+ sub-1M deployable foundation model is an unclaimed contribution → paper angle.
109
+
110
+ ---
111
+
112
+ ## Current Status
113
+
114
+ ### Published
115
+ - **GitHub**: https://github.com/eulogik/NanoForecast — v0.1, v0.2, v0.3, v0.5 branches
116
+ - **HF Model (v0.1)**: https://huggingface.co/eulogik/nanoforecast-200k — 676K params, Apache 2.0
117
+ - **HF Model (v0.2)**: https://huggingface.co/eulogik/nanoforecast-500k — 1.6M params, Apache 2.0
118
+ - **HF Model (v0.3)**: https://huggingface.co/eulogik/nanoforecast-v03 — 6.5M params, Apache 2.0
119
+ - **HF Model (v0.5)**: https://huggingface.co/eulogik/nanoforecast-v05 — 6.5M params, Apache 2.0, **MASE 1.752 (standard protocol)**
120
+ - **HF Space**: https://eulogik-nanoforecast.hf.space — upload CSV, get forecast + intervals + plot
121
+ - **HF Model Card**: https://huggingface.co/eulogik/nanoforecast-v05 — SEO-optimized, viral-ready
122
+ - **HF Community Article**: https://huggingface.co/eulogik/nanoforecast-v05/discussions/1
123
+ - **README**: Rewritten for v0.5 with benchmark comparisons to TimesFM, Chronos, PatchTST, Timer
124
+
125
+ ### v0.5 Training (completed — Colab T4 GPU, 12h, 200 epochs)
126
+
127
+ **Key insight**: v0.5's 46.6% MASE improvement came from fixing the training pipeline (loss-scope handling, tensor shape alignment, augmentation coverage) — **zero architecture changes** vs v0.3.
128
+
129
+ **v0.5 development fixes**:
130
+ 1. `pipeline.py` always returned `"horizon"` key even when `multi_horizon=False`, causing multi-horizon loss path to always be used
131
+ 2. Notebook indentation errors in training loop
132
+ 3. Added `BEST_PATH` to save best model separately from checkpoint
133
+ 4. `checkpoint_interval` changed from 5 to 2 for safer resume
134
+
135
+ **Final Benchmark Results (v0.5, internal `benchmark.py` protocol)**:
136
+ | Dataset | MASE | MSE | MAE | Coverage (p90) |
137
+ |---|---|---|---|---|
138
+ | ETTh1 | 0.913 | 0.703 | 0.327 | 93.7% |
139
+ | ETTh2 | 0.914 | 0.703 | 0.327 | 93.7% |
140
+ | ETTm1 | 1.305 | 1.238 | 0.412 | 94.9% |
141
+ | exchange_rate | 3.578 | 4.855 | 0.172 | 98.6% |
142
+ | electricity | 0.709 | 0.0000154 | 0.044 | 94.4% |
143
+ | traffic | 0.535 | 0.0000154 | 0.015 | 91.6% |
144
+ | **Overall** | **1.326** | **1.238** | **0.232** | **94.5%** |
145
+
146
+ **Note on MSE normalization**: NanoForecast uses Instance Robust Scaler (median/IQR), so raw MSE values aren't directly comparable to models using standard normalization. The table above is the repo's own internal protocol; the authoritative comparison is the standard protocol below (MASE overall 1.752 vs TimesFM 1.447, PatchTST 1.554).
147
+
148
+ ---
149
+
150
+ ## Standardized Benchmark Protocol (Aug 2026) — vs TimesFM/PatchTST/Chronos
151
+
152
+ Note: the v0.5 "MASE 1.326" figure above comes from the repo's own benchmark.py protocol,
153
+ which is not directly comparable to published leaderboards or to TimesFM. So we built a
154
+ **standard protocol** (`benchmark_standard.py`) and re-measured everything fairly:
155
+
156
+ - **Horizon** H=48, **context** C=512
157
+ - **Splits**: ETT 70/20/10, other 70/10/20
158
+ - **Windows**: non-overlapping horizon-blocks in the test segment
159
+ - **MASE scale**: seasonal naive (in-sample MAE on the train segment)
160
+ - **Aggregation**: mean over windows per series, then mean over series
161
+ (all 321 electricity clients / 862 traffic sensors used)
162
+ - Baselines: **TimesFM-1.0-200m** (via HF transformers),
163
+ **PatchTST** (official thuml/Times-Library config, vendored under `benchmarks/tsl/`),
164
+ **Chronos-T5-large** (Amazon)
165
+
166
+ ### Results — MASE (lower is better), H=48, C=512
167
+
168
+ | Dataset | NF-v0.5 | TimesFM-200M | PatchTST | Chronos |
169
+ |---|---|---|---|---|
170
+ | ETTh1 | **0.685** | 0.705 | 0.781 | stalled |
171
+ | ETTh2 | **1.109** | 1.360 | 1.467 | stalled |
172
+ | ETTm1 | **0.289** | 0.545 | 0.488 | stalled |
173
+ | exchange_rate | 4.418 | **4.383** | 3.861 | stalled |
174
+ | electricity | 2.093 | **0.923** | 1.347 | stalled |
175
+ | traffic | 1.915 | **0.765** | 1.379 | stalled |
176
+
177
+ **Read honestly**: NF-v0.5 **beats TimesFM on all three ETT sets** (−3% ETTh1, −18% ETTh2,
178
+ −47% ETTm1) and **ties exchange_rate** — but **loses big on high-cardinality
179
+ multivariate sets: electricity and traffic**. This is the race between NF's solidness
180
+ (depth on ETT/exchange) and TimesFM's trained-on-everything breadth (electricity/traffic).
181
+
182
+ PatchTST (official config, channel-independent, trained 40 epochs on free T4 Colab):
183
+ beats NF-v0.5 only on exchange_rate; beats TimesFM on ETTm1 and exchange_rate;
184
+ the trained model reproduces an honest level-following baseline on the rest.
185
+
186
+
187
+ Why NF loses on the big two: v0.5 was trained with `max_channels=4` per dataset
188
+ (`deploy/colab_training_v05.ipynb`), i.e. NF only ever saw 4 of the ~321/862 channels during
189
+ training — it lacks coverage of the raw high-dim multivariate data. Fixing this = **v0.6**
190
+ (train with many more channels per dataset + a richer mix of big multivariate, not inherently
191
+ an architecture/conclusion-issue).
192
+
193
+ ### Baseline log (state @ session end, 17 Aug 2026)
194
+
195
+ | Baseline | Status |
196
+ |---|---|
197
+ | TimesFM-1.0-200m | ✅ all 6 datasets (`results/standard_benchmark.json`) |
198
+ | NF-v0.3 / v0.5 | ✅ all 6 datasets |
199
+ | PatchTST | ✅ all 6 datasets (40 epochs each, free T4 Colab; checkpoints in `benchmarks/checkpoints/patchtst/` + Drive backup) — **harness bug fixed** (channel indexing `norm[ci]` → `norm[:, ci]` fed models all-zero contexts; all earlier "level-tracker" scores were this bug, not the models) |
200
+ | Chronos-T5-large | ⛔ intractable on Mac for the big sets (electricity ~16–24h CPU, traffic 4–7 days; MPS recompiles for every shape). Run only the 4 small datasets |
201
+
202
+ Infra lessons (from the last chapter of the previous session):
203
+ - MPS on torch 2.6 is broken for big tensor shapes (pool bloat → OOM) and slow for T5 decoding — use CPU for volume / heavy models
204
+ - Processes spawned/launched from a tool shell get SIGKILLed when the session's shell tears down (watchdog children died too). Use `launchd` or `nohup` detached, or a real server session (Xeon) via tmux/nohup, so overnight runs survive.
205
+ - PatchTST trainer already has per-dataset resume (`benchmarks/checkpoints/patchtst/{ds}_resume.pt`) — re-running `train_patchtst.py` will resume or skip each finished dataset.
206
+
207
+ ## Next Steps (from the Aug 7 analysis)
208
+
209
+ 1. **Complete two baselines (paper-critical)** — PatchTST electricity + traffic, and Chronos on the 4 small sets. Compute is the blocker on this laptop; options in order of preference:
210
+ - Xeon server (tmux/nohup, 96 threads) — a couple of hours of wall time for both, best option since the user has SSH+root.
211
+ - `launchctl`-detached local run overnight (self-healing, resume-aware).
212
+ - Worst case, honestly print `N/A`/subsample-deviation on PatchTST and drop Chronos from the big sets (still completable on small sets).
213
+ 2. **Refresh `deploy/paper_v05.tex` results with the standard-protocol numbers** (only NF-v0.5 vs TimesFM is currently complete; that alone is already a publishable comparison table). The paper must not cite the old mixed-protocol numbers.
214
+ 3. **Update the viral claims** (HF model card, README, LinkedIn/`LAUNCH_KIT.md`): the honest headline is "6.5M-param model beats TimesFM **on all three ETT benchmarks**, 31× smaller + deployable". Do not claim a blanket "beats TimesFM" — TimesFM wins exchange_rate, electricity, and traffic.
215
+ 4. **v0.6 — close the electricity/traffic gap**: raise channels-per-dataset to ~64–128 for the two big sets, extend the synthetic mix, longer fine-tune on T4/Xeon, re-run standard protocol, expect MASE under the TimesFM lines.
216
+ 5. **Commit + push the backlog** (files below): the v0.5 branch has uncommitted + untracked benchmark/paper/launch artifacts (~20 files). Commit per-milestone, then push.
217
+
218
+ ## What Makes This Wantable
219
+
220
+ **For developers with CSV data:**
221
+ - `python3 train_from_csv.py --csv sales.csv --target revenue --horizon 48`
222
+ - Custom model trained on your data in 2 minutes — no GPU, no cloud
223
+ - No need to think about zero-shot vs fine-tuning — it just trains on your data
224
+
225
+ **For real-time / streaming use cases:**
226
+ - Only TS model with stateful online inference — feed one value at a time
227
+ - DeltaNet RNN carries memory across calls; no other architecture does this
228
+ - IoT sensor monitoring, live financial data, interactive dashboards
229
+
230
+ **For GitHub users:**
231
+ - `pip install nanoforecast` works
232
+ - Understandable codebase (small files, clean naming)
233
+ - Train on your data in 20 min
234
+ - Deploy with FastAPI or ONNX.js
235
+
236
+ **For HF Hub users:**
237
+ - Smallest deployable TS model on the Hub (~9.2 MB INT8 at 6.5M params)
238
+ - `from_pretrained` + `predict()` in 2 lines
239
+ - Model card with honest benchmarks
240
+ - Gradio Space with live demo
241
+
242
+ **For OpenRouter users:**
243
+ - Cheapest TS forecast API available
244
+ - $0.001/series because compute cost is near-zero
245
+
246
+ **For edge/IoT developers:**
247
+ - Raspberry Pi, Lambda, mobile, browser — it runs anywhere
248
+ - CPU-only inference (140 ms full forecast on an Apple M4; Raspberry Pi feasible, not benchmarked)
249
+
250
+ ## Accuracy — two protocols, one truth
251
+
252
+ **Two sets of numbers exist and they are NOT comparable:**
253
+
254
+ 1. **Repo protocol** (`benchmark.py`, old) — the MASE 1.326 / "Beats PatchTST, Best-in-class" rows
255
+ found in earlier marketing docs. It used an InstanceScaler + app's own settings, so it is
256
+ **not directly comparable to published leaderboards or to TimesFM**. Keep for internal diff-ing
257
+ across versions only.
258
+ 2. **Standard protocol** (`benchmark_standard.py`, Aug 2026) — the **single source of truth** for
259
+ the paper, cards and any public claim. See the table above: NF-v0.5 beats TimesFM on all three
260
+ ETT sets (−3% → −47% MASE), ties exchange_rate (4.42 vs 4.38), and loses on electricity/traffic.
261
+
262
+ **Remaining targets (now divorced from marketing):**
263
+ - **Close the electricity/traffic gap vs TimesFM** (2.09 vs 0.92, 1.92 vs 0.77) — v0.6, more channel
264
+ coverage + mixed-aug train. This is the make-or-break for a defensible "beats TimesFM" claim.
265
+ - exchange_rate currently ties TimesFM (4.42 vs 4.38) — already far from the old 3.578-internal baseline.
266
+ - arXiv paper must be written over the standard protocol table.