From 8aedf054bfe29b076c6fcb6f54d996fd2752e4de Mon Sep 17 00:00:00 2001 From: reminisce Date: Sat, 24 Jun 2017 22:08:48 -0700 Subject: [PATCH] Remove nnvm namespace for FInferShape, FInferType, and FInferStorageType --- include/mxnet/op_attr_types.h | 40 ++++++++++++ src/c_api/c_api_ndarray.cc | 6 +- src/executor/infer_graph_attr_pass.cc | 2 +- src/io/image_io.cc | 8 +-- src/nnvm/legacy_op_util.cc | 4 +- src/operator/contrib/dequantize.cc | 4 +- src/operator/contrib/quantize.cc | 4 +- src/operator/loss_binary_op.cc | 4 +- src/operator/nn/cast_storage.cc | 6 +- src/operator/optimizer_op.cc | 20 +++--- src/operator/random/multisample_op.cc | 4 +- src/operator/random/sample_multinomial_op.cc | 4 +- src/operator/random/sample_op.cc | 4 +- src/operator/tensor/broadcast_reduce_op.h | 10 +-- .../tensor/broadcast_reduce_op_index.cc | 8 +-- .../tensor/broadcast_reduce_op_value.cc | 8 +-- src/operator/tensor/control_flow_op.cc | 4 +- .../tensor/elemwise_binary_broadcast_op.h | 4 +- src/operator/tensor/elemwise_binary_op.h | 4 +- .../tensor/elemwise_binary_op_basic.cc | 4 +- .../tensor/elemwise_binary_scalar_op.h | 4 +- src/operator/tensor/elemwise_sum.cc | 4 +- src/operator/tensor/elemwise_unary_op.cc | 8 +-- src/operator/tensor/elemwise_unary_op.h | 4 +- src/operator/tensor/indexing_op.cc | 30 ++++----- src/operator/tensor/init_op.cc | 20 +++--- src/operator/tensor/matrix_op.cc | 62 +++++++++---------- src/operator/tensor/ordering_op.cc | 12 ++-- 28 files changed, 168 insertions(+), 128 deletions(-) diff --git a/include/mxnet/op_attr_types.h b/include/mxnet/op_attr_types.h index cffca441e4b0..ec73b9d651f2 100644 --- a/include/mxnet/op_attr_types.h +++ b/include/mxnet/op_attr_types.h @@ -71,6 +71,46 @@ using FComputeEx = std::function& inputs, const std::vector& req, const std::vector& outputs)>; + +/*! + * \brief Inference function of certain type. + * \tparam AttrType The type of the attribute to be infered. + * \return whether all attributes are inferred. + */ +template +using FInferNodeEntryAttr = std::function *in_attrs, + std::vector *out_attrs)>; +/*! + * \brief Shape inference function. + * Update the shapes given the input shape information. + * TShape.ndim() == 0 means the shape is still unknown. + * + * \note Register under "FInferShape", + * by default do not update any shapes. + * + * FInferShape is needed by shape inference + */ +using FInferShape = FInferNodeEntryAttr; + +/*! + * \brief Type inference function. + * Update the type given the known type information. + * + * \note Register under "FInferType", + * by default set all the output types to 0. + */ +using FInferType = FInferNodeEntryAttr; + +/*! + * \brief Storage type inference function. + * Update the type given the known type information. + * + * \note Register under "FInferStorageType", + * by default set all the output types to 1. + */ +using FInferStorageType = FInferNodeEntryAttr; + } // namespace mxnet #endif // MXNET_OP_ATTR_TYPES_H_ diff --git a/src/c_api/c_api_ndarray.cc b/src/c_api/c_api_ndarray.cc index 8d190597ab0b..bdd8268317a7 100644 --- a/src/c_api/c_api_ndarray.cc +++ b/src/c_api/c_api_ndarray.cc @@ -133,9 +133,9 @@ void SetShapeType(const nnvm::Op* op, std::vector* p_ndoutputs, int* dispatch_stype) { std::vector& ndoutputs = *p_ndoutputs; - static auto& infershape = nnvm::Op::GetAttr("FInferShape"); - static auto& infertype = nnvm::Op::GetAttr("FInferType"); - static auto& inferstorage = nnvm::Op::GetAttr("FInferStorageType"); + static auto& infershape = nnvm::Op::GetAttr("FInferShape"); + static auto& infertype = nnvm::Op::GetAttr("FInferType"); + static auto& inferstorage = nnvm::Op::GetAttr("FInferStorageType"); MXAPIThreadLocalEntry *ret = MXAPIThreadLocalStore::Get(); // infer shape std::vector& in_shapes = ret->arg_shapes; diff --git a/src/executor/infer_graph_attr_pass.cc b/src/executor/infer_graph_attr_pass.cc index fb098f818f43..719809b135b5 100644 --- a/src/executor/infer_graph_attr_pass.cc +++ b/src/executor/infer_graph_attr_pass.cc @@ -28,7 +28,7 @@ nnvm::Graph InferAttr(nnvm::Graph &&ret, const IndexedGraph& idx = ret.indexed_graph(); static auto& finfer_shape = - Op::GetAttr >(infer_name); + Op::GetAttr >(infer_name); static auto& is_backward = Op::GetAttr("TIsBackward"); // gradient function, used to get node correspondence. diff --git a/src/io/image_io.cc b/src/io/image_io.cc index 1ef1df1b74bd..f110d518bb20 100644 --- a/src/io/image_io.cc +++ b/src/io/image_io.cc @@ -281,8 +281,8 @@ NNVM_REGISTER_OP(_cvimresize) .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(op::ParamParser) -.set_attr("FInferShape", ResizeShape) -.set_attr("FInferType", op::ElemwiseType<1, 1>) +.set_attr("FInferShape", ResizeShape) +.set_attr("FInferType", op::ElemwiseType<1, 1>) .set_attr("FCompute", Imresize) .add_argument("src", "NDArray", "source image") .add_arguments(ResizeParam::__FIELDS__()); @@ -292,8 +292,8 @@ NNVM_REGISTER_OP(_cvcopyMakeBorder) .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(op::ParamParser) -.set_attr("FInferShape", MakeBorderShape) -.set_attr("FInferType", op::ElemwiseType<1, 1>) +.set_attr("FInferShape", MakeBorderShape) +.set_attr("FInferType", op::ElemwiseType<1, 1>) .set_attr("FCompute", copyMakeBorder) .add_argument("src", "NDArray", "source image") .add_arguments(MakeBorderParam::__FIELDS__()); diff --git a/src/nnvm/legacy_op_util.cc b/src/nnvm/legacy_op_util.cc index 9b39794b4782..fed568111e89 100644 --- a/src/nnvm/legacy_op_util.cc +++ b/src/nnvm/legacy_op_util.cc @@ -323,8 +323,8 @@ void RegisterLegacyOpProp() { op.set_attr("FListInputNames", OpPropListInputNames); op.set_attr("FListOutputNames", OpPropListOutputNames); op.set_attr("FNumVisibleOutputs", OpPropNumVisibleOutputs); - op.set_attr("FInferShape", OpPropInferShape); - op.set_attr("FInferType", OpPropInferType); + op.set_attr("FInferShape", OpPropInferShape); + op.set_attr("FInferType", OpPropInferType); op.set_attr("FMutateInputs", OpPropMutateInputs); op.set_attr("FInplaceOption", OpPropInplaceOption); op.set_attr("FResourceRequest", OpPropResourceRequest); diff --git a/src/operator/contrib/dequantize.cc b/src/operator/contrib/dequantize.cc index 46e36fa3c891..958162a2666d 100644 --- a/src/operator/contrib/dequantize.cc +++ b/src/operator/contrib/dequantize.cc @@ -23,8 +23,8 @@ here `range(T) = numeric_limits::max() - numeric_limits::min()` .set_attr_parser(ParamParser) .set_num_inputs(3) .set_num_outputs(1) -.set_attr("FInferShape", DequantizeShape) -.set_attr("FInferType", DequantizeType) +.set_attr("FInferShape", DequantizeShape) +.set_attr("FInferType", DequantizeType) .set_attr("FCompute", DequantizeCompute) .set_attr("FGradient", ElemwiseGradUseNone{"_dequantize"}) .add_argument("input", "NDArray-or-Symbol", "A ndarray/symbol of type `uint8`") diff --git a/src/operator/contrib/quantize.cc b/src/operator/contrib/quantize.cc index 86f35e117882..4cd60beb3e91 100644 --- a/src/operator/contrib/quantize.cc +++ b/src/operator/contrib/quantize.cc @@ -23,8 +23,8 @@ here `range(T) = numeric_limits::max() - numeric_limits::min()` .set_attr_parser(ParamParser) .set_num_inputs(3) .set_num_outputs(3) -.set_attr("FInferShape", QuantizeShape) -.set_attr("FInferType", QuantizeType) +.set_attr("FInferShape", QuantizeShape) +.set_attr("FInferType", QuantizeType) .set_attr("FCompute", QuantizeCompute) .set_attr("FGradient", ElemwiseGradUseNone{"_quantize"}) .add_argument("input", "NDArray-or-Symbol", "A ndarray/symbol of type `float32`") diff --git a/src/operator/loss_binary_op.cc b/src/operator/loss_binary_op.cc index 43bf6943e0c5..4563c02ef3ce 100644 --- a/src/operator/loss_binary_op.cc +++ b/src/operator/loss_binary_op.cc @@ -40,8 +40,8 @@ Example:: )code" ADD_FILELINE) .set_num_inputs(2) .set_num_outputs(1) -.set_attr("FInferShape", SoftmaxCrossEntropyShape) -.set_attr("FInferType", ElemwiseType<2, 1>) +.set_attr("FInferShape", SoftmaxCrossEntropyShape) +.set_attr("FInferType", ElemwiseType<2, 1>) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; diff --git a/src/operator/nn/cast_storage.cc b/src/operator/nn/cast_storage.cc index 21c13e8fa564..6b155122c5d2 100644 --- a/src/operator/nn/cast_storage.cc +++ b/src/operator/nn/cast_storage.cc @@ -19,9 +19,9 @@ NNVM_REGISTER_OP(cast_storage) .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", ElemwiseType<1, 1>) -.set_attr("FInferStorageType", CastStorageInferStorageType) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferStorageType", CastStorageInferStorageType) .set_attr("FCompute", IdentityCompute) .set_attr("FComputeEx", CastStorageComputeEx) .add_argument("data", "NDArray-or-Symbol", "The input.") diff --git a/src/operator/optimizer_op.cc b/src/operator/optimizer_op.cc index 5c8bedcb0ebc..afae278f652b 100644 --- a/src/operator/optimizer_op.cc +++ b/src/operator/optimizer_op.cc @@ -29,8 +29,8 @@ update is applied only to rows whose gradient has non-zero entries. .set_num_inputs(2) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<2, 1>) -.set_attr("FInferType", ElemwiseType<2, 1>) +.set_attr("FInferShape", ElemwiseShape<2, 1>) +.set_attr("FInferType", ElemwiseType<2, 1>) .set_attr("FCompute", SGDUpdate) .set_attr("FComputeEx", SGDUpdateEx) .add_argument("weight", "NDArray-or-Symbol", "Weight") @@ -63,8 +63,8 @@ only rows whose gradients contain non-zero entries are updated (for both weight .set_num_inputs(3) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<3, 1>) -.set_attr("FInferType", ElemwiseType<3, 1>) +.set_attr("FInferShape", ElemwiseShape<3, 1>) +.set_attr("FInferType", ElemwiseType<3, 1>) .set_attr("FMutateInputs", [](const nnvm::NodeAttrs& attrs) { return std::vector{2}; @@ -100,8 +100,8 @@ It updates the weights using:: .set_num_inputs(4) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<4, 1>) -.set_attr("FInferType", ElemwiseType<4, 1>) +.set_attr("FInferShape", ElemwiseShape<4, 1>) +.set_attr("FInferType", ElemwiseType<4, 1>) .set_attr("FMutateInputs", [](const nnvm::NodeAttrs& attrs) { return std::vector{2, 3}; @@ -152,8 +152,8 @@ Hinton suggests the momentum term :math:`\gamma` to be 0.9 and the learning rate .set_num_inputs(3) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<3, 1>) -.set_attr("FInferType", ElemwiseType<3, 1>) +.set_attr("FInferShape", ElemwiseShape<3, 1>) +.set_attr("FInferType", ElemwiseType<3, 1>) .set_attr("FMutateInputs", [](const nnvm::NodeAttrs &attrs) { return std::vector{2}; @@ -191,8 +191,8 @@ to be 0.9 and the learning rate :math:`\eta` to be 0.0001. .set_num_inputs(5) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<5, 1>) -.set_attr("FInferType", ElemwiseType<5, 1>) +.set_attr("FInferShape", ElemwiseShape<5, 1>) +.set_attr("FInferType", ElemwiseType<5, 1>) .set_attr("FMutateInputs", [](const nnvm::NodeAttrs& attrs) { return std::vector{2, 3, 4}; diff --git a/src/operator/random/multisample_op.cc b/src/operator/random/multisample_op.cc index 303d1d2f0086..734f74b7c630 100644 --- a/src/operator/random/multisample_op.cc +++ b/src/operator/random/multisample_op.cc @@ -131,8 +131,8 @@ DMLC_REGISTER_PARAMETER(MultiSampleParam); [](const NodeAttrs& attrs) { \ std::vector v = {input_name_1, input_name_2}; v.resize(num_inputs); return v; \ }) \ - .set_attr("FInferShape", MultiSampleOpShape) \ - .set_attr("FInferType", MultiSampleOpType) \ + .set_attr("FInferShape", MultiSampleOpShape) \ + .set_attr("FInferType", MultiSampleOpType) \ .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { \ return std::vector(1, ResourceRequest::kRandom); \ }) \ diff --git a/src/operator/random/sample_multinomial_op.cc b/src/operator/random/sample_multinomial_op.cc index 9e6dbe99c045..150a85defa86 100644 --- a/src/operator/random/sample_multinomial_op.cc +++ b/src/operator/random/sample_multinomial_op.cc @@ -47,8 +47,8 @@ Examples:: return param.get_prob ? 2U : 1U; }) .set_attr_parser(ParamParser) -.set_attr("FInferShape", SampleMultinomialOpShape) -.set_attr("FInferType", SampleMultinomialOpType) +.set_attr("FInferShape", SampleMultinomialOpShape) +.set_attr("FInferType", SampleMultinomialOpType) .set_attr("FResourceRequest", [](const nnvm::NodeAttrs& attrs) { return std::vector{ diff --git a/src/operator/random/sample_op.cc b/src/operator/random/sample_op.cc index 1b3c293548e1..5171bc13753f 100644 --- a/src/operator/random/sample_op.cc +++ b/src/operator/random/sample_op.cc @@ -21,8 +21,8 @@ DMLC_REGISTER_PARAMETER(SampleGenNegBinomialParam); .set_num_inputs(0) \ .set_num_outputs(1) \ .set_attr_parser(ParamParser) \ - .set_attr("FInferShape", InitShape) \ - .set_attr("FInferType", SampleOpType) \ + .set_attr("FInferShape", InitShape) \ + .set_attr("FInferType", SampleOpType) \ .set_attr("FResourceRequest", SampleResource) \ .add_arguments(ParamType::__FIELDS__()) diff --git a/src/operator/tensor/broadcast_reduce_op.h b/src/operator/tensor/broadcast_reduce_op.h index 13f112b6f59d..2685735a48ce 100644 --- a/src/operator/tensor/broadcast_reduce_op.h +++ b/src/operator/tensor/broadcast_reduce_op.h @@ -663,8 +663,8 @@ void PickOpBackward(const nnvm::NodeAttrs& attrs, .set_num_inputs(1) \ .set_num_outputs(1) \ .set_attr_parser(ParamParser) \ - .set_attr("FInferShape", ReduceAxisShape) \ - .set_attr("FInferType", ElemwiseType<1, 1>) \ + .set_attr("FInferShape", ReduceAxisShape) \ + .set_attr("FInferType", ElemwiseType<1, 1>) \ .add_argument("data", "NDArray-or-Symbol", "The input") \ .add_arguments(ReduceAxisParam::__FIELDS__()) @@ -673,8 +673,8 @@ void PickOpBackward(const nnvm::NodeAttrs& attrs, .set_num_inputs(1) \ .set_num_outputs(1) \ .set_attr_parser(AxesParamParser) \ - .set_attr("FInferShape", ReduceAxesShape) \ - .set_attr("FInferType", ElemwiseType<1, 1>) \ + .set_attr("FInferShape", ReduceAxesShape) \ + .set_attr("FInferType", ElemwiseType<1, 1>) \ .add_argument("data", "NDArray-or-Symbol", "The input") \ .add_arguments(ReduceAxesParam::__FIELDS__()) @@ -688,7 +688,7 @@ void PickOpBackward(const nnvm::NodeAttrs& attrs, NNVM_REGISTER_OP(name) \ .set_num_inputs(1) \ .set_num_outputs(1) \ - .set_attr("FInferType", ElemwiseType<1, 1>) \ + .set_attr("FInferType", ElemwiseType<1, 1>) \ .set_attr("FGradient", \ [](const nnvm::NodePtr& n, \ const std::vector& ograds) { \ diff --git a/src/operator/tensor/broadcast_reduce_op_index.cc b/src/operator/tensor/broadcast_reduce_op_index.cc index 5944e2374ea3..fd98fe90ee51 100644 --- a/src/operator/tensor/broadcast_reduce_op_index.cc +++ b/src/operator/tensor/broadcast_reduce_op_index.cc @@ -84,8 +84,8 @@ Examples:: param.keepdims = false; attrs->parsed = param; }) -.set_attr("FInferShape", ReduceAxisShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ReduceAxisShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", SearchAxisCompute) .add_argument("data", "NDArray-or-Symbol", "The input array"); @@ -131,8 +131,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector{"data", "index"}; }) -.set_attr("FInferShape", PickOpShape) -.set_attr("FInferType", PickOpType) +.set_attr("FInferShape", PickOpShape) +.set_attr("FInferType", PickOpType) .set_attr("FCompute", PickOpForward) .set_attr("FGradient", [](const nnvm::NodePtr& n, const std::vector& ograds) { diff --git a/src/operator/tensor/broadcast_reduce_op_value.cc b/src/operator/tensor/broadcast_reduce_op_value.cc index fdbaf7610e9b..18aaf9ce01f1 100644 --- a/src/operator/tensor/broadcast_reduce_op_value.cc +++ b/src/operator/tensor/broadcast_reduce_op_value.cc @@ -168,7 +168,7 @@ Example:: )code" ADD_FILELINE) .set_attr_parser(ParamParser) .add_arguments(BroadcastAxesParam::__FIELDS__()) -.set_attr("FInferShape", BroadcastAxesShape) +.set_attr("FInferShape", BroadcastAxesShape) .set_attr("FCompute", BroadcastCompute); MXNET_OPERATOR_REGISTER_BROADCAST(broadcast_to) @@ -192,7 +192,7 @@ So with `shape=(2,0)`, we will obtain the same result as in the above example. )code" ADD_FILELINE) .set_attr_parser(ParamParser) .add_arguments(BroadcastToParam::__FIELDS__()) -.set_attr("FInferShape", BroadcastToShape) +.set_attr("FInferShape", BroadcastToShape) .set_attr("FCompute", BroadcastCompute); // backward op for broadcast. @@ -218,7 +218,7 @@ Examples:: )code" ADD_FILELINE) .set_num_inputs(1) .set_num_outputs(1) -.set_attr("FInferShape", +.set_attr("FInferShape", [](const nnvm::NodeAttrs& attrs, std::vector *in_attrs, std::vector *out_attrs) { @@ -228,7 +228,7 @@ Examples:: SHAPE_ASSIGN_CHECK(*out_attrs, 0, mshadow::Shape1(1)); return true; }) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", L2NormCompute) .add_argument("data", "NDArray-or-Symbol", "Source input"); diff --git a/src/operator/tensor/control_flow_op.cc b/src/operator/tensor/control_flow_op.cc index 5dd525ea391e..e8236ea36dd9 100644 --- a/src/operator/tensor/control_flow_op.cc +++ b/src/operator/tensor/control_flow_op.cc @@ -25,8 +25,8 @@ NNVM_REGISTER_OP(where) [](const NodeAttrs& attrs) { return std::vector{"condition", "x", "y"}; }) -.set_attr("FInferShape", WhereOpShape) -.set_attr("FInferType", WhereOpType) +.set_attr("FInferShape", WhereOpShape) +.set_attr("FInferType", WhereOpType) .set_attr("FCompute", WhereOpForward) .set_attr("FGradient", // Use the following lambda function instead of ElemwiseGradUseIn diff --git a/src/operator/tensor/elemwise_binary_broadcast_op.h b/src/operator/tensor/elemwise_binary_broadcast_op.h index be0d27d1e334..a747930f958d 100644 --- a/src/operator/tensor/elemwise_binary_broadcast_op.h +++ b/src/operator/tensor/elemwise_binary_broadcast_op.h @@ -227,8 +227,8 @@ void BinaryBroadcastBackwardUseIn(const nnvm::NodeAttrs& attrs, [](const NodeAttrs& attrs) { \ return std::vector{"lhs", "rhs"}; \ }) \ - .set_attr("FInferShape", BinaryBroadcastShape) \ - .set_attr("FInferType", ElemwiseType<2, 1>) \ + .set_attr("FInferShape", BinaryBroadcastShape) \ + .set_attr("FInferType", ElemwiseType<2, 1>) \ .set_attr("FInplaceOption", \ [](const NodeAttrs& attrs){ \ return std::vector >{{0, 0}, {1, 0}}; \ diff --git a/src/operator/tensor/elemwise_binary_op.h b/src/operator/tensor/elemwise_binary_op.h index 222b0d1ffc31..d4a31a939a24 100644 --- a/src/operator/tensor/elemwise_binary_op.h +++ b/src/operator/tensor/elemwise_binary_op.h @@ -361,8 +361,8 @@ void BinaryBackwardUseInWithHalf2(const nnvm::NodeAttrs& attrs, [](const NodeAttrs& attrs) { \ return std::vector{"lhs", "rhs"}; \ }) \ - .set_attr("FInferShape", ElemwiseShape<2, 1>) \ - .set_attr("FInferType", ElemwiseType<2, 1>) \ + .set_attr("FInferShape", ElemwiseShape<2, 1>) \ + .set_attr("FInferType", ElemwiseType<2, 1>) \ .set_attr("FInplaceOption", \ [](const NodeAttrs& attrs){ \ return std::vector >{{0, 0}, {1, 0}}; \ diff --git a/src/operator/tensor/elemwise_binary_op_basic.cc b/src/operator/tensor/elemwise_binary_op_basic.cc index c9e5b21470d9..37e073172d28 100644 --- a/src/operator/tensor/elemwise_binary_op_basic.cc +++ b/src/operator/tensor/elemwise_binary_op_basic.cc @@ -14,7 +14,7 @@ MXNET_OPERATOR_REGISTER_BINARY(elemwise_add) .set_attr("FCompute", BinaryCompute) .set_attr("FComputeEx", BinaryComputeEx) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_add"}) -.set_attr("FInferStorageType", ElemwiseStorageType<2, 1>); +.set_attr("FInferStorageType", ElemwiseStorageType<2, 1>); // specialized gradient add function to do add to optimization // this must differ from elemwise_add to prevent add to optimization in forward pass. @@ -33,7 +33,7 @@ NNVM_REGISTER_OP(_backward_add) mshadow_op::identity>) .set_attr("FComputeEx", BinaryBackwardUseNoneEx) -.set_attr("FInferStorageType", ElemwiseStorageType<1, 2>); +.set_attr("FInferStorageType", ElemwiseStorageType<1, 2>); MXNET_OPERATOR_REGISTER_BINARY(_sub) .add_alias("_minus").add_alias("_Minus") diff --git a/src/operator/tensor/elemwise_binary_scalar_op.h b/src/operator/tensor/elemwise_binary_scalar_op.h index 5e577c6e3d4f..9334302a0f57 100644 --- a/src/operator/tensor/elemwise_binary_scalar_op.h +++ b/src/operator/tensor/elemwise_binary_scalar_op.h @@ -56,8 +56,8 @@ void BinaryScalarBackward(const nnvm::NodeAttrs& attrs, .set_attr_parser([](NodeAttrs* attrs) { \ attrs->parsed = std::stod(attrs->dict["scalar"]); \ }) \ - .set_attr("FInferShape", ElemwiseShape<1, 1>) \ - .set_attr("FInferType", ElemwiseType<1, 1>) \ + .set_attr("FInferShape", ElemwiseShape<1, 1>) \ + .set_attr("FInferType", ElemwiseType<1, 1>) \ .set_attr("FInplaceOption", \ [](const NodeAttrs& attrs){ \ return std::vector >{{0, 0}}; \ diff --git a/src/operator/tensor/elemwise_sum.cc b/src/operator/tensor/elemwise_sum.cc index 06ec01e8ebd0..e25645815034 100644 --- a/src/operator/tensor/elemwise_sum.cc +++ b/src/operator/tensor/elemwise_sum.cc @@ -81,8 +81,8 @@ NNVM_REGISTER_OP(add_n) "FInplaceOption", [](const NodeAttrs& attrs) { return std::vector >{{0, 0}}; }) -.set_attr("FInferShape", ElementWiseSumShape) -.set_attr("FInferType", ElementWiseSumType) +.set_attr("FInferShape", ElementWiseSumShape) +.set_attr("FInferType", ElementWiseSumType) .set_attr("FGradient", ElementWiseSumGrad) .add_argument("args", "NDArray-or-Symbol[]", "Positional input arguments"); diff --git a/src/operator/tensor/elemwise_unary_op.cc b/src/operator/tensor/elemwise_unary_op.cc index 372e94509a68..480a47bb6dae 100644 --- a/src/operator/tensor/elemwise_unary_op.cc +++ b/src/operator/tensor/elemwise_unary_op.cc @@ -125,8 +125,8 @@ NNVM_REGISTER_OP(_identity_with_attr_like_rhs) [](const NodeAttrs& attrs) { return std::vector(1, 1); }) .set_attr("FCompute", IdentityCompute) .set_attr("FComputeEx", IdentityLikeRhsComputeEx) -.set_attr("FInferShape", ElemwiseShape<2, 1>) -.set_attr("FInferStorageType", IdentityAttrLikeRhsStorageType) +.set_attr("FInferShape", ElemwiseShape<2, 1>) +.set_attr("FInferStorageType", IdentityAttrLikeRhsStorageType) .set_attr( "FGradient", [](const nnvm::NodePtr& n, const std::vector& ograds) { @@ -156,8 +156,8 @@ Example:: )code" ADD_FILELINE) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", CastType) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", CastType) .set_attr("FInplaceOption", [](const NodeAttrs& attrs){ return std::vector >{{0, 0}}; diff --git a/src/operator/tensor/elemwise_unary_op.h b/src/operator/tensor/elemwise_unary_op.h index f3aab781eddb..02a093bb500f 100644 --- a/src/operator/tensor/elemwise_unary_op.h +++ b/src/operator/tensor/elemwise_unary_op.h @@ -207,8 +207,8 @@ struct relu_grad { NNVM_REGISTER_OP(name) \ .set_num_inputs(1) \ .set_num_outputs(1) \ - .set_attr("FInferShape", ElemwiseShape<1, 1>) \ - .set_attr("FInferType", ElemwiseType<1, 1>) \ + .set_attr("FInferShape", ElemwiseShape<1, 1>) \ + .set_attr("FInferType", ElemwiseType<1, 1>) \ .set_attr("FInplaceOption", \ [](const NodeAttrs& attrs){ \ return std::vector >{{0, 0}}; \ diff --git a/src/operator/tensor/indexing_op.cc b/src/operator/tensor/indexing_op.cc index dfe53cf4614e..6764bc04c898 100644 --- a/src/operator/tensor/indexing_op.cc +++ b/src/operator/tensor/indexing_op.cc @@ -60,8 +60,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector{"data", "weight"}; }) -.set_attr("FInferShape", EmbeddingOpShape) -.set_attr("FInferType", EmbeddingOpType) +.set_attr("FInferShape", EmbeddingOpShape) +.set_attr("FInferType", EmbeddingOpType) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -105,9 +105,9 @@ The gradient of an embedding matrix has the form of gradient vectors that are on [](const NodeAttrs& attrs) { return std::vector{"data", "weight"}; }) -.set_attr("FInferShape", SparseEmbeddingShape) -.set_attr("FInferType", EmbeddingOpType) -.set_attr("FInferStorageType", SparseEmbeddingForwardStorageType) +.set_attr("FInferShape", SparseEmbeddingShape) +.set_attr("FInferType", EmbeddingOpType) +.set_attr("FInferStorageType", SparseEmbeddingForwardStorageType) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -164,8 +164,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector{"a", "indices"}; }) -.set_attr("FInferShape", TakeOpShape) -.set_attr("FInferType", TakeOpType) +.set_attr("FInferShape", TakeOpShape) +.set_attr("FInferType", TakeOpType) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -218,8 +218,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector{"a", "indices"}; }) -.set_attr("FInferShape", BatchTakeOpShape) -.set_attr("FInferType", BatchTakeOpType) +.set_attr("FInferShape", BatchTakeOpShape) +.set_attr("FInferType", BatchTakeOpType) .set_attr("FCompute", BatchTakeOpForward) .add_argument("a", "NDArray-or-Symbol", "The input array") .add_argument("indices", "NDArray-or-Symbol", "The index array"); @@ -265,8 +265,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector{"indices"}; }) -.set_attr("FInferShape", OneHotOpShape) -.set_attr("FInferType", OneHotOpType) +.set_attr("FInferShape", OneHotOpShape) +.set_attr("FInferType", OneHotOpType) .set_attr("FCompute", OneHotOpForward) .set_attr("FGradient", MakeZeroGradNodes) .add_argument("indices", "NDArray-or-Symbol", "array of locations where to set on_value") @@ -294,9 +294,9 @@ Example:: [](const NodeAttrs& attrs) { return std::vector{"data", "indices"}; }) -.set_attr("FInferShape", SparseRetainOpShape) -.set_attr("FInferType", SparseRetainOpType) -.set_attr("FInferStorageType", SparseRetainForwardInferStorageType) +.set_attr("FInferShape", SparseRetainOpShape) +.set_attr("FInferType", SparseRetainOpType) +.set_attr("FInferStorageType", SparseRetainForwardInferStorageType) .set_attr("FComputeEx", SparseRetainOpForwardEx) .set_attr("FGradient", [](const nnvm::NodePtr& n, const std::vector& ograds) { @@ -310,7 +310,7 @@ NNVM_REGISTER_OP(_backward_sparse_retain) .set_num_inputs(2) .set_num_outputs(2) .set_attr("TIsBackward", true) -.set_attr("FInferStorageType", SparseRetainBackwardInferStorageType) +.set_attr("FInferStorageType", SparseRetainBackwardInferStorageType) .set_attr("FComputeEx", SparseRetainOpBackwardEx); } // namespace op diff --git a/src/operator/tensor/init_op.cc b/src/operator/tensor/init_op.cc index 679d1fb55bab..44b7a3eb6b18 100644 --- a/src/operator/tensor/init_op.cc +++ b/src/operator/tensor/init_op.cc @@ -18,8 +18,8 @@ NNVM_REGISTER_OP(_zeros) .set_num_inputs(0) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", InitShape) -.set_attr("FInferType", InitType) +.set_attr("FInferShape", InitShape) +.set_attr("FInferType", InitType) .set_attr("FCompute", FillCompute) .set_attr("FComputeEx", FillComputeZerosEx) .add_arguments(InitOpParam::__FIELDS__()); @@ -29,8 +29,8 @@ NNVM_REGISTER_OP(_ones) .set_num_inputs(0) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", InitShape) -.set_attr("FInferType", InitType) +.set_attr("FInferShape", InitShape) +.set_attr("FInferType", InitType) .set_attr("FCompute", FillCompute) .add_arguments(InitOpParam::__FIELDS__()); @@ -39,8 +39,8 @@ NNVM_REGISTER_OP(_arange) .set_num_inputs(0) .set_num_outputs(1) .set_attr_parser(RangeParamParser) -.set_attr("FInferShape", RangeShape) -.set_attr("FInferType", InitType) +.set_attr("FInferShape", RangeShape) +.set_attr("FInferType", InitType) .set_attr("FCompute", RangeCompute) .add_arguments(RangeParam::__FIELDS__()); @@ -59,8 +59,8 @@ Examples:: )code") .set_num_inputs(1) .set_num_outputs(1) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FIgnoreInputs", [](const NodeAttrs& attrs) { return std::vector(1, 0); }) .set_attr("FCompute", FillCompute) @@ -82,8 +82,8 @@ Examples:: )code") .set_num_inputs(1) .set_num_outputs(1) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FIgnoreInputs", [](const NodeAttrs& attrs) { return std::vector(1, 0); }) .set_attr("FCompute", FillCompute) diff --git a/src/operator/tensor/matrix_op.cc b/src/operator/tensor/matrix_op.cc index 9ac998f02378..95e78d5de9e7 100644 --- a/src/operator/tensor/matrix_op.cc +++ b/src/operator/tensor/matrix_op.cc @@ -88,8 +88,8 @@ If the argument `reverse` is set to 1, then the special values are inferred from .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ReshapeShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ReshapeShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_copy"}) .set_attr("FCompute", IdentityCompute) .set_attr("FInplaceOption", @@ -127,8 +127,8 @@ Example:: )code" ADD_FILELINE) .set_num_inputs(1) .set_num_outputs(1) -.set_attr("FInferShape", FlattenShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", FlattenShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FGradient", ElemwiseGradUseNone{ "_backward_copy" }) .set_attr("FCompute", IdentityCompute) .set_attr("FInplaceOption", @@ -169,8 +169,8 @@ Examples:: .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", TransposeShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", TransposeShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FGradient", [](const nnvm::NodePtr& n, const std::vector& ograds) { const TransposeParam& param = nnvm::get(n->attrs.parsed); @@ -205,8 +205,8 @@ will return a new array with shape ``(2,1,3,4)``. .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ExpandDimShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ExpandDimShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FInplaceOption", [](const NodeAttrs& attrs){ return std::vector >{{0, 0}}; @@ -246,9 +246,9 @@ Example:: )code" ADD_FILELINE) .set_attr_parser(ParamParser) -.set_attr("FInferShape", SliceShape) -.set_attr("FInferType", ElemwiseType<1, 1>) -.set_attr("FInferStorageType", ElemwiseStorageType<1, 1>) +.set_attr("FInferShape", SliceShape) +.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferStorageType", ElemwiseStorageType<1, 1>) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_slice"}) .set_attr("FCompute", Slice) .set_attr("FComputeEx", SliceEx) @@ -274,8 +274,8 @@ NNVM_REGISTER_OP(_slice_assign) return std::vector{"lhs", "rhs"}; }) .set_attr_parser(ParamParser) -.set_attr("FInferShape", SliceAssignShape) -.set_attr("FInferType", ElemwiseType<2, 1>) +.set_attr("FInferShape", SliceAssignShape) +.set_attr("FInferType", ElemwiseType<2, 1>) .set_attr("FInplaceOption", [](const NodeAttrs& attrs){ return std::vector >{{0, 0}}; @@ -294,8 +294,8 @@ NNVM_REGISTER_OP(_crop_assign_scalar) .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", CropAssignScalarShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", CropAssignScalarShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FInplaceOption", [](const NodeAttrs& attrs){ return std::vector >{{0, 0}}; @@ -330,8 +330,8 @@ Examples:: .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", SliceAxisShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", SliceAxisShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", SliceAxis) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_slice_axis"}) .add_argument("data", "NDArray-or-Symbol", "Source input") @@ -373,9 +373,9 @@ NNVM_REGISTER_OP(dot) [](const NodeAttrs& attrs) { return std::vector{"lhs", "rhs"}; }) -.set_attr("FInferShape", DotShape) -.set_attr("FInferType", ElemwiseType<2, 1>) -.set_attr("FInferStorageType", DotForwardInferStorageType) +.set_attr("FInferShape", DotShape) +.set_attr("FInferType", ElemwiseType<2, 1>) +.set_attr("FInferStorageType", DotForwardInferStorageType) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -392,7 +392,7 @@ NNVM_REGISTER_OP(_backward_dot) .set_num_outputs(2) .set_attr_parser(ParamParser) .set_attr("TIsBackward", true) -.set_attr("FInferStorageType", DotBackwardInferStorageType) +.set_attr("FInferStorageType", DotBackwardInferStorageType) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -421,8 +421,8 @@ which is computed by:: [](const NodeAttrs& attrs) { return std::vector{"lhs", "rhs"}; }) -.set_attr("FInferShape", BatchDotShape) -.set_attr("FInferType", ElemwiseType<2, 1>) +.set_attr("FInferShape", BatchDotShape) +.set_attr("FInferType", ElemwiseType<2, 1>) .set_attr("FResourceRequest", [](const NodeAttrs& attrs) { return std::vector{ResourceRequest::kTempSpace}; @@ -462,8 +462,8 @@ Example:: .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", Clip) .set_attr("FGradient", ElemwiseGradUseIn{ "_backward_clip" }) .add_argument("data", "NDArray-or-Symbol", "Input array.") @@ -508,8 +508,8 @@ The parameter ``axis`` specifies the axis along which to perform repeat:: [](const NodeAttrs& attrs) { return std::vector{"data"}; }) -.set_attr("FInferShape", RepeatOpShape) -.set_attr("FInferType", RepeatOpType) +.set_attr("FInferShape", RepeatOpShape) +.set_attr("FInferType", RepeatOpType) .set_attr("FCompute", RepeatOpForward) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_repeat"}) .add_argument("data", "NDArray-or-Symbol", "Input data array") @@ -569,8 +569,8 @@ there cases: [](const NodeAttrs& attrs) { return std::vector{"data"}; }) -.set_attr("FInferShape", TileOpShape) -.set_attr("FInferType", TileOpType) +.set_attr("FInferShape", TileOpShape) +.set_attr("FInferType", TileOpType) .set_attr("FCompute", TileOpForward) .set_attr("FGradient", ElemwiseGradUseNone{"_backward_tile"}) .add_argument("data", "NDArray-or-Symbol", "Input data array") @@ -615,8 +615,8 @@ Examples:: [](const NodeAttrs& attrs) { return std::vector {ResourceRequest::kTempSpace}; }) -.set_attr("FInferShape", ElemwiseShape<1, 1>) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ElemwiseShape<1, 1>) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", ReverseOpForward) .set_attr("FGradient", ElemwiseGradUseNone{ "_backward_reverse" }) .add_argument("data", "NDArray-or-Symbol", "Input data array") diff --git a/src/operator/tensor/ordering_op.cc b/src/operator/tensor/ordering_op.cc index 3308836c1840..1804ceb69d41 100644 --- a/src/operator/tensor/ordering_op.cc +++ b/src/operator/tensor/ordering_op.cc @@ -45,8 +45,8 @@ Examples:: .set_num_inputs(1) .set_num_outputs(TopKNumOutputs) .set_attr_parser(ParamParser) -.set_attr("FInferShape", TopKShape) -.set_attr("FInferType", TopKType) +.set_attr("FInferShape", TopKShape) +.set_attr("FInferType", TopKType) .set_attr("FNumVisibleOutputs", TopKNumVisibleOutputs) .set_attr("FCompute", TopK) .set_attr("FGradient", @@ -108,8 +108,8 @@ Examples:: .set_num_inputs(1) .set_num_outputs(2) .set_attr_parser(ParamParser) -.set_attr("FInferShape", SortShape) -.set_attr("FInferType", ElemwiseType<1, 2>) +.set_attr("FInferShape", SortShape) +.set_attr("FInferType", ElemwiseType<1, 2>) .set_attr("FNumVisibleOutputs", [](const NodeAttrs& attrs) { return 1; }) .set_attr("FCompute", Sort) .set_attr("FGradient", @@ -158,8 +158,8 @@ Examples:: .set_num_inputs(1) .set_num_outputs(1) .set_attr_parser(ParamParser) -.set_attr("FInferShape", ArgSortShape) -.set_attr("FInferType", ElemwiseType<1, 1>) +.set_attr("FInferShape", ArgSortShape) +.set_attr("FInferType", ElemwiseType<1, 1>) .set_attr("FCompute", ArgSort) .set_attr("FGradient", MakeZeroGradNodes) .set_attr("FResourceRequest",