Why do my LSTM multi-step forecasts explode, despite low MAPE on validation set (single-step) on very simple linear trend?

Example below is self-complete.

I have recently switched from using darts (where forecast horizons etc) are all handled for me to keras because I wanted to integrate with other libraries such as shap etc.

As part of attempting to setup a multi-step forecast, I have created a very simple linear function to ensure I understand all the basic components associated with the keras model pipeline. Model performance on single step predictions of the validation set is R^2: 0.943, MAPE: 0.102%. I obviously expect performance to degrade with multi-step forecasts, especially since the input size is smaller than the number of steps I hope to perform. However, this paper (scroll to highlighted text created by link), uses 7 days input periods to forecast one day ahead, and autoregressively generates 28 forecasts using LSTM cells on data far noiser than a linear trend.

Can anyone spot the basic mistake I have made somewhere?

import numpy as np
import matplotlib.pyplot as plt

import keras

from sklearn.metrics import r2_score, mean_absolute_percentage_error

horizon = 1
forecast_steps = 28
input_size = 7
batch_size = 32
training_size = 5000
linear = np.arange(training_size) / training_size
val = (np.arange(100) + training_size) / training_size
dataset_train = keras.preprocessing.timeseries_dataset_from_array(linear[:-horizon], linear[input_size:], sequence_length=input_size, batch_size=batch_size)
dataset_val = keras.preprocessing.timeseries_dataset_from_array(val[:-horizon], val[input_size:], sequence_length=input_size, batch_size=batch_size)

model = keras.models.Sequential()
model.add(keras.layers.Input(shape=(input_size, 1), dtype='float64', batch_size=batch_size))
model.add(keras.layers.LSTM(units=1, dtype='float64'))
model.add(keras.layers.Dense(1, dtype='float64'))

model.compile(optimizer=keras.optimizers.Adam(learning_rate=1e-3), loss="mse")

history = model.fit(
    dataset_train,
    epochs=500,
    validation_data=dataset_val,
    callbacks=[keras.callbacks.EarlyStopping(monitor="val_loss", min_delta=0, patience=7, mode='min')],
)

Multi-Step Forecast:

last_steps = np.zeros((1, input_size))
last_steps[0, :] = linear[:input_size]
pred = np.zeros(28)

for x, y in dataset_train.take(1):
    for ii in range(28):
        pred[ii] = model.predict(last_steps, verbose=False, batch_size=1)[0][0]
        new_last_steps = np.zeros((1, input_size))
        new_last_steps[0, :-1] = last_steps[0, 1:]
        new_last_steps[0, -1] = pred[ii]
        last_steps[:] = new_last_steps[:]

plt.plot(pred, 'go')
plt.plot(linear[input_size: input_size + forecast_steps])

Single Step Model Performance Evaluation:

train_pred = model.predict(dataset_train)
plt.plot(linear)
plt.plot(np.arange(len(train_pred)) + input_size, train_pred)
plt.show()

print(r2_score(linear[input_size:], train_pred))
print(mean_absolute_percentage_error(linear[input_size:], train_pred) * 100)

val_pred = model.predict(dataset_val)
plt.plot(val)
plt.plot(np.arange(len(val_pred)) + input_size, val_pred)
plt.show()

print(r2_score(val[input_size:], val_pred))
print(mean_absolute_percentage_error(val[input_size:], val_pred) * 100)

Questions Reviewed:

Single to Multi-Step – Accepted Answer suggested out of the box solutions I have used before and am trying to replace
Broken Multi-Step – I attempted fixes provided and they had no impact on performance

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật