Temporal Fusion Transformer predict error

Hello everyone,

I’m currently working with the Temporal Fusion Transformer (TFT) and facing a dimension mismatch issue. My dataset contains ~5,000 unique combinations (e.g., SKU, store, etc.) over 24 timesteps (2 years of monthly data). My goal is to forecast the next month for each combination.

When I calculate metrics like the Mean Absolute Error (MAE) using Baseline().predict() with return_y=True, I encounter the following error:

RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 1280 but got size 641 for tensor number 4 in the list.

Interestingly, if I set return_y=False, the code runs without issues. Below is the setup I’ve been using:

# Create validation set (predict=True) to predict the last max_prediction_length points in time for each series  
validation = TimeSeriesDataSet.from_dataset(training, df, predict=True, stop_randomization=True)  

# Create dataloaders for the model  
batch_size = 128  # Set this between 32 to 128  
train_dataloader = training.to_dataloader(train=True, batch_size=batch_size, num_workers=0)  
val_dataloader = validation.to_dataloader(train=False, batch_size=batch_size * 10, num_workers=0, drop_last=True)  

# Define baseline predictions  
baseline_predictions = Baseline().predict(val_dataloader, return_y=True)  

# Calculate MAE  
MAE()(baseline_predictions.output, baseline_predictions.y)  

Here are the parameters I’ve configured:

  • max_prediction_length = 2
  • max_encoder_length = 12

It appears to be a dimension mismatch issue, but I’m not sure how to address it. Has anyone encountered a similar issue or can suggest a solution?

Thank you in advance for your help!

Do you know what the expectations are from MAE() for the shape of its inputs?

You mention that the code runs without issues when return_y=False, would baseline_predictions.y still passed to MAE() in that case?