forked from mindspore-Ecosystem/mindspore
!24792 [feat] [assistant] [I48OFK] add the dynamic shape for AbsGrad
Merge pull request !24792 from 彭涛/op_abs_grad
This commit is contained in:
commit
24fe0e0896
|
@ -15,10 +15,53 @@
|
|||
*/
|
||||
|
||||
#include "ops/grad/abs_grad.h"
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "abstract/param_validator.h"
|
||||
#include "utils/check_convert_utils.h"
|
||||
#include "abstract/primitive_infer_map.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace ops {
|
||||
REGISTER_PRIMITIVE_C(kNameAbsGrad, AbsGrad);
|
||||
namespace {
|
||||
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
|
||||
MS_EXCEPTION_IF_NULL(primitive);
|
||||
auto prim_name = primitive->name();
|
||||
const int64_t input_num = 2;
|
||||
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name);
|
||||
for (const auto &item : input_args) {
|
||||
MS_EXCEPTION_IF_NULL(item);
|
||||
}
|
||||
auto x = input_args[0]->BuildShape();
|
||||
MS_EXCEPTION_IF_NULL(x);
|
||||
auto shape_element = x->cast<abstract::ShapePtr>();
|
||||
MS_EXCEPTION_IF_NULL(shape_element);
|
||||
return shape_element;
|
||||
}
|
||||
|
||||
TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
|
||||
MS_EXCEPTION_IF_NULL(prim);
|
||||
auto prim_name = prim->name();
|
||||
const int64_t input_num = 2;
|
||||
(void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name);
|
||||
MS_EXCEPTION_IF_NULL(input_args[0]);
|
||||
auto x_type = input_args[0]->BuildType();
|
||||
MS_EXCEPTION_IF_NULL(x_type);
|
||||
if (!x_type->isa<TensorType>()) {
|
||||
MS_EXCEPTION(TypeError) << "The " << prim_name << "'s "
|
||||
<< " input must be tensor type but got " << x_type->ToString();
|
||||
}
|
||||
return x_type;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AbstractBasePtr AbsGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
|
||||
const std::vector<AbstractBasePtr> &input_args) {
|
||||
auto type = InferType(primitive, input_args);
|
||||
auto shape = InferShape(primitive, input_args);
|
||||
return abstract::MakeAbstract(shape, type);
|
||||
}
|
||||
|
||||
REGISTER_PRIMITIVE_EVAL_IMPL(AbsGrad, prim::kPrimAbsGrad, AbsGradInfer, nullptr, true);
|
||||
} // namespace ops
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
#include "ops/primitive_c.h"
|
||||
#include "ops/op_utils.h"
|
||||
#include "abstract/abstract_value.h"
|
||||
#include "utils/check_convert_utils.h"
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from .abs_ds import _abs_ds_tbe
|
|||
from .inplace_add import _inplace_add_tbe
|
||||
from .inplace_sub import _inplace_sub_tbe
|
||||
from .abs_grad import _abs_grad_tbe
|
||||
from .abs_grad_ds import _abs_grad_ds_tbe
|
||||
from .acos import _acos_tbe
|
||||
from .acos_grad import _acos_grad_tbe
|
||||
from .acosh import _acosh_tbe
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
"""AbsGrad op"""
|
||||
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType
|
||||
|
||||
abs_grad_op_info = TBERegOp("AbsGrad") \
|
||||
.fusion_type("ELEMWISE") \
|
||||
.async_flag(False) \
|
||||
.binfile_name("abs_grad.so") \
|
||||
.compute_cost(10) \
|
||||
.kernel_name("abs_grad") \
|
||||
.dynamic_shape(True)\
|
||||
.partial_flag(True) \
|
||||
.input(0, "y", None, "required", None) \
|
||||
.input(1, "dy", None, "required", None) \
|
||||
.output(0, "z", False, "required", "all") \
|
||||
.dtype_format(DataType.F16_5HD, DataType.F16_5HD, DataType.F16_5HD) \
|
||||
.dtype_format(DataType.F16_FracZ, DataType.F16_FracZ, DataType.F16_FracZ) \
|
||||
.dtype_format(DataType.F16_C1HWNCoC0, DataType.F16_C1HWNCoC0, DataType.F16_C1HWNCoC0) \
|
||||
.dtype_format(DataType.F16_Default, DataType.F16_Default, DataType.F16_Default) \
|
||||
.dtype_format(DataType.F32_5HD, DataType.F32_5HD, DataType.F32_5HD) \
|
||||
.dtype_format(DataType.F32_FracZ, DataType.F32_FracZ, DataType.F32_FracZ) \
|
||||
.dtype_format(DataType.F32_C1HWNCoC0, DataType.F32_C1HWNCoC0, DataType.F32_C1HWNCoC0) \
|
||||
.dtype_format(DataType.F32_Default, DataType.F32_Default, DataType.F32_Default) \
|
||||
.get_op_info()
|
||||
|
||||
|
||||
@op_info_register(abs_grad_op_info)
|
||||
def _abs_grad_ds_tbe():
|
||||
"""AbsGrad TBE register"""
|
||||
return
|
|
@ -32,12 +32,6 @@ class AbsGrad(PrimitiveWithInfer):
|
|||
def __init__(self):
|
||||
"""Initialize AbsGrad"""
|
||||
|
||||
def infer_shape(self, y, dy):
|
||||
return y
|
||||
|
||||
def infer_dtype(self, y, dy):
|
||||
return y
|
||||
|
||||
|
||||
class ACosGrad(PrimitiveWithInfer):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue