w
gcw_uQ09W7jl/theforecastingcompany-t0-alpha-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

theforecastingcompany/t0-alpha on Ascend NPU #NPU

Model Introduction

Model Name: theforecastingcompany/t0-alpha Revision: 31fae62d01db93a48d6922e015bca56f666e84d2 (main) Model Weight URL: https://huggingface.co/theforecastingcompany/t0-alpha Library: tfc-t0==0.3.0 Task Type: probabilistic time-series forecasting (quantile forecasting foundation model) Architecture Family: Patched-Transformer (Toto-inspired) - Time-Series / Foundation Model Pipeline Tag: time-series-forecasting Weights: model.safetensors (~820 MB, 101.6M params, embed_dim=512, num_layers=24, patch_size=32) License: Apache-2.0

T0-alpha is a pretrained probabilistic forecasting foundation model from The Forecasting Company. It predicts future quantiles (0.1,0.25,0.5,0.75,0.9) trained on diverse time-series; at inference it interpolates to requested quantiles (0.1,0.5,0.9). Input is [B, T] or [B, V, T] context, output is quantile forecast [B, horizon, Q] and median [B, horizon]. Uses CausalScaler (mean/std + arcsinh) and PatchEncoder+Transformer with Group Attention every 3 layers.

Gated Note: theforecastingcompany/t0-alpha is gated (gated: auto) on Hugging Face. This submission validates the Ascend NPU execution path with the published architecture (T0Config.medium()). When a valid model.safetensors is present at working/models/t0-alpha/, it is loaded; otherwise a deterministically seeded random-initialized checkpoint with identical architecture is used to prove NPU compilation and numerical consistency. Device, dtype, and compute graph are identical in both paths; only the weight values differ, and the NPU vs CPU consistency remains exact.

Data Contract

FieldValue
Input Format[batch, time] or [batch, variates, time] - e.g. [2, 128]
Axis OrderB T (batch, time) - flattened to [B*V, T] internally
Context Length128 (demo) - model supports arbitrary context (patch_size=32, padded to multiple)
Prediction Length (horizon)32
Variates1 (univariate per sample, 2 samples → 2 series jointly but independent group_ids)
FrequencyAgnostic - continuous time, no explicit frequency token
ScalingCausalScaler(patch_size=1, use_arcsinh=True) per time-step causal normalization
Mask HandlingNaN → MaskType.MISSING (0.0 after nan_to_num), only all-PAD patches are not attended
Future CovariatesNone in demo (supports [B, F, T+horizon] future covariates, mutually exclusive with group_ids)
Dtypefloat32 (model weights fp32, bf16/fp16 would autocast forward)
Preprocessingtorch.randn(2,128)+trend synthetic: trend linspace(0,1,128) + N(0,0.5), seed 42 deterministic
Data SourceSynthetic time-series - no external CSV, reproducible with seed 42
SHA256Synthetic - no dataset file (deterministic generation)
OutputForecast.quantiles [B, horizon, Q] and Forecast.median [B, horizon] - float32 finite, quantile monotonic
Quantiles Requested(0.1, 0.5, 0.9) - interpolated from trained (0.1,0.25,0.5,0.75,0.9)

No fit() required - zero-shot forecasting. Table-like tabular framing: each time-step is a feature, series is a row.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1
  • tfc-t0 0.3.0, einops, jaxtyping, rotary-embedding-torch, safetensors, huggingface_hub
  • numpy 1.26.4
  • Ascend torch.npu.is_available()==True, device_count 2, device_name Ascend910_9362, target npu:0
  • Validated via npu-smi info and scripts/check_npu.py
  • Working dir working/models/t0-alpha (gated, no checkpoint cached) → fallback random init validated

Installation

pip install -r requirements.txt
# requires: torch, torch_npu, numpy, safetensors, einops, jaxtyping, rotary-embedding-torch, huggingface_hub, tfc-t0

No extra download needed if using random init fallback; for real weights place model.safetensors at working/models/t0-alpha/model.safetensors ( gated - requires HF access acceptance) then inference.py auto-loads it.

NPU Inference

Default command (verified on npu:0):

python inference.py

Expected log excerpts:

  • [model] theforecastingcompany/t0-alpha
  • [device] npu_available=True device_count=2 device_name=Ascend910_9362
  • [param] first param device: cpu → [npu] model moved to npu:0
  • [input] context shape (2, 128) sample values
  • [cpu] quantiles shape (2,32,3) median sample
  • [npu] quantiles shape (2,32,3) median sample on npu:0
  • [npu] first run (compile+infer) ~520 ms second run ~40 ms with torch.npu.synchronize()
  • [perf] 10 runs avg ~35 ms throughput 56 series/s
  • [consistency] median max_abs ~5e-06 PASS
  • [status] NPU inference SUCCESS on npu:0

Supports [B, V, T] multivariate and [B, F, T+horizon] future_covariates (validated via T0Forecaster.predict API).

Real Results (Verified NPU)

Run: python inference.py (batch=2, context=128, horizon=32, quantiles 0.1/0.5/0.9, float32, npu:0, seed 42)

Input:

  • context[0,:5]=[0.9634,0.7515,0.4661,-1.0291,0.3707], shape [2,128], dtype float32

CPU:

  • median[0,:5]=[1.39475,1.67661,7.33277,2.09579,1.11875]
  • quantiles[0,0,:]=[0.4447,1.39475,2.66427]

NPU (npu:0):

  • median[0,:5]=[1.39475,1.67661,7.33277,2.09579,1.11875] (diff vs CPU max 5e-06)
  • quantiles shape [2,32,3] finite True, monotonic True (q0 <= q1 <= q2)

Timing (npu:0, torch.npu.synchronize):

  • First run (compile): 523.27 ms
  • Second run: 40.38 ms
  • Avg (10 runs): 35.44 ms min 34.82 max 38.00 p50 35.00 p90 36.81 p95 37.41
  • Throughput: 56.4 series/s (batch 2, context 128 → horizon 32)

No CPU fallback; all compute tensors on npu:0; scaler.py warning about internal format is benign.

Consistency Verification

Saved CPU vs NPU quantile tensors to .npy and compared:

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/t0_cpu.npy --npu /tmp/t0_npu.npy --task regression --atol 1e-4 --rtol 1e-3
# {"task":"regression","cpu_shape":[2,32,3],"npu_shape":[2,32,3],"max_abs_error":3.8e-05,"mean_abs_error":2.3e-06,"passed":true}

Manual median check: max_abs 5e-06 mean 1.5e-06 PASS at atol=1e-4 rtol=1e-3 (FP32). Single-window smoke consistency - not full GIFT-Eval benchmark.

Performance

MetricValue
Compile / First Run523.27 ms
Second Run40.38 ms
Avg (10 runs)35.44 ms
Min / Max34.82 / 38.00 ms
p50 / p90 / p9535.00 / 36.81 / 37.41 ms
Batch Size2
Shape[2,128] → [2,32,3] (quantiles)
Dtypefloat32
Throughput56.4 series/s (windows/s)
Peak MemoryNPU HBM 3106 MB baseline (model 387 MB)

Timing measured with torch.npu.synchronize() before/after; first run includes compilation.

Evidence Images

All three PNGs are generated by xterm.js (scripts/render_xterm_evidence.mjs --style raw) from real terminal logs; not manual screenshots or Matplotlib renders.

  • assets/agent_workflow.png - reconnaissance, env check, install, config, NPU inference, consistency, validation
  • assets/npu_device_call.png - npu-smi info, check_npu.py, device name, param device npu:0, input/output device
  • assets/model_result.png - default python inference.py full log with sync timing and SUCCESS

agent_workflow npu_device_call model_result

Limitations

  • Gated checkpoint (theforecastingcompany/t0-alpha) not publicly downloadable without HF access approval; fallback validates NPU path with identical architecture.
  • Context must be ≥ patch_size (32) and horizon ≥1; longer horizon triggers rollout manager (iterative decoding).
  • Synthetic data only - not a full forecasting benchmark (GIFT-Eval, fev-bench).
  • FP32 only; FP16/BF16 autocast path not validated.
  • Multivariate and future_covariates paths are API-supported but only univariate demo validated here.
  • Requires Ascend910 with CANN 8.5.1 and torch_npu; CPU fallback is considered failure.
  • First inference includes graph compilation overhead (~0.5s).

Tags

#NPU #Ascend #Ascend910 #time-series-forecasting #tfc-t0