time-series-foundation-models / lag-llama

Lag-Llama: Towards Foundation Models for Probabilistic Time Series Forecasting
Apache License 2.0
1.09k stars 121 forks source link

random seed, how to freeze predictions #26

Closed m6129 closed 2 months ago

m6129 commented 3 months ago

Hello. How do I freeze the predictions? I have a different prediction every time.

ashok-arjun commented 3 months ago

Hi, as it is a probabilistic forecasting model, it is expected to give new predictions when you're sampling every time.

If you'd like to have the same samples predicted every time, can you maybe try using a random seed just before sampling?

If that doesn't work, I'm happy to take a look at this again in 2 weeks (I'm busy with releasing everything else for the next 2 weeks).

Let me know,

Thanks Arjun

m6129 commented 3 months ago

Thanks!! By how using a random seed just before sampling?

ashok-arjun commented 3 months ago

I believe you've to add the random seed function before this line.

I recommend seeding everything (random, torch, numpy etc.). I usually use this (but I haven't tested it for your usecase):

import os
import random
import numpy as np
import torch

def set_seed(seed, deterministic=True):
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed(seed)
        torch.cuda.manual_seed_all(seed)
        torch.backends.cudnn.deterministic = deterministic
        torch.backends.cudnn.benchmark = False
    os.environ["PYTHONHASHSEED"] = str(seed)
ashok-arjun commented 2 months ago

Hi @m6129 is this resolved?

m6129 commented 2 months ago

Hi @m6129 is this resolved?

Yes, Thanks! it helped