timesfm 1.0 200m

google

Introduction

TimesFM (Time Series Foundation Model) is a pretrained model developed by Google Research for time-series forecasting. It is designed to perform univariate time series forecasting with specific context and horizon lengths. The model is a decoder-only architecture, focusing on point forecasts with an experimental feature for quantile forecasts.

Architecture

TimesFM operates using a decoder-only architecture that accommodates univariate time series data. It employs context lengths up to 512 time points and flexible horizon lengths, maintaining the same frequency for both context and horizon. The model requires contiguous context data without gaps and supports an optional frequency indicator but is not designed for probabilistic forecasts.

Training

The model training focused on point forecasts with experimental quantile heads, which have not been fully calibrated after pretraining. The frequency indicator is a categorical value that helps the model handle different granularity levels in time series data.

Guide: Running Locally

Basic Steps

  1. Installation: Follow the instructions on the TimesFM GitHub repository to install the necessary libraries for model inference. Note that the lingvo dependency does not support ARM architectures, affecting machines with Apple silicon.

  2. Initialize the Model: Load the model using the following code snippet:

    import timesfm
    
    tfm = timesfm.TimesFm(
        context_len=<context>,
        horizon_len=<horizon>,
        input_patch_len=32,
        output_patch_len=128,
        num_layers=20,
        model_dims=1280,
        backend=<backend>,
    )
    tfm.load_from_checkpoint(repo_id="google/timesfm-1.0-200m")
    
  3. Perform Inference: Use either array inputs or pandas dataframes to forecast. Set the frequency using categorical indicators (0, 1, 2) for high, medium, and low frequency time series. For example:

    • Array Input:

      import numpy as np
      forecast_input = [np.sin(np.linspace(0, 20, 100)), np.sin(np.linspace(0, 20, 200)), np.sin(np.linspace(0, 20, 400))]
      frequency_input = [0, 1, 2]
      point_forecast, experimental_quantile_forecast = tfm.forecast(forecast_input, freq=frequency_input)
      
    • Dataframe Input:

      import pandas as pd
      forecast_df = tfm.forecast_on_df(
          inputs=input_df,
          freq="M",  # monthly
          value_name="y",
          num_jobs=-1,
      )
      

Cloud GPUs

Consider using cloud-based GPU services such as AWS, Google Cloud, or Azure for more efficient model training and inference, especially when working with large datasets.

License

TimesFM is released under the Apache 2.0 License. This indicates that users are free to use, modify, and distribute the software, provided that any copies or substantial portions of the software include the original copyright notice and the license.

More Related APIs in Time Series Forecasting