An out-of-sample forecast predicts future time steps that were excluded from the model input or fitting data, rather than reproducing observations already seen. section 4.2.2
Eight-week store-sales forecast
Lag-Llama produces out-of-sample predictions for the next eight weeks of sales at four Walmart stores, including 95% prediction intervals.
Listing 4.2 Defining a function to get predictions from Lag-Llama
def get_lag_llama_predictions(dataset,
prediction_length,
device,
context_length=32,
num_samples=100):
ckpt = torch.load("lag-llama.ckpt",
➥map_location=device) #1
estimator_args = ckpt["hyper_parameters"]["model_kwargs"]
estimator = LagLlamaEstimator(
ckpt_path="lag-llama.ckpt",
prediction_length=prediction_length,
context_length=context_length,
input_size=estimator_args["input_size"], #2
n_layer=estimator_args["n_layer"],
n_embd_per_head=estimator_args["n_embd_per_head"],
n_head=estimator_args["n_head"],
scaling=estimator_args["scaling"],
time_feat=estimator_args["time_feat"],
batch_size=1,
num_parallel_samples=num_samples,
device=device,
)
lightning_module =
➥estimator.create_lightning_module() #3
transformation =
➥estimator.create_transformation() #4
predictor = estimator.create_predictor(
➥transformation, lightning_module) #5
forecasts = predictor.predict( #6
dataset=dataset,
)
forecasts = list(forecasts) #7
return forecasts
Inspect the prediction function that loads Lag-Llama parameters, configures the context and horizon, and returns forecast samples. section 4.2.2

