Full 120M-parameter Amazon Chronos-2 time-series forecasting compiled into a 119 KiB Rust/WASM SIMD engine β ~10Γ less RAM than PyTorch, faster on single-core CPU for typical forecasts, within Β±0.12% of FP32 across 224 public benchmarks, and running resident inside a single Cloudflare Worker.
No GPUs. No containers. No external inference APIs. No calibration data or retraining.
| PyTorch FP32 (CPU) | This Engine (WASM SIMD) | Delta | |
|---|---|---|---|
| Weight file | 478.0 MB | 88.7 MB | 5.4Γ smaller |
Peak memory (8,192 / 1,024) |
959.8 MB RSS | 95.9 MB WASM (fits 128 MiB Worker) | ~10Γ less RAM |
| Runtime binary | Python + PyTorch + OpenBLAS | 119 KiB.wasm (37.5 KiB gz) |
Zero runtime deps |
Single-core CPU (512 / 64 p50) |
112.0 ms | 96.6 ms | 1.16Γ faster |
3,800 benchmark forecasts (512 ctx) |
403.9 s | 363.1 s | 1.11Γ faster (1.42Γ on Chronos-II) |
| Accuracy (224 tasks, 9 deciles) | baseline | Β±0.12% SQL / WQL / MASE | Indistinguishable from FP32 |
| Live Cloudflare Workers edge | Cannot run (OOM) | 261 ms p50 (512/64 ) Β·1.03 s R2 cold |
0 warm R2 reads |
Supports the full univariate amazon/chronos-2 contract: 1β8,192 context length (including null missing values), 1β1,024 forecast horizon, and all 9 native deciles (0.1 through 0.9).
Five engineering choices make the full 120M model fit in 95.9 MB and outperform PyTorch CPU without losing accuracy:
A bespoke 119 KiB WASM engine specialized to one model. Instead of shipping a general-purpose ML runtime,engine/src/c2edge30.rs hardcodes everyamazon/chronos-2 dimension (12 layers, D=768, FF=3072, patch=16, 9 deciles ) and computes every tensor's byte offset at compile time (const usize ). There is no header parser, no dynamic shape dispatch, and no per-layer heap allocation. Activations run through a32-token micro-batched scratch arena with L2-tiled 4-query head-major attention, keeping total working RAM flat at6.5 MB even at8,192 context /1,024 horizon.
2.
Why WebAssembly beats PyTorch CPU on typical forecasts. For1β512 step histories, transformer inference is memory-bandwidth bound, not FLOP bound. Streaming88.7 MB of packed weights moves5.4Γ fewer bytes than FP32 (478 MB ), eliminates Python/PyTorch dispatch overhead, and drops 12 matrix multiplies via exactO @ V fusion. Custom 16-token WASM SIMD128 micro-kernels (i32x4_dot_i16x8 ) run1.11Γβ1.42Γ faster than single-core PyTorch OpenBLAS FP32 across 3,800 public benchmark forecasts.(At 8,192 / 1,024, quadratic attention FLOPs dominate and PyTorch OpenBLAS is slightly faster: 1.38 s vs 1.67 s.)
3.
Zero 4-bit quantization, zero calibration data. Standard 4-bit quantization degrades Chronos-2 on spiky and high-dynamic-range series, while switching to Amazon's smaller 28Mchronos-2-small drops accuracy by+4% to+14% . Instead,model/pack.py assigns precision purely by structural sensitivity with zero calibration data:
- Tiny I/O boundary heads & all norms/biases stay in FP32 (
3.1 MB). - Large I/O MLPs use IEEE FP16 (
9.4 MB), decoded branchlessly on the fly in SIMD with zero RAM expansion. - The 17 most sensitive encoder projections (all 12
Vmatrices,L0/L1/L11FFNwi, andL11`` ov/wo) use**Q8_G64** (15.3 MB). - The remaining 67 encoder projections use split-plane 6-bit (
Q6_G64:low4 + high2) (60.8 MB), fitted with 3-iteration closed-form alternating least-squares per 64 weights and unpacked with zero byte shuffles in WASM SIMD128.
- Tiny I/O boundary heads & all norms/biases stay in
Two exact weight-space transforms (zero accuracy loss in FP32).
- Diagonal-split exact
O @ Vfusion: For univariate series, Chronos-2's group-attention softmax has a single active key, so attention weights are identically1.0. The exporter multipliesM = O @ Vexactly in FP64 (eliminating 12 matrices), pulls out the 768-element diagonal intoFP32 (36 KBtotal β capturing ~25% of matrix energy), and quantizes only the smooth off-diagonalM β diag(M). - Free FFN neuron sorting: Because
W_o Β· ReLU(W_i Β· x)is invariant to permuting hidden neurons, sorting the 3,072 neurons by ascendingmax(|W_o[:, j]|)clusters outlier columns into shared 64-element quantization blocks β cuttingW_oquantization error by up to19% at0bytes and0runtime cycles.
Zero-copy BYOB streaming from Cloudflare R2. Buffering an88.7 MB model in JS heap before copying to WASM blows past Cloudflare Workers' 128 MiB isolate ceiling. On cold start,worker/handler.mjs streams the single R2 object through a reused128 KiB BYOB buffer straight intoWebAssembly.Memory while verifyingSHA-256 incrementally (1.03 s cold on live edge,0 R2 reads on every warm request after).
Requires Linux x86-64 (or macOS/ARM64 for local builds), Node.js 22+, Python 3.12, and Rust via rustup with wasm32-unknown-unknown.
./scripts/bootstrap.sh # downloads pinned amazon/chronos-2, packs 88.7 MB weights, builds 119 KiB WASM
npm test # runs Worker, ABI, and 8,192/1,024 memory tests
npm run serve # starts local workerd on http://127.0.0.1:8787
Run a forecast:
curl -sS http://127.0.0.1:8787/forecast \
-H 'Content-Type: application/json' \
-d '{"history":[10,12,11,13,15,14,10,12,11,13,15,14,10,12,11,13,15],"horizon":7}'
GET /healthβ liveness check ({"status":"ok"}); does not load model weights (1 msstartup).POST /forecastβ accepts{"history": [...], "horizon": N}(application/json,β€ 256 KiB):history:1β8,192 finite float32 values (nullsupported for missing observations; at least one observed value required).horizon: integer in1β1,024 .- Returns
{"quantiles": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], "values": [[...], ...]}(raw native model outputs; no post-processing).
Requires a Cloudflare Workers Paid plan ([limits] cpu_ms = 30000 for 8,192-context requests) and R2 enabled on your account.
key=$(node -p 'require("./worker/generated/artifact.json").key')
cf r2 buckets create-by-name chronos-2-artifacts
cf r2 buckets objects upload "$key" \
--bucket-name chronos-2-artifacts \
--content-type application/octet-stream \
--file ".cache/artifacts/$key"
npx wrangler deploy
See docs/deployment.md for Wrangler R2 upload commands and production notes.
npm run evaluate
.cache/venv/bin/python campaigns/rfc5/run_official.py --context 512 --series-limit 16 --window-limit 1 --cpu 8 --output .cache/c2edge30/official-512
.cache/venv/bin/python campaigns/rfc5/run_official.py --context 8192 --series-limit 1 --window-limit 1 --cpu 8 --output .cache/c2edge30/official-8192
python3 scripts/generate-charts.py
- Model Artifact & Memory Layout β exact byte layout, mixed-precision split, and weight transforms
- Cloudflare Workers Deployment Guide β R2 setup, Wrangler deployment, and live edge numbers
- Full 224-Task Benchmark & Edge Verification Report β complete suite tables, paired CPU timings, and live soak results
Apache-2.0 β see LICENSE. Model weights are not redistributed; model/fetch.py downloads the pinned Apache-2.0 amazon/chronos-2 checkpoint directly from Hugging Face and verifies its SHA-256 digests against model/lock.json.