LongCut logo

Install and Run locally Timestral - Mistral AI's Forecaster

By Aleksandar Haber PhD

Summary

Topics Covered

  • Forecasts Without Uncertainty Are Only Half the Story
  • Classical Refitting Gives Way to Zero-Shot Transformers
  • A Four-Step Local Workflow: Cache, Test, Forecast, Plot

Full Transcript

Hello everyone and welcome to machine learning and AI tutorials.

In this tutorial, we explain how to install and run locally the Time Stral AI model.

Time Stral AI model is the newest AI model published by Mistral AI.

So, let's immediately start.

This model is used for time series forecasting and prediction.

And over here, before we explain the model, let's provide a simple demo.

Namely, over here you can see a simple sinusoidal signal that's corrupted by noise.

And our task is to predict the signal starting from this sample 1,000 and to predict 96 steps in the future.

And you can see the results.

The results are presented by this orange line.

Not only that this model predicts the time series behavior, it also gives the confidence intervals.

This model can be very useful for stock prediction.

And over here, you can see the Python script that I created that demonstrates how to use this model.

In this video tutorial, I will thoroughly explain how to install and run this model locally. Okay, let's

start with the explanations.

First of all, we provide a brief introduction to Time Stral.

Mistral AI's Time Stral is a family of compact time series foundation models ranging from 5 million to 209 million

parameters. It is designed for zero-shot

parameters. It is designed for zero-shot forecasting delivering leading performance across major public benchmarks without requiring domain-specific training.

The architecture supports context lengths up to 32,000 time steps to capture complex long-term historical patterns.

Let's briefly talk about core capabilities.

Instead of single-point predictions, TimeSformer generates probabilistic forecasts across multiple quantiles for robust uncertainty estimation.

It natively supports past-only and known future covariates to incorporate external driving factors into predictions.

The lightweight models run efficiently on consumer GPUs or CPUs using PyTorch and the official Python inference library.

Developers can easily load checkpoints like TimeSformer 209M, which I will be using in this video tutorial, using Hugging Face integration by the TimeSformer using the TimeSformer

Forecaster class. Passing historical

Forecaster class. Passing historical context arrays allow you to predict future horizons and extract median trends along with confidence bounds, which I showed at the beginning.

Visualizing the outputs with matplotlib provides a clear way to inspect both expected values and risk boundaries.

Let's briefly talk about TimeSformer and let's compare it with classical time series models.

While classical models like ARX or autoregressive with exogenous inputs rely on strict linear assumptions and must be refitted from scratch on every

new data set, TimeSformer is a deep transformer-based foundation model. It

processes long-range contexts up to 32,000 time steps to model complex non-linear patterns using patch-based attention.

TimeSformer performs instant zero-shot forecasting on unseen time series without requiring gradient updates or local parameter fitting. Furthermore, it

natively handles past and future covariates while predicting 21 distinct quantiles to capture realistic non-parametric uncertainty.

Next, we explain how to install and run this model locally.

First of all, open a terminal.

And over here, before you install any program or package on a Linux Ubuntu system, you need to update and upgrade your system. To do that, you need to run

your system. To do that, you need to run these two commands.

I'm not going to run them since I often update and upgrade my system. However, I

strongly suggest that you do that. Next,

you you have to make sure that you have Python, Python pip, Python 3 virtual environment creation command, and git on your system. You can do that by running

your system. You can do that by running this command and then enter your password.

Next, let's create a folder called timexture local, and let's navigate to this folder. Inside of this

folder, let's create a Python virtual environment.

And next, let's activate this Python virtual environment.

Good.

Next let's install pip and let's install the library

from the timexture git repository.

So, what will happen over here? We're

not only going to install a single library, we're going to install a bunch of libraries that you can see, or better to say packages to be more precise, that will be necessary to run

this model. And it's going to take a

this model. And it's going to take a while to do so.

After we do that, we also need to install Matplotlib such that we can visualize predictions of time series.

Okay.

This will take a while, so consequently be patient.

Finally, let's install Matplotlib library.

After we do that, let's create a test code.

Okay.

So, let's wait for a while.

To create the test code, we are going to use use Visual Studio Code. However, you

can also use any other Python editor you have. If you want to learn how to install Visual Studio Code on a Linux Ubuntu computer, then on my YouTube page there a number of tutorials.

To start Visual Studio Code, we need to type this.

And over here, let's create a new file and let's call the file as test.py.

Let's save it in the same workspace folder and over here, I will simply copy and paste the code that I wrote previously.

Okay, so let's do this. Here's the code.

I will simply copy and paste it here.

And let's briefly explain this code.

First of all, we need to install the necessary packages. We need NumPy

necessary packages. We need NumPy or better to say import to be more precise. We need NumPy, Matplotlib and

precise. We need NumPy, Matplotlib and from TimeSynth, we are importing TimeSynth forecaster.

Then, we need to load the TimeSynth model directly onto the GPU. If this is the first time you're running this code, then the first step is to

download this model. On the other hand, the second time you're running this model, the model will be cached on your local disk and it will be loaded locally.

Here, we need to generate a realistic and time series. So, what do I do over here?

time series. So, what do I do over here?

I'm basically generating a sine signal and on top of that signal I'm adding trend and seasonality as well as noise.

And that's it.

Next, I need to run my forecast.

Here I'm simply running the forecast specifying the prediction length length.

And after I do that, I need to extract, convert to CPU, and squeeze dimensions for plotting.

Okay.

Then I need to create a time axis indices for plotting.

And then finally, I'm plotting the historical context and the probabilistic forecast. You can see it over here.

forecast. You can see it over here.

I'm adding bunch of things to my plot, title, X label, Y label, legend, and grid. And finally, I'm saving the plot

grid. And finally, I'm saving the plot to the disk. Here I suggest you to use 600 DPI. That is dots per inch. And

600 DPI. That is dots per inch. And

that's it. Simple as that.

Let's save this file.

And I will provide the link to this file in the description below. And finally,

let's make sure that the file is here.

Here it is. And let's run it by typing python 3 test.py. And here it is.

So, now you can see how the forecast is running on GPU.

And the plot is saved over here.

And here it is. So, let's open this file.

Let's go to the home folder. Here it is.

And here's our plot.

Great. Awesome.

Good. Let's now more deeply investigate what's happening behind the scenes. Here

I'm going to open a new terminal and in this terminal install NVTOP. You can type in

NVTOP. You can type in sudo apt install NVTOP. NVTOP is a simple program for displaying the GPU processor memory

usage.

Enter your password.

And let's run NVTop.

And you will see this. You will see the GPU and you will see the memory usage.

And let's run the model once again.

However, this time let's see what's happening behind the scenes.

We can immediately see that the model is being loaded in GPU memory.

And literally in 1 second everything is being computed. That's it. Let's run it

being computed. That's it. Let's run it once again. Let's see what's happening.

once again. Let's see what's happening.

[snorts] You can see the model is being loaded and you can see how fast the prediction is being performed.

Okay, that's all for today. I hope that you like this video. If you like the videos I'm creating, please press the like and subscribe buttons and see you in the next video tutorial.

Loading...

Loading video analysis...