Kronos forecast endpoint

This directory holds the Python server that powers the Kronos forecast card in the finance page. It is deployed separately as a HuggingFace Inference Endpoint β€” the Supabase Edge Function (supabase/functions/finance) calls it via the forecast action.

What Kronos is

Kronos (shiyu-coder/Kronos) is a foundation model for K-line forecasting. Given a window of recent OHLCV bars, it predicts the next N bars. We run it 30 times with stochastic sampling to produce a mean forecast plus a 10–90% confidence band.

Architecture

browser  ──►  Supabase Edge Fn (finance)  ──►  HF Inference Endpoint (this dir)
              Β· pulls history from Yahoo            Β· loads Kronos-small
              Β· POSTs bars + horizon                 Β· 30-sample forecast
              Β· returns predictions + CI            Β· returns mean + CI

Deploying to HuggingFace Inference Endpoints

  1. Create a new model repo on HuggingFace, e.g. <your-org>/aczen-kronos-handler.
  2. Push the contents of this directory (handler.py, requirements.txt) to that repo. Also include the Kronos model/ directory from https://github.com/shiyu-coder/Kronos/tree/master/model so from model import Kronos, KronosTokenizer, KronosPredictor resolves.
  3. Open the repo on HuggingFace β†’ Deploy β†’ Inference Endpoints.
  4. Pick a GPU instance (T4 is enough β€” a 30-day forecast with 30 samples runs in ~10–15s on T4).
  5. Once deployed, copy the endpoint URL (looks like https://xxxx.us-east-1.aws.endpoints.huggingface.cloud) and a HF access token with read permission for that endpoint.

Wiring it into Supabase

The edge function reads two secrets:

supabase secrets set KRONOS_ENDPOINT_URL=https://xxxx.endpoints.huggingface.cloud
supabase secrets set KRONOS_HF_TOKEN=hf_xxxxxxxxxxxxxxxx

Then redeploy:

supabase functions deploy finance --no-verify-jwt

Local testing

cd src/api/kronos
pip install -r requirements.txt
# Also clone the Kronos repo and copy its `model/` directory next to handler.py
python handler.py    # runs the built-in smoke test on a sine wave

To test the wire format the way Supabase calls it:

python -c "
import handler, json
h = handler.EndpointHandler()
bars = [{'timestamp': f'2024-01-{i+1:02d}', 'open':100,'high':101,'low':99,'close':100+i*0.1,'volume':1e6} for i in range(60)]
print(json.dumps(h({'inputs':{'history':bars,'pred_len':10,'n_samples':4}}), indent=2))
"

Tuning

Environment variables (set on the HF endpoint):

Var Default Notes
KRONOS_MODEL_REPO NeoQuasar/Kronos-small Switch to Kronos-base for higher quality
KRONOS_TOKENIZER_REPO NeoQuasar/Kronos-Tokenizer-base Must match the model checkpoint
KRONOS_MAX_CONTEXT 512 Max history bars passed to the model
KRONOS_DEFAULT_PRED_LEN 30 Default forecast horizon if client omits
KRONOS_CI_LOWER 0.1 Lower quantile of confidence band
KRONOS_CI_UPPER 0.9 Upper quantile of confidence band

Cost

A T4 endpoint on HuggingFace is roughly $0.60/hr while running. Use the endpoint's auto-scale-to-zero feature so it spins down between requests; the first forecast after idle has a 30–60s cold start.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support