Skip to content

dtau00/chronos2-lm-studio

Repository files navigation

Amazon Chronos2 + LM Studio Setup

This project sets up Amazon's Chronos2 time series forecasting model and makes it accessible through LM Studio via an OpenAI-compatible API.

What is Chronos2?

Chronos2 is a family of pretrained time series forecasting models developed by Amazon. It uses a language model architecture (T5) adapted for time series prediction, achieving state-of-the-art zero-shot forecasting performance.

Setup Instructions

1. Install Python Dependencies

pip install -r requirements.txt

This will install:

  • PyTorch
  • Transformers
  • Chronos-forecasting
  • FastAPI and Uvicorn (for the API server)

2. Start the Chronos2 Server

python chronos_server.py

The server will:

  • Download the Chronos model from Hugging Face (first run only)
  • Start an OpenAI-compatible API server on http://localhost:8000
  • Automatically use GPU if available, otherwise CPU

3. Configure LM Studio

  1. Open LM Studio
  2. Go to the "Developer" tab or "Local Server" section
  3. Look for "Add External Server" or "Custom OpenAI Endpoint"
  4. Add a new server with these settings:
    • Name: Chronos2
    • Base URL: http://localhost:8000/v1
    • API Key: (leave empty or use any text)
    • Model: amazon/chronos-t5-small

4. Chat with Chronos2

In LM Studio's chat interface:

  1. Select the "Chronos2" model
  2. Send time series data for forecasting

Usage Examples

Example 1: Simple Forecast

User: [120, 135, 128, 145, 142, 155, 160, 148, 165, 172]

Chronos2 will forecast the next 12 time steps by default.

Example 2: Custom Forecast Length

System: prediction_length: 24

User: [10.5, 11.2, 10.8, 12.1, 11.9, 12.5, 13.2, 12.8, 13.5, 14.1]

Example 3: Real-World Data

User: Monthly sales data: 1500, 1620, 1580, 1720, 1850, 1920, 2100, 2050, 2200, 2350, 2280, 2450

API Endpoints

Chat Completions

POST http://localhost:8000/v1/chat/completions

OpenAI-compatible endpoint for forecasting.

List Models

GET http://localhost:8000/v1/models

Returns available models.

Health Check

GET http://localhost:8000/health

Check server status and model loading.

Model Variants

You can modify chronos_server.py to use different Chronos2 variants:

  • amazon/chronos-t5-tiny - Fastest, least accurate
  • amazon/chronos-t5-mini - Good balance
  • amazon/chronos-t5-small - Default, recommended
  • amazon/chronos-t5-base - Higher accuracy
  • amazon/chronos-t5-large - Best accuracy, slower

Change the model_name variable in chronos_server.py.

Configuration Parameters

In System Messages

  • prediction_length: N - Number of future steps to forecast (default: 12)
  • num_samples: N - Number of sample paths to generate (default: 20)

Example with Parameters

System: prediction_length: 6
System: num_samples: 50

User: [1.2, 1.5, 1.3, 1.8, 1.6, 2.1, 2.3, 2.0, 2.5, 2.8]

Troubleshooting

Model Download Issues

If the model fails to download, ensure you have internet connectivity and enough disk space (~200MB for the small model).

GPU Not Detected

The server will automatically fall back to CPU. Check your PyTorch CUDA installation if you have a GPU.

Port Already in Use

Change the port in chronos_server.py (last line) from 8000 to another port.

LM Studio Connection Failed

Ensure the Chronos server is running before trying to connect from LM Studio.

Technical Details

  • Architecture: T5-based language model adapted for time series
  • Training: Pretrained on diverse time series datasets
  • Inference: Zero-shot forecasting (no fine-tuning needed)
  • Output: Probabilistic forecasts with confidence intervals

Resources

About

Amazon Chronos-2 time series forecasting with OpenAI-compatible API for LM Studio

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors