Skip to content

Commit 91b00a1

Browse files
Automated g4 rollback of changelist 166276461
PiperOrigin-RevId: 166305887
1 parent 2f531b5 commit 91b00a1

19 files changed

+714
-1730
lines changed

tensorflow/contrib/fused_conv/BUILD

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ tf_kernel_library(
6060
srcs = [
6161
"kernels/fused_conv2d_bias_activation_op.cc",
6262
"kernels/fused_conv2d_bias_activation_op.h",
63-
"kernels/fused_conv_ops_gpu.h",
6463
],
6564
prefix = "fused_conv2d_bias_activation_op",
6665
deps = [
6766
"//tensorflow/core:framework",
6867
"//tensorflow/core:lib",
6968
"//tensorflow/core:lib_proto_parsing",
70-
"//tensorflow/core:stream_executor",
7169
"//tensorflow/core/kernels:bounds_check_lib",
7270
"//tensorflow/core/kernels:conv_2d_hdrs",
7371
"//tensorflow/core/kernels:conv_ops_gpu_hdrs",
@@ -83,7 +81,6 @@ tf_custom_op_library(
8381
srcs = [
8482
"kernels/fused_conv2d_bias_activation_op.cc",
8583
"kernels/fused_conv2d_bias_activation_op.h",
86-
"kernels/fused_conv_ops_gpu.h",
8784
"ops/fused_conv2d_bias_activation_op.cc",
8885
],
8986
deps = [
@@ -97,8 +94,12 @@ tf_custom_op_library(
9794
)
9895

9996
tf_gen_op_libs(
100-
op_lib_names = ["fused_conv2d_bias_activation_op"],
101-
deps = ["//tensorflow/core:lib_proto_parsing"],
97+
op_lib_names = [
98+
"fused_conv2d_bias_activation_op",
99+
],
100+
deps = [
101+
"//tensorflow/core:lib_proto_parsing",
102+
],
102103
)
103104

104105
tf_gen_op_wrapper_py(
@@ -108,7 +109,7 @@ tf_gen_op_wrapper_py(
108109

109110
cuda_py_test(
110111
name = "fused_conv2d_bias_activation_op_test",
111-
size = "large",
112+
size = "small",
112113
srcs = ["python/ops/fused_conv2d_bias_activation_op_test.py"],
113114
additional_deps = [
114115
":fused_conv_py",

tensorflow/contrib/fused_conv/kernels/fused_conv2d_bias_activation_op.cc

Lines changed: 297 additions & 363 deletions
Large diffs are not rendered by default.

tensorflow/contrib/fused_conv/kernels/fused_conv2d_bias_activation_op.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
#if GOOGLE_CUDA
2626
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
27-
#include "tensorflow/contrib/fused_conv/kernels/fused_conv_ops_gpu.h"
27+
#include "tensorflow/core/kernels/conv_ops_gpu.h"
2828
#include "tensorflow/core/platform/stream_executor.h"
2929
#endif // GOOGLE_CUDA
3030

@@ -33,30 +33,27 @@ namespace tensorflow {
3333
// Forward declaration.
3434
class OpKernelContext;
3535

36-
template <typename Device, typename T, typename BiasType, typename ScaleType>
36+
template <typename Device, typename T>
3737
class LaunchFusedConv2DBiasActivationOp {
3838
public:
3939
void launch(OpKernelContext* ctx, bool cudnn_use_autotune,
40-
const Tensor& conv_input, ScaleType conv_input_scale,
41-
const Tensor& filter, int32 row_stride, int32 col_stride,
42-
const Eigen::PaddingType& padding, const Tensor& side_input,
43-
ScaleType side_input_scale, const Tensor& bias,
44-
ActivationMode activation_mode, TensorFormat data_format,
45-
FilterTensorFormat filter_format, Tensor* output);
40+
const Tensor& input, const Tensor& filter, int row_stride,
41+
int col_stride, const Tensor& bias,
42+
const ActivationMode& activation_mode,
43+
const Eigen::PaddingType& padding, TensorFormat data_format,
44+
Tensor* output);
4645
};
4746

4847
#ifdef GOOGLE_CUDA
49-
template <typename T, typename BiasType, typename ScaleType>
50-
class LaunchFusedConv2DBiasActivationOp<Eigen::GpuDevice, T, BiasType,
51-
ScaleType> {
48+
template <typename T>
49+
class LaunchFusedConv2DBiasActivationOp<Eigen::GpuDevice, T> {
5250
public:
5351
void launch(OpKernelContext* ctx, bool cudnn_use_autotune,
54-
const Tensor& conv_input, ScaleType conv_input_scale,
55-
const Tensor& filter, int32 row_stride, int32 col_stride,
56-
const Eigen::PaddingType& padding, const Tensor& side_input,
57-
ScaleType side_input_scale, const Tensor& bias,
58-
ActivationMode activation_mode, TensorFormat data_format,
59-
FilterTensorFormat filter_format, Tensor* output);
52+
const Tensor& input, const Tensor& filter, int32 row_stride,
53+
int32 col_stride, const Tensor& bias,
54+
const ActivationMode& activation_mode,
55+
const Eigen::PaddingType& padding, TensorFormat data_format,
56+
Tensor* output);
6057
};
6158
#endif // GOOGLE_CUDA
6259

tensorflow/contrib/fused_conv/kernels/fused_conv_ops_gpu.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

tensorflow/contrib/fused_conv/ops/fused_conv2d_bias_activation_op.cc

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,73 +33,40 @@ string GetAllActivationModeAttrString() { return "activation_mode: {'Relu'}"; }
3333
} // namespace
3434

3535
// --------------------------------------------------------------------------
36-
37-
// TODO(pauldonnelly): Add support for double inputs and scales to this Op,
38-
// (currently Attr does not support double).
39-
4036
REGISTER_OP("FusedConv2DBiasActivation")
41-
.Input("conv_input: T")
37+
.Input("input: T")
4238
.Input("filter: T")
43-
.Input("bias: Tbias")
44-
.Input("side_input: T")
39+
.Input("bias: T")
4540
.Output("output: T")
46-
.Attr("T: {float, half, qint8}")
47-
.Attr("Tbias: {float, half}")
48-
.Attr("conv_input_scale: float = 1.0")
49-
.Attr("side_input_scale: float = 0.0")
41+
.Attr("T: {float}")
5042
.Attr("strides: list(int)")
5143
.Attr(GetPaddingAttrString())
52-
.Attr("data_format: {'NHWC', 'NCHW', 'NCHW_VECT_C'} = 'NHWC'")
53-
.Attr("filter_format: {'HWIO', 'OIHW', 'OIHW_VECT_I'} = 'HWIO'")
54-
.Attr("activation_mode: {'Relu'} = 'Relu'")
44+
.Attr(GetConvnetDataFormatAttrString())
45+
.Attr(GetAllActivationModeAttrString())
5546
.SetShapeFn(shape_inference::FusedConvBiasActivationShape)
5647
.Doc(R"doc(
57-
Computes a fused kernel which implements: 2-D convolution, adds side input,
58-
with separate scaling on convolution and side inputs, then adds bias and
59-
applies the RELU activation function to the result. Supports both float and
60-
qint8 data formats. In the case of qint8, the output is clipped to [0..127].
48+
Computes a fused 2-D convolution, adds bias, and applies an activation function
49+
on the output given 4-D `input`, 4-D `filter`, 1-D `bias` tensors and an activation mode.
6150
62-
conv_input: A tensor with format as specified by `data_format` (see below).
63-
filter: A tensor with format depending on `data_format` as follows:
64-
"NHWC", "NCHW":
65-
`float [ filter_height, filter_width, in_channels, out_channels ]`
66-
"NCHW_VECT_C":
67-
`qint8 [ out_channels, in_channels, filter_height, filter_width ]`
68-
bias: 1-D float tensor with size matching the `out_channels` dimension of
69-
`filter`.
70-
Note: this tensor is still float, even if other inputs are qint8.
71-
side_input: A tensor with format as specified by `data_format` (see below).
72-
This tensor will be ignored and can be [] if side_input_scale == 0.
73-
Otherwise, the size of each dimension must match the `output` tensor.
74-
output: A tensor with format as specified by `data_format` (see below).
75-
The dimension sizes are determined automatically based on other inputs
76-
and attributes.
77-
T: The element data type of `conv_input`, `side_input` and `output` tensors.
78-
Note: must match with the `data_format`.
79-
Tbias: The element data type of `bias`.
80-
conv_input_scale: scalar float value to be multiplied by `conv_input`.
81-
(conceptually.. in reality it is applied after convolution).
82-
side_input_scale: scalar float value to be multiplied by `side_input`.
51+
input: A 4-D tensor. The dimension order is interpreted according to the value
52+
of `data_format`, see below for details.
53+
filter: A 4-D tensor of shape
54+
`[filter_height, filter_width, in_channels, out_channels]`
55+
bias: 1-D with size of the `out_channels` dimension in filter.
56+
output: A 4-D tensor. The dimension order is determined by the value of
57+
`data_format`, see below for details.
58+
T: The data type for the elements of input, filter, bias, and output Tensors.
8359
strides: 1-D tensor of length 4. The stride of the sliding window for each
8460
dimension of `input`. The dimension order is determined by the value of
8561
`data_format`, see below for details.
86-
Note: the stride for batch and channel dimensions must be 1.
8762
padding: The type of padding algorithm to use.
88-
data_format: A string specifying the data format of `conv_input`,
89-
`side_input` and `output` tensors with the following options:
90-
"NHWC": `float [ batch, height, width, channels ]`
91-
"NCHW": `float [ batch, channels, height, width ]`
92-
"NCHW_VECT_C":
93-
`qint8 [ batch, channels / 4, height, width, channels % 4 ]`
94-
Note: for "NCHW_VECT_C", `channels` must be a multiple of 4.
95-
filter_format: A string specifying the data format of `filter`,
96-
"HWIO": `float [ kernel_height, kernel_width, input_channels,
97-
output_channels ]`
98-
"OIHW_VECT_I":
99-
`qint8 [ output_channels, input_channels / 4,
100-
kernel_height, kernel_width, input_channels % 4 ]`
101-
activation_mode: The activation applied to the output.
102-
Currently must be "Relu".
63+
data_format: Specify the data format of the input and output data. With the
64+
default format "NHWC", the data is stored in the order of:
65+
[batch, height, width, channels].
66+
Alternatively, the format could be "NCHW", the data storage order of:
67+
[batch, channels, height, width].
68+
activation_mode: Specify the activation function to apply to the output tensor
69+
of bias add. Currently only supports "Relu".
10370
)doc");
10471

10572
} // namespace tensorflow

tensorflow/contrib/fused_conv/python/ops/fused_conv2d_bias_activation_op.py

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,83 +26,62 @@
2626
resource_loader.get_path_to_datafile("_fused_conv2d_bias_activation_op.so"))
2727

2828

29-
# pylint: disable=redefined-builtin
30-
def fused_conv2d_bias_activation(conv_input,
31-
filter,
29+
def fused_conv2d_bias_activation(input_tensor,
30+
filter_tensor,
3231
bias,
33-
strides=None,
34-
padding=None,
35-
conv_input_scale=1.0,
36-
side_input_scale=0.0,
37-
side_input=None,
38-
activation_mode="Relu",
32+
strides,
33+
padding,
34+
activation_mode,
3935
data_format=None,
40-
filter_format=None,
4136
name=None):
42-
"""Fused 2D conv, bias and activation with optional side input.
37+
"""Computes a fused 2-D convolution, adds bias, and applies relu.
4338
44-
Computes a fused 2-D convolution scaled by conv_input_scale,
45-
adds an optional side input scaled by side_input_scale, adds biases,
46-
and applies ReLU. As an equation:
47-
output = ReLU(conv_input_scale * Conv(conv_input, filter) +
48-
side_input_scale * side_input + bias)
49-
Note: In int8 mode, The ReLU will clip the output to the range [0..127].
39+
input_tensor: A 4-D tensor. The dimension order is interpreted
40+
according to the value of `data_format`, see below for details.
41+
filter_tensor: A 4-D tensor of shape
42+
`[filter_height, filter_width, in_channels, out_channels]`
43+
bias: 1-D with size of the `out_channels` dimension in filter.
44+
output: A 4-D tensor. The dimension order is determined by the value of
45+
`data_format`, see below for details.
46+
T: The data type for the elements of input, filter, bias, and output
47+
Tensors.
48+
strides: 1-D tensor of length 4. The stride of the sliding window for
49+
each
50+
dimension of `input`. The dimension order is determined by the value
51+
of
52+
`data_format`, see below for details.
53+
padding: The type of padding algorithm to use.
54+
data_format: Specify the data format of the input and output data. With
55+
the
56+
default format "NHWC", the data is stored in the order of:
57+
[batch, height, width, channels].
58+
Alternatively, the format could be "NCHW", the data storage order of:
59+
[batch, channels, height, width].
60+
activation_mode: Specify the activation function to apply to the output
61+
tensor
62+
of bias add. Currently only supports "Relu".
5063
5164
Args:
52-
conv_input: A `Tensor` of the format specified by `data_format`.
53-
filter: A `Tensor` whose format depends on `data_format`:
54-
if `data_format` is "NCHW_VECT_C", filter should be "OIHW_VECT_I"
55-
otherwise, it should be "HWIO" format.
56-
bias: A 1-D `Tensor` of type `float32`, and dimensions equal to the
57-
number of output channels.
58-
strides: A list of 4 `ints` specifying convolution strides.
59-
if `data_format` is "NCHW" or "NCHW_VECT_C", the order should be NCHW.
60-
if `data_format` is "NHWC", the order should be NHWC.
65+
input_tensor: A `Tensor`. Must be one of the following types: `float32`.
66+
filter_tensor: A `Tensor`. Must have the same type as `input`.
67+
bias: A `Tensor`. Must have the same type as `input`.
68+
strides: A list of `ints`.
6169
padding: A `string` from: `"SAME", "VALID"`.
62-
conv_input_scale: A scalar `float32` that will be multiplied by conv_input.
63-
This is optional and defaults to 1. However it should be set to
64-
specify the quantization scale when `data_format` is "NCHW_VECT_C".
65-
side_input_scale: A scalar `float32` that will be multiplied by side_input.
66-
This is optional and defaults to 0.
67-
side_input: A `Tensor` of the format specified by `data_format`.
68-
This is useful for imlementing ResNet blocks.
69-
activation_mode: (optional) currently must be the default "Relu".
70-
Note that in qint8 mode, it also clips to 127, so acts like ReluX.
71-
data_format: Specifies the data format.
72-
Possible values are:
73-
"NHWC" float [batch, height, width, channels]
74-
"NCHW" float [batch, channels, height, width]
75-
"NCHW_VECT_C" qint8 [batch, channels / 4, height, width, channels % 4]
76-
Defaults to `"NHWC"`.
77-
Performance is worst for `"NHWC"` and best for `"NCHW_VECT_C"`.
78-
filter_format: Specifies the filter format.
79-
Possible values are:
80-
"HWIO" float [kernel_height, kernel_width, input_channels,
81-
output_channels ]
82-
"OIHW" float [output_channels, input_channels, kernel_height,
83-
kernel_width ]
84-
"OIHW_VECT_I" qint8 [ output_channels, input_channels / 4,
85-
kernel_height, kernel_width, input_channels % 4 ]
86-
Defaults to `"HWIO"`.
70+
activation_mode: A `string` from: `"Sigmoid", "Relu", "Relu6", "ReluX",
71+
"Tanh", "BandPass"`.
72+
data_format: An optional `string` from: `"NHWC", "NCHW"`. Defaults to
73+
`"NHWC"`.
8774
name: A name for the operation (optional).
8875
8976
Returns:
90-
A `Tensor` of the format specified by `data_format`.
77+
A `Tensor`. Has the same type as `input`.
9178
"""
92-
if strides is None:
93-
strides = [1, 1, 1, 1]
94-
if side_input is None:
95-
side_input = []
9679
return gen_fused_conv2d_bias_activation_op.fused_conv2d_bias_activation(
97-
conv_input,
98-
filter,
99-
bias,
100-
padding=padding,
80+
input=input_tensor,
81+
filter=filter_tensor,
82+
bias=bias,
10183
strides=strides,
102-
conv_input_scale=conv_input_scale,
103-
side_input_scale=side_input_scale,
104-
side_input=side_input,
84+
padding=padding,
10585
activation_mode=activation_mode,
10686
data_format=data_format,
107-
filter_format=filter_format,
10887
name=name)

0 commit comments

Comments
 (0)