Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conv3DTranspose issue with torch backend padding arguments (padding=same) and output_padding=1) lead to a Torch output_padding (1) that is greater than strides (1). #20949

Open
pure-rgb opened this issue Feb 23, 2025 · 2 comments
Assignees
Labels
backend:torch keras-team-review-pending Pending review by a Keras team member. type:Bug

Comments

@pure-rgb
Copy link

I ended up with the following issue keras-team/keras-core#774

Currently a warning is given but what is the solution or workaround?

ValueError: Exception encountered when calling Conv3DTranspose.call().

The padding arguments (padding=same) and output_padding=1) lead to a Torch output_padding (1) that is greater than strides (1). This is not supported. You can change the padding arguments, kernel or stride, or run on another backend.

Arguments received by Conv3DTranspose.call():
• inputs=torch.Tensor(shape=torch.Size([16, 96, 6, 6, 128]), dtype=float32)

@dhantule
Copy link
Contributor

Hi @pure-rgb, thanks for reporting this. Could you provide some reproducible code?

@pure-rgb
Copy link
Author

@dhantule

Sample code.

import  os
os.environ["KERAS_BACKEND"] = "torch"

import numpy as np
import keras

a = np.ones((1, 8, 8, 8, 16), dtype=np.float32)
x = keras.layers.Conv3DTranspose(
    32,
    kernel_size=2,
    strides=1,
    padding='same',
)
output = x(a)
print(output.shape)

This works in tf and jax, output: (1, 8, 8, 8, 32). But in torch backend, it gives

/opt/conda/lib/python3.10/site-packages/keras/src/backend/common/backend_utils.py:91: UserWarning: You might experience inconsistencies across backends when calling conv transpose with kernel_size=2, stride=1, dilation_rate=1, padding=same, output_padding=1.
  warnings.warn(
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 8
      1 a = np.ones((1, 8, 8, 8, 16), dtype=np.float32)
      2 x = keras.layers.Conv3DTranspose(
      3     32,
      4     kernel_size=2,
      5     strides=1,
      6     padding='same',
      7 )
----> 8 output = x(a)
      9 print(output.shape)

File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    119     filtered_tb = _process_traceback_frames(e.__traceback__)
    120     # To get the full stack trace, call:
    121     # `keras.config.disable_traceback_filtering()`
--> 122     raise e.with_traceback(filtered_tb) from None
    123 finally:
    124     del filtered_tb

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1517 else:
-> 1518     return self._call_impl(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
   1522 # If we don't have any hooks, we want to skip the rest of the logic in
   1523 # this function, and just call forward.
   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1525         or _global_backward_pre_hooks or _global_backward_hooks
   1526         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527     return forward_call(*args, **kwargs)
   1529 try:
   1530     result = None

ValueError: Exception encountered when calling Conv3DTranspose.call().

The padding arguments (padding=same) and output_padding=1) lead to a Torch output_padding (1) that is greater than strides (1). This is not supported. You can change the padding arguments, kernel or stride, or run on another backend. 

Arguments received by Conv3DTranspose.call():
  • inputs=torch.Tensor(shape=torch.Size([1, 8, 8, 8, 16]), dtype=float32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:torch keras-team-review-pending Pending review by a Keras team member. type:Bug
Projects
None yet
Development

No branches or pull requests

4 participants