Skip to content

Commit 63f00ea

Browse files
committed
feat(autoformer): Improve ValueError for insufficient sequence length
1 parent 0b6229d commit 63f00ea

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/transformers/models/autoformer/modeling_autoformer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,12 +1303,15 @@ def get_lagged_subsequences(
13031303
# calculates the indices of the lags by subtracting the shift value from the given lags_sequence
13041304
indices = [lag - shift for lag in self.config.lags_sequence]
13051305

1306-
# checks if the maximum lag plus the length of the subsequences exceeds the length of the input sequence
13071306
sequence_length = sequence.shape[1]
1308-
if max(indices) + subsequences_length > sequence_length:
1307+
# We need to check if the sequence is long enough to create the lags
1308+
min_len_for_lags = max(self.config.lags_sequence) + subsequences_length
1309+
if sequence_length < min_len_for_lags:
13091310
raise ValueError(
1310-
f"lags cannot go further than history length, found lag {max(indices)} "
1311-
f"while history length is only {sequence_length}"
1311+
"The length of the 'past_values' tensor is too short for the configured lags. "
1312+
f"To use lags up to {max(self.config.lags_sequence)}, the input sequence length needs to be at least "
1313+
f"{min_len_for_lags} (max_lag + context_length + prediction_length), but it is only "
1314+
f"{sequence_length}."
13121315
)
13131316

13141317
# extracts the lagged subsequences from the input sequence using the calculated indices

0 commit comments

Comments
 (0)