[Relax][Frontend] Add TFLite Frontend Support for CONV_3D_TRANSPOSE#19530
Conversation
This commit adds support for the CONV_3D_TRANSPOSE operator in the Relax TFLite frontend. Key implementations: - Registered CONV_3D_TRANSPOSE to the TFLite op map. - Implemented convert_conv3d_transpose which shares Conv3DOptions with regular Conv3D but handles the distinct tensor input layout [output_shape, weight, data, bias] and the DHWOI kernel layout. - Added calculation for SAME padding that correctly handles transposed convolution semantics, computing padding and output_padding based on dilated kernel and stride sizes. - Added comprehensive unit tests for valid and same padding in test_frontend_tflite.py.
There was a problem hiding this comment.
Code Review
This pull request introduces support for the CONV_3D_TRANSPOSE operator in the TFLite frontend for Relax, including the implementation of the conversion logic and associated unit tests for different padding modes. The feedback recommends minor code cleanups, such as using underscores for unused variables and adopting relax.op.nn.bias_add for better consistency with other convolution implementations.
| padding = conv3d_options.Padding() | ||
| fused_activation_fn = conv3d_options.FusedActivationFunction() | ||
|
|
||
| _, input_d, input_h, input_w, input_c = to_int_list(self.get_tensor_shape(input_tensor)) |
There was a problem hiding this comment.
The variables input_d, input_h, and input_w are extracted from the input tensor shape but are not used in the subsequent logic, including the padding calculations. For clarity and to avoid unused variable warnings, they can be replaced with underscores.
| _, input_d, input_h, input_w, input_c = to_int_list(self.get_tensor_shape(input_tensor)) | |
| _, _, _, _, input_c = to_int_list(self.get_tensor_shape(input_tensor)) |
| dtype=bias_tensor_type_str, | ||
| source_name=bias_tensor.tensor.Name(), | ||
| ) | ||
| out = relax.op.add(out, bias_expr) |
There was a problem hiding this comment.
While relax.op.add works for adding bias due to broadcasting, using relax.op.nn.bias_add is generally preferred for neural network layers as it explicitly targets the channel dimension and is more robust to layout variations. This would also be consistent with the implementation of convert_transpose_conv (2D) in this frontend.
| out = relax.op.add(out, bias_expr) | |
| out = relax.op.nn.bias_add(out, bias_expr, axis=4) |
This commit adds support for the CONV_3D_TRANSPOSE operator in the Relax TFLite frontend.
Key implementations:
Testing:
python3 -m pytest tests/python/relax/test_frontend_tflite.py -k "test_conv3d_transpose"Related to: #19519