Skip to content

fix: use numpy reshape instead of keras.ops.reshape in SequenceEstimator#10

Merged
jrosenfeld13 merged 1 commit intomainfrom
fix/torch-backend-cuda-tensor-issue
Jan 24, 2026
Merged

fix: use numpy reshape instead of keras.ops.reshape in SequenceEstimator#10
jrosenfeld13 merged 1 commit intomainfrom
fix/torch-backend-cuda-tensor-issue

Conversation

@jrosenfeld13
Copy link
Contributor

@jrosenfeld13 jrosenfeld13 commented Jan 24, 2026

Fixes #5 - torch backend LSTMRegressor fit fails with CUDA tensors.

The issue was that ops.reshape() converts numpy arrays to backend tensors. With torch backend + CUDA GPU, this creates CUDA tensors that numpy.asarray() cannot convert back, causing the error: "can't convert cuda:0 device type tensor to numpy"

The fix uses numpy's native reshape() method instead, keeping data as numpy arrays until model.fit() where Keras handles the conversion internally. This matches the pattern used by other estimators (dense.py, autoencoder.py, tree.py) which don't use keras.ops for preprocessing.


Note

Replaces Keras ops.reshape with NumPy reshape in SequenceEstimator to keep data as NumPy arrays during preprocessing and avoid unintended backend tensor conversion (e.g., CUDA tensors with Torch backend).

  • Update _reshape to call X.reshape(...) and similarly for validation data; return unchanged API
  • Remove unused keras.ops import
  • Keeps prediction path intact; only reshaping logic changed prior to model.fit()

Written by Cursor Bugbot for commit fa223a9. This will update automatically on new commits. Configure here.

Fixes #5 - torch backend LSTMRegressor fit fails with CUDA tensors.

The issue was that `ops.reshape()` converts numpy arrays to backend
tensors. With torch backend + CUDA GPU, this creates CUDA tensors that
`numpy.asarray()` cannot convert back, causing the error:
"can't convert cuda:0 device type tensor to numpy"

The fix uses numpy's native `reshape()` method instead, keeping data as
numpy arrays until `model.fit()` where Keras handles the conversion
internally. This matches the pattern used by other estimators (dense.py,
autoencoder.py, tree.py) which don't use keras.ops for preprocessing.
@jrosenfeld13 jrosenfeld13 merged commit 45274f7 into main Jan 24, 2026
4 checks passed
@jrosenfeld13 jrosenfeld13 deleted the fix/torch-backend-cuda-tensor-issue branch January 24, 2026 21:40
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.

torch backend LSTMRegressor fit fails

1 participant