Skip to content

fix: TCN model predict crash on single-sample final batch#2172

Open
EdenRochmanSharabi wants to merge 1 commit intomicrosoft:mainfrom
EdenRochmanSharabi:fix/tcn-single-sample-batch
Open

fix: TCN model predict crash on single-sample final batch#2172
EdenRochmanSharabi wants to merge 1 commit intomicrosoft:mainfrom
EdenRochmanSharabi:fix/tcn-single-sample-batch

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown

Summary

Fixes #1752

When the inference dataset size is not evenly divisible by batch size, the last batch has 1 sample. squeeze() produces a 0-d tensor, and after .numpy(), np.concatenate fails because it cannot concatenate 0-d arrays with 1-d arrays.

Changes

  • qlib/contrib/model/pytorch_tcn_ts.py: Wrapped prediction output with np.atleast_1d() before appending to the results list
  • tests/test_tcn_single_sample_batch.py: Tests verifying concatenation works with mixed array dimensions

When the final batch has a single sample, model output becomes a 0-d
numpy array after .cpu().numpy(). np.concatenate cannot mix 0-d and
1-d arrays, causing a crash. Wrap with np.atleast_1d() before
appending to preds list.

Fixes microsoft#1752
@EdenRochmanSharabi
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@EdenRochmanSharabi EdenRochmanSharabi changed the title Fix TCN model predict crash on single-sample final batch fix: TCN model predict crash on single-sample final batch Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qlib/qlib/contrib/model /pytorch_tcn_ts.py error

1 participant