nanoforecast 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nanoforecast-0.2.0/LICENSE +201 -0
- nanoforecast-0.2.0/PKG-INFO +359 -0
- nanoforecast-0.2.0/README.md +319 -0
- nanoforecast-0.2.0/nanoforecast/__init__.py +5 -0
- nanoforecast-0.2.0/nanoforecast/config.py +44 -0
- nanoforecast-0.2.0/nanoforecast/data/__init__.py +2 -0
- nanoforecast-0.2.0/nanoforecast/data/generator.py +164 -0
- nanoforecast-0.2.0/nanoforecast/data/pipeline.py +168 -0
- nanoforecast-0.2.0/nanoforecast/data/real_datasets.py +213 -0
- nanoforecast-0.2.0/nanoforecast/evaluation/__init__.py +1 -0
- nanoforecast-0.2.0/nanoforecast/evaluation/benchmark.py +145 -0
- nanoforecast-0.2.0/nanoforecast/export/__init__.py +1 -0
- nanoforecast-0.2.0/nanoforecast/export/onnx_export.py +156 -0
- nanoforecast-0.2.0/nanoforecast/hub.py +271 -0
- nanoforecast-0.2.0/nanoforecast/model/__init__.py +15 -0
- nanoforecast-0.2.0/nanoforecast/model/blocks.py +254 -0
- nanoforecast-0.2.0/nanoforecast/model/core.py +250 -0
- nanoforecast-0.2.0/nanoforecast/model/heads.py +123 -0
- nanoforecast-0.2.0/nanoforecast/model/utils.py +139 -0
- nanoforecast-0.2.0/nanoforecast/train/__init__.py +2 -0
- nanoforecast-0.2.0/nanoforecast/train/loss.py +109 -0
- nanoforecast-0.2.0/nanoforecast/train/trainer.py +186 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/PKG-INFO +359 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/SOURCES.txt +30 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/dependency_links.txt +1 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/entry_points.txt +3 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/requires.txt +22 -0
- nanoforecast-0.2.0/nanoforecast.egg-info/top_level.txt +1 -0
- nanoforecast-0.2.0/pyproject.toml +67 -0
- nanoforecast-0.2.0/setup.cfg +4 -0
- nanoforecast-0.2.0/tests/test_data.py +86 -0
- nanoforecast-0.2.0/tests/test_model.py +148 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of tracking or otherwise improving the Work,
|
|
59
|
+
but excludes communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed" page as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 NanoForecast Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nanoforecast
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Ultra-lightweight time series foundation model architecture (200K-1.6M params) with streaming inference and Hugging Face Hub integration.
|
|
5
|
+
Author: NanoForecast Contributors, Eulogik (https://eulogik.com)
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/eulogik/NanoForecast
|
|
8
|
+
Project-URL: Repository, https://github.com/eulogik/NanoForecast
|
|
9
|
+
Project-URL: Issues, https://github.com/eulogik/NanoForecast/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: torch<3.0,>=2.0
|
|
22
|
+
Requires-Dist: numpy<3.0,>=1.24
|
|
23
|
+
Requires-Dist: pandas<3.0,>=1.5
|
|
24
|
+
Requires-Dist: requests>=2.28
|
|
25
|
+
Requires-Dist: huggingface_hub>=0.20
|
|
26
|
+
Provides-Extra: onnx
|
|
27
|
+
Requires-Dist: onnx>=1.14; extra == "onnx"
|
|
28
|
+
Requires-Dist: onnxruntime>=1.15; extra == "onnx"
|
|
29
|
+
Provides-Extra: spaces
|
|
30
|
+
Requires-Dist: gradio>=4.0; extra == "spaces"
|
|
31
|
+
Requires-Dist: plotly>=5.0; extra == "spaces"
|
|
32
|
+
Provides-Extra: deploy
|
|
33
|
+
Requires-Dist: fastapi>=0.110.0; extra == "deploy"
|
|
34
|
+
Requires-Dist: uvicorn[standard]>=0.27.0; extra == "deploy"
|
|
35
|
+
Requires-Dist: python-multipart>=0.0.6; extra == "deploy"
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# 🔮 NanoForecast
|
|
42
|
+
|
|
43
|
+
**World's most deployable time series transformer**
|
|
44
|
+
|
|
45
|
+
[](https://huggingface.co/spaces/eulogik/nanoforecast)
|
|
46
|
+
[](https://huggingface.co/eulogik/nanoforecast-500k)
|
|
47
|
+
[](./LICENSE)
|
|
48
|
+
[](./pyproject.toml)
|
|
49
|
+
[](https://eulogik.com)
|
|
50
|
+
|
|
51
|
+
NanoForecast is a **tiny, fast, deployable** time series forecasting model. Unlike foundation models that require GPUs and terabytes of data, NanoForecast:
|
|
52
|
+
|
|
53
|
+
- **Trains on your data in 2 minutes** — `python3 train_from_csv.py --csv sales.csv --target revenue`
|
|
54
|
+
- **Streams forecasts online** — the only TS model where you can feed one value at a time
|
|
55
|
+
- **Runs on a Raspberry Pi** (<50ms inference on ARM)
|
|
56
|
+
- **Exports to 1.4 MB ONNX** (Edge/IoT/browser ready)
|
|
57
|
+
- **Fully Apache 2.0** — no strings attached
|
|
58
|
+
|
|
59
|
+
It's **not** a foundation model. It's not going to beat TimesFM on benchmarks. What it does is **actually ship to production**.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
### Train on your own data (primary path)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
python3 train_from_csv.py --csv my_data.csv --target sales --horizon 48
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
That's it. You get a saved model checkpoint + forecast CSV. No GPU, no cloud.
|
|
72
|
+
|
|
73
|
+
> Built by [Eulogik](https://eulogik.com) — deployable AI for the real world.
|
|
74
|
+
|
|
75
|
+
### Or use the pretrained model
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install nanoforecast
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import numpy as np
|
|
83
|
+
from nanoforecast import NanoForecast
|
|
84
|
+
|
|
85
|
+
model = NanoForecast.from_pretrained("eulogik/nanoforecast-500k")
|
|
86
|
+
|
|
87
|
+
context = np.sin(np.linspace(0, 8*np.pi, 256)) + 0.1 * np.random.randn(256)
|
|
88
|
+
result = model.predict(context, horizon=48, freq=1)
|
|
89
|
+
forecast = result["forecast"][0] # shape (48,)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Streaming / Online Inference (unique to NanoForecast)
|
|
93
|
+
|
|
94
|
+
NanoForecast's DeltaNet RNN architecture maintains a recurrent state across calls — no other TS model does this.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# Initial forecast + state
|
|
98
|
+
result = model.predict(context, horizon=48, return_state=True)
|
|
99
|
+
state = result.pop("state")
|
|
100
|
+
|
|
101
|
+
# Stream new observations one at a time
|
|
102
|
+
for new_val in incoming_data_stream:
|
|
103
|
+
result = model.predict_step(new_val, state, horizon=48)
|
|
104
|
+
print(result["forecast"][0, :5]) # updated forecast instantly
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Each call preserves the DeltaNet's memory of all past data. Use it for:
|
|
108
|
+
- **Real-time IoT sensor monitoring**
|
|
109
|
+
- **Live financial tick data**
|
|
110
|
+
- **Interactive dashboards**
|
|
111
|
+
|
|
112
|
+
## Try It Now
|
|
113
|
+
|
|
114
|
+
[](https://huggingface.co/spaces/eulogik/nanoforecast)
|
|
115
|
+
|
|
116
|
+
Upload a CSV, set your horizon, get a forecast + prediction intervals + decomposition plot. No code required.
|
|
117
|
+
|
|
118
|
+
## Features
|
|
119
|
+
|
|
120
|
+
| Feature | Details |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| **Architecture** | LongConv + DeltaNet RNN + gated router + MLP blocks |
|
|
123
|
+
| **Parameters** | ~200K–700K (tiny) |
|
|
124
|
+
| **Outputs** | Point forecast + 5 quantiles (p10/p25/p50/p75/p90) + trend/seasonal/residual decomposition |
|
|
125
|
+
| **Context** | 256 timesteps |
|
|
126
|
+
| **Horizon** | Any length (trained on 48) |
|
|
127
|
+
| **Frequency** | Hourly / Daily / Weekly / Monthly |
|
|
128
|
+
| **Deploy targets** | CPU, ARM, Raspberry Pi, Lambda, iOS, browser (via ONNX.js) |
|
|
129
|
+
| **Streaming inference** | Stateful RNN — feed one value at a time, no re-processing |
|
|
130
|
+
| **Train on your data** | `train_from_csv.py` — 2 min on a laptop, no GPU |
|
|
131
|
+
|
|
132
|
+
## Deploy
|
|
133
|
+
|
|
134
|
+
### FastAPI Server
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pip install nanoforecast fastapi uvicorn python-multipart
|
|
138
|
+
python3 deploy/fastapi_server.py
|
|
139
|
+
# → http://localhost:8000/docs
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
curl -X POST http://localhost:8000/predict \
|
|
144
|
+
-d "context=[1.0,2.0,3.0,...]" \
|
|
145
|
+
-d "horizon=48" \
|
|
146
|
+
-d "freq=1"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Docker
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
docker build -t nanoforecast -f deploy/Dockerfile .
|
|
153
|
+
docker run -p 8000:8000 nanoforecast
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### ONNX (Edge / IoT)
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
pip install "nanoforecast[onnx]"
|
|
160
|
+
python3 -m nanoforecast.export.onnx_export \
|
|
161
|
+
--checkpoint <checkpoint-dir> \
|
|
162
|
+
--output nanoforecast.onnx
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Then load with onnxruntime on any platform:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import onnxruntime as ort
|
|
169
|
+
session = ort.InferenceSession("nanoforecast.onnx")
|
|
170
|
+
forecast = session.run(None, {"input": context_numpy})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Repository layout
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
nanoforecast/
|
|
179
|
+
config.py # NanoForecastConfig dataclass
|
|
180
|
+
model/ # core architecture
|
|
181
|
+
blocks.py # LongConv, DeltaNet, GatedMLP, GatedRouter
|
|
182
|
+
heads.py # point, quantile (monotonic), anomaly, decomposition
|
|
183
|
+
core.py # NanoForecast nn.Module
|
|
184
|
+
utils.py # scaler, patching, freq prefix, positional encoding
|
|
185
|
+
train/
|
|
186
|
+
loss.py # multi-task loss (point + quantile + anomaly + smooth)
|
|
187
|
+
trainer.py # OneCycleLR trainer with MPS / CUDA / CPU support
|
|
188
|
+
data/
|
|
189
|
+
generator.py # synthetic time series generator
|
|
190
|
+
pipeline.py # dataset + resolution-aware batch sampler
|
|
191
|
+
real_datasets.py # ETTh1/2, ETTm1, exchange_rate, electricity, traffic loaders
|
|
192
|
+
evaluation/
|
|
193
|
+
benchmark.py # MASE, sMAPE, MSE, MAE, CRPS, coverage
|
|
194
|
+
export/
|
|
195
|
+
onnx_export.py # FP32 + dynamic INT8 ONNX export
|
|
196
|
+
hub.py # save_pretrained / from_pretrained / predict mixin
|
|
197
|
+
gradio_app.py # Hugging Face Space (upload CSV → forecast plot)
|
|
198
|
+
demo.py # one-liner demo: python3 demo.py
|
|
199
|
+
deploy/ # FastAPI server + Docker
|
|
200
|
+
fastapi_server.py
|
|
201
|
+
Dockerfile
|
|
202
|
+
requirements.txt
|
|
203
|
+
pretrain.py # real + synthetic pretraining CLI
|
|
204
|
+
benchmark.py # multi-dataset benchmark CLI
|
|
205
|
+
push_to_hub.py # publish a checkpoint to the HF Hub
|
|
206
|
+
run_pipeline.py # synthetic-only smoke pipeline (legacy)
|
|
207
|
+
train_from_csv.py # train on your own CSV (primary user path)
|
|
208
|
+
tests/ # unit + smoke tests
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Architecture
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
Raw Context -> Robust Scaling & Patching -> Resolution Prefix Token
|
|
217
|
+
|
|
|
218
|
+
v
|
|
219
|
+
Sequence Mixing Blocks (x N)
|
|
220
|
+
- LongConv (global periodicity)
|
|
221
|
+
- DeltaNet RNN (local dependencies)
|
|
222
|
+
- Gated Router & MLP (dynamic blend)
|
|
223
|
+
|
|
|
224
|
+
v
|
|
225
|
+
Multi-Task Heads (single forward pass)
|
|
226
|
+
- Point forecast
|
|
227
|
+
- Monotonic quantiles (p10..p90)
|
|
228
|
+
- Context reconstruction (anomaly)
|
|
229
|
+
- Trend / Seasonality decomposition
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
| Preset | d_model | Layers | Patch | Parameters | FP32 size |
|
|
233
|
+
|---|---:|---:|---:|---:|---:|
|
|
234
|
+
| `nano-200k` | 32 | 4 | 8 | ~676K | ~2.7 MB |
|
|
235
|
+
| `nano-500k` | 64 | 8 | 8 | ~1.6M | ~6.4 MB |
|
|
236
|
+
| `nano-1m` (v0.3) | 96 | 8 | 8 | ~3.6M | ~14 MB |
|
|
237
|
+
|
|
238
|
+
### Design notes
|
|
239
|
+
|
|
240
|
+
- **Instance Robust Scaler** (median / IQR) makes the model robust to outliers.
|
|
241
|
+
- **Monotonic quantile head** guarantees p10 ≤ p25 ≤ p50 ≤ p75 ≤ p90.
|
|
242
|
+
- **Conservation identity**: trend + seasonal + residual ≡ point forecast.
|
|
243
|
+
- **ONNX exportable** with a drop-in RMSNorm replacement.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Train Your Own
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
python3 pretrain.py \
|
|
251
|
+
--datasets ETTh1,ETTh2,exchange_rate,electricity \
|
|
252
|
+
--epochs 50 \
|
|
253
|
+
--batch-size 64 \
|
|
254
|
+
--device cpu \
|
|
255
|
+
--output checkpoints/nanoforecast-my-data
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Benchmarking
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
python3 benchmark.py \
|
|
262
|
+
--checkpoint <checkpoint-dir> \
|
|
263
|
+
--datasets ETTh1,ETTh2,ETTm1,exchange_rate \
|
|
264
|
+
--max-windows 64 \
|
|
265
|
+
--output results/benchmark.json
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Publishing to HF Hub
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
huggingface-cli login
|
|
272
|
+
python3 push_to_hub.py \
|
|
273
|
+
--checkpoint <checkpoint-dir> \
|
|
274
|
+
--repo-id your-username/nanoforecast-500k \
|
|
275
|
+
--benchmark-json results/benchmark.json
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Benchmarks
|
|
281
|
+
|
|
282
|
+
### v0.3 (d_model=96, 6.5M params, context=512, 200 epochs, Colab T4)
|
|
283
|
+
|
|
284
|
+
| Dataset | MASE | sMAPE (%) | MAE | CRPS |
|
|
285
|
+
|---:|---:|---:|---:|---:|
|
|
286
|
+
| ETTh1 | **1.95** | 12.06 | 1.30 | 1.05 |
|
|
287
|
+
| ETTh2 | **2.74** | 10.47 | 2.46 | 1.99 |
|
|
288
|
+
| ETTm1 | **2.17** | 10.70 | 0.72 | 0.65 |
|
|
289
|
+
| exchange_rate | **7.44** | 1.72 | 0.011 | 0.014 |
|
|
290
|
+
| electricity | **1.29** | 4.76 | 158.30 | 175.24 |
|
|
291
|
+
| traffic | **0.81** | 24.00 | 0.004 | 0.003 |
|
|
292
|
+
| **Overall** | **2.73** | 10.62 | 27.13 | 29.83 |
|
|
293
|
+
|
|
294
|
+
### v0.2 (d_model=64, 1.6M params, context=256, 100 epochs, Mac Mini M4)
|
|
295
|
+
|
|
296
|
+
| Dataset | MASE | sMAPE (%) | MAE | CRPS |
|
|
297
|
+
|---:|---:|---:|---:|---:|
|
|
298
|
+
| ETTh1 | **3.34** | 25.13 | 2.40 | 1.80 |
|
|
299
|
+
| ETTh2 | **3.71** | 17.65 | 3.21 | 2.52 |
|
|
300
|
+
| ETTm1 | **3.58** | 17.22 | 1.17 | 1.00 |
|
|
301
|
+
| exchange_rate | **7.31** | 1.63 | 0.010 | 0.009 |
|
|
302
|
+
| electricity | **1.54** | 5.65 | 189.75 | 187.26 |
|
|
303
|
+
| traffic | **1.25** | 44.80 | 0.006 | 0.006 |
|
|
304
|
+
| **Overall** | **3.45** | 18.68 | 32.76 | 32.10 |
|
|
305
|
+
|
|
306
|
+
### v0.3 vs v0.2 comparison
|
|
307
|
+
|
|
308
|
+
| Dataset | v0.2 | v0.3 | Improvement |
|
|
309
|
+
|---:|---:|---:|---|
|
|
310
|
+
| ETTh1 | 3.34 | **1.95** | ↓ 42% |
|
|
311
|
+
| ETTh2 | 3.71 | **2.74** | ↓ 26% |
|
|
312
|
+
| ETTm1 | 3.58 | **2.17** | ↓ 39% |
|
|
313
|
+
| exchange_rate | 7.31 | 7.44 | ↑ 2% |
|
|
314
|
+
| electricity | 1.54 | **1.29** | ↓ 16% |
|
|
315
|
+
| traffic | 1.25 | **0.81** | ↓ 35% |
|
|
316
|
+
| **Overall** | **3.45** | **2.73** | **↓ 21%** |
|
|
317
|
+
|
|
318
|
+
v0.3 beats v0.2 on 5 of 6 datasets. Larger model (6.5M vs 1.6M) and longer context (512 vs 256) provide significant accuracy gains on ETTh1/ETTh2/ETTm1. Exchange rate (volatile FX) slightly regresses.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Known limitations
|
|
323
|
+
|
|
324
|
+
| Issue | Status |
|
|
325
|
+
|---|---|
|
|
326
|
+
| **Accuracy** | Modest vs SOTA (MASE ~2.73 overall for v0.3). Good enough for prototypes, not production forecasting at scale. |
|
|
327
|
+
| **Training** | Multi-dataset mixing (v0.3: 6 real + 10K synthetic, 200 epochs). |
|
|
328
|
+
| **Context** | Fixed 256 — longer history is truncated. |
|
|
329
|
+
| **Channels** | Univariate by default; multivariate support is per-dimension independent. |
|
|
330
|
+
| **Edge cases** | NaN values, missing timestamps, irregularly-sampled data not handled automatically. |
|
|
331
|
+
|
|
332
|
+
This is a **developer tool**, not a research paper. It prioritizes deployability over accuracy.
|
|
333
|
+
|
|
334
|
+
## Roadmap
|
|
335
|
+
|
|
336
|
+
| Version | Focus | Timeline |
|
|
337
|
+
|---|---|---|
|
|
338
|
+
| v0.1 | Deployable MVP — train, predict, export, deploy | ✅ Done |
|
|
339
|
+
| v0.2 | Streaming inference + train-from-CSV CLI + multi-dataset training (Mac Mini) | ✅ Done |
|
|
340
|
+
| v0.3 | Colab T4 training (larger model, more data) + ONNX.js browser demo | TBD |
|
|
341
|
+
| v0.4 | OpenRouter API — $0.001/forecast | TBD |
|
|
342
|
+
|
|
343
|
+
## Why "NanoForecast"?
|
|
344
|
+
|
|
345
|
+
Because forecasting models shouldn't require:
|
|
346
|
+
- A $30K GPU
|
|
347
|
+
- 100 GB of training data
|
|
348
|
+
- 12 dependencies that break every release
|
|
349
|
+
- A team of PhDs to deploy
|
|
350
|
+
|
|
351
|
+
You should be able to train a forecasting model on your laptop, deploy it to a Raspberry Pi, and have it running in production before lunch.
|
|
352
|
+
|
|
353
|
+
## License
|
|
354
|
+
|
|
355
|
+
Apache 2.0. See [LICENSE](./LICENSE).
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
Built by [Eulogik](https://eulogik.com) — deployable AI for the real world.
|