forked from mindspore-Ecosystem/mindspore
Add some bprop mindir files
This commit is contained in:
parent
bf59d75604
commit
7c808ee792
|
@ -93,13 +93,17 @@ mindspore::HashSet<std::string> GetSerializableBpropList() {
|
|||
}
|
||||
|
||||
auto ops_list = serializable_bprop_ops_attr.cast<py::list>();
|
||||
for (size_t i = 0; i < ops_list.size(); ++i) {
|
||||
auto prim_adapter = ops_list[i].cast<PrimitivePyAdapterPtr>();
|
||||
if (prim_adapter == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "The python obj in serializable bprop list should be a Primitive, but it is "
|
||||
<< py::str(ops_list[i]);
|
||||
for (auto op : ops_list) {
|
||||
if (py::isinstance<py::str>(op)) {
|
||||
serializable_bprop_list.insert(op.cast<std::string>());
|
||||
continue;
|
||||
}
|
||||
serializable_bprop_list.insert(prim_adapter->name());
|
||||
py::object prim_name = op.attr("__name__");
|
||||
if (!py::isinstance<py::str>(prim_name)) {
|
||||
MS_LOG(WARNING) << "The name of obj " << py::str(op) << " to be exported to mindir should be a string";
|
||||
continue;
|
||||
}
|
||||
serializable_bprop_list.insert(prim_name.cast<std::string>());
|
||||
}
|
||||
return serializable_bprop_list;
|
||||
}
|
||||
|
@ -185,20 +189,23 @@ FuncGraphPtr ImportBpropFromMindIR(const PrimitivePtr &prim) {
|
|||
}
|
||||
MindIRLoader mindir_loader;
|
||||
auto bprop_fg = mindir_loader.LoadMindIR(bprop_mindir_realpath.value());
|
||||
if (bprop_fg == nullptr) {
|
||||
MS_LOG(WARNING) << "Failed to load the bprop mindir " << bprop_mindir_realpath.value();
|
||||
return nullptr;
|
||||
}
|
||||
if (!CheckBpropHash(bprop_fg->bprop_hash())) {
|
||||
MS_LOG(EXCEPTION) << "The bprop mindir files are not up to date.";
|
||||
}
|
||||
return bprop_fg;
|
||||
}
|
||||
|
||||
void ExportBpropToMindIR(const PrimitivePtr &prim, const FuncGraphPtr &func_graph) {
|
||||
MS_EXCEPTION_IF_NULL(prim);
|
||||
void ExportBpropToMindIR(const std::string &prim_name, const FuncGraphPtr &func_graph) {
|
||||
std::string bprop_dir = GetBpropDir();
|
||||
auto bprop_mindir_path = bprop_dir + kBpropMindIRDir;
|
||||
std::optional<std::string> bprop_mindir_realpath =
|
||||
Common::CreatePrefixPath(bprop_mindir_path + prim->name() + kBpropMindIRSuffix, true);
|
||||
Common::CreatePrefixPath(bprop_mindir_path + prim_name + kBpropMindIRSuffix, true);
|
||||
if (!bprop_mindir_realpath.has_value()) {
|
||||
MS_LOG(ERROR) << "Failed to get the realpath of bprop mindir: " << bprop_mindir_path << prim->name()
|
||||
MS_LOG(ERROR) << "Failed to get the realpath of bprop mindir: " << bprop_mindir_path << prim_name
|
||||
<< kBpropMindIRSuffix;
|
||||
return;
|
||||
}
|
||||
|
@ -214,7 +221,7 @@ void ExportBpropToMindIR(const PrimitivePtr &prim, const FuncGraphPtr &func_grap
|
|||
return;
|
||||
}
|
||||
if (!fg_model->SerializeToOstream(&fout)) {
|
||||
MS_LOG(ERROR) << "Failed to cache the bprop of op \"" << prim->name() << "\" to file \""
|
||||
MS_LOG(ERROR) << "Failed to cache the bprop of op \"" << prim_name << "\" to file \""
|
||||
<< bprop_mindir_realpath.value() << "\".";
|
||||
fout.close();
|
||||
return;
|
||||
|
@ -286,45 +293,62 @@ std::string GetBpropFileHash(const py::function &fn) {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool NeedExportBpropMindIR(const std::string &prim_name, const std::string ¤t_hash) {
|
||||
static std::string bprop_mindir_path = GetBpropDir() + kBpropMindIRDir;
|
||||
std::optional<std::string> bprop_mindir_realpath =
|
||||
FileUtils::GetRealPath(common::SafeCStr(bprop_mindir_path + prim_name + kBpropMindIRSuffix));
|
||||
bool bprop_cache_file_exists = bprop_mindir_realpath.has_value() && Common::FileExists(bprop_mindir_realpath.value());
|
||||
if (!bprop_cache_file_exists) {
|
||||
return true;
|
||||
}
|
||||
MindIRLoader mindir_loader;
|
||||
auto bprop_fg = mindir_loader.LoadMindIR(bprop_mindir_realpath.value());
|
||||
if (bprop_fg == nullptr) {
|
||||
MS_LOG(WARNING) << "Failed to load the bprop mindir " << bprop_mindir_realpath.value();
|
||||
return true;
|
||||
}
|
||||
return bprop_fg->bprop_hash() != current_hash;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
#ifndef _WIN32
|
||||
// Given a python primitive, export a mindir file from the bprop defined in python.
|
||||
// Given a python primitive or string, export a mindir file from the bprop defined in python.
|
||||
void KPrim::ExportBpropMindir(const py::object &obj) {
|
||||
auto prim_adapter = obj.cast<PrimitivePyAdapterPtr>();
|
||||
if (prim_adapter == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "The python obj to be exported to bprop mindir should be a Primitive, but it is "
|
||||
<< py::str(obj);
|
||||
std::string prim_name;
|
||||
if (!py::isinstance<py::str>(obj)) {
|
||||
py::object obj_name = obj.attr("__name__");
|
||||
if (!py::isinstance<py::str>(obj_name)) {
|
||||
MS_LOG(EXCEPTION) << "The name of obj " << py::str(obj) << " to be exported to mindir should be a string";
|
||||
}
|
||||
auto prim = prim_adapter->attached_primitive();
|
||||
if (prim == nullptr) {
|
||||
prim = std::make_shared<PrimitivePy>(obj, prim_adapter);
|
||||
prim_adapter->set_attached_primitive(prim);
|
||||
prim_name = obj_name.cast<std::string>();
|
||||
} else {
|
||||
prim_name = obj.cast<std::string>();
|
||||
}
|
||||
|
||||
// Get the bprop function from python.
|
||||
py::function fn = prim->cast<PrimitivePyPtr>()->GetBpropFunction();
|
||||
if (py::isinstance<py::none>(fn)) {
|
||||
fn = GetBpropFunction(prim->name());
|
||||
}
|
||||
py::function fn = GetBpropFunctionByObj(obj);
|
||||
if (!fn || py::isinstance<py::none>(fn)) {
|
||||
MS_LOG(EXCEPTION) << "Fail to find bprop function for " << prim->name() << ".";
|
||||
MS_LOG(EXCEPTION) << "Fail to find bprop function for " << prim_name << ".";
|
||||
}
|
||||
std::string bprop_hash = GetBpropFileHash(fn);
|
||||
if (bprop_hash.empty()) {
|
||||
MS_LOG(EXCEPTION) << "Fail to get the file hash for " << prim->name();
|
||||
MS_LOG(EXCEPTION) << "Fail to get the file hash for " << prim_name;
|
||||
}
|
||||
// If the bprop file hash has not changed, we don't need to export a new mindir.
|
||||
if (!NeedExportBpropMindIR(prim_name, bprop_hash)) {
|
||||
return;
|
||||
}
|
||||
// Parse and resolve.
|
||||
auto func_graph = parse::ParsePythonCode(fn);
|
||||
if (func_graph == nullptr) {
|
||||
MS_LOG(EXCEPTION) << "Fail to parse bprop function for " << prim->name() << ".";
|
||||
MS_LOG(EXCEPTION) << "Fail to parse bprop function for " << prim_name << ".";
|
||||
}
|
||||
auto res = std::make_shared<pipeline::Resource>();
|
||||
(void)parse::ResolveFuncGraph(func_graph, res);
|
||||
|
||||
func_graph->set_bprop_hash(bprop_hash);
|
||||
ExportBpropToMindIR(prim, func_graph);
|
||||
ExportBpropToMindIR(prim_name, func_graph);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -383,7 +407,7 @@ FuncGraphPtr KPrim::GetBprop(const PrimitivePtr &prim, const pipeline::ResourceB
|
|||
std::string bprop_hash = GetBpropFileHash(fn);
|
||||
if (!bprop_hash.empty()) {
|
||||
func_graph->set_bprop_hash(bprop_hash);
|
||||
ExportBpropToMindIR(prim, func_graph);
|
||||
ExportBpropToMindIR(prim->name(), func_graph);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -619,7 +619,13 @@ bool IrExportBuilder::BuildCNode(const CNodePtr &node, mind_ir::GraphProto *cons
|
|||
// Add primitive attrs
|
||||
if (IsValueNode<Primitive>(op)) {
|
||||
auto prim = GetValueNode<PrimitivePtr>(op);
|
||||
for (auto attr : prim->attrs()) {
|
||||
if (prim->isa<prim::DoSignaturePrimitive>()) {
|
||||
auto func = prim->cast<prim::DoSignaturePrimitivePtr>()->function();
|
||||
if (func != nullptr && func->isa<Primitive>()) {
|
||||
prim = func->cast<PrimitivePtr>();
|
||||
}
|
||||
}
|
||||
for (const auto &attr : prim->attrs()) {
|
||||
MS_LOG(DEBUG) << "attr: " << attr.first << " " << attr.second->DumpText() << " " << attr.second->type_name();
|
||||
auto iter = g_export_attr_blacklist.find(attr.first);
|
||||
if (iter != g_export_attr_blacklist.end()) {
|
||||
|
|
|
@ -65,13 +65,15 @@ py::tuple ConvertDatatoPyTuple(const VectorRef &args) {
|
|||
}
|
||||
|
||||
py::function GetComputeFunctionWithoutPyObj(const std::string &name) {
|
||||
static const std::string module = "tests.vm_impl.vm_impl_function";
|
||||
py::module mod = py::module::import(common::SafeCStr(module));
|
||||
if (!py::hasattr(mod, common::SafeCStr(name))) {
|
||||
static const std::string vm_module = "mindspore.ops.vm_impl_registry";
|
||||
static const std::string get_vm_impl_fn = "get_vm_impl_fn";
|
||||
py::function get_fn = parse::python_adapter::GetPyFn(vm_module, get_vm_impl_fn);
|
||||
if (py::isinstance<py::none>(get_fn)) {
|
||||
MS_LOG(DEBUG) << "Failed to get the function 'get_vm_impl_fn'";
|
||||
return py::none();
|
||||
}
|
||||
py::object fn = mod.attr(common::SafeCStr(name));
|
||||
return fn;
|
||||
py::function vm_fn = get_fn(py::str(name));
|
||||
return vm_fn;
|
||||
}
|
||||
|
||||
BaseRef RunComputeFunctionWithoutPyObj(const PrimitivePtr &prim, const VectorRef &args) {
|
||||
|
|
|
@ -947,13 +947,21 @@ AnfNodePtr MSANFModelParser::BuildOperatorNode(const mind_ir::NodeProto &node_pr
|
|||
}
|
||||
}
|
||||
MS_EXCEPTION_IF_NULL(prim);
|
||||
auto prim_to_add_attr = prim;
|
||||
if (prim->isa<prim::DoSignaturePrimitive>()) {
|
||||
auto func = prim->cast<prim::DoSignaturePrimitivePtr>()->function();
|
||||
if (func != nullptr && func->isa<Primitive>()) {
|
||||
prim_to_add_attr = func->cast<PrimitivePtr>();
|
||||
prim_to_add_attr->set_attr("is_load", MakeValue(true));
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < node_proto.attribute_size(); ++i) {
|
||||
const mind_ir::AttributeProto &attr_proto = node_proto.attribute(i);
|
||||
// CNode abstract
|
||||
if (attr_proto.ref_attr_name().find("shape:") != string::npos) {
|
||||
continue;
|
||||
}
|
||||
if (!GetAttrValueForCNode(prim, attr_proto)) {
|
||||
if (!GetAttrValueForCNode(prim_to_add_attr, attr_proto)) {
|
||||
MS_LOG(ERROR) << "Parser prim: " << node_type << " attributes error : " << attr_proto.DebugString();
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ def get_bprop_zeros(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.DType)
|
||||
@bprop_getters.register(P.DType.__name__)
|
||||
def get_bprop_dtype(self):
|
||||
"""Generate bprop for DType"""
|
||||
|
||||
|
@ -134,6 +135,7 @@ def get_bprop_cast(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Shape)
|
||||
@bprop_getters.register(P.Shape.__name__)
|
||||
def get_bprop_shape(self):
|
||||
"""Generate bprop for Shape"""
|
||||
|
||||
|
@ -144,6 +146,7 @@ def get_bprop_shape(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.DynamicShape)
|
||||
@bprop_getters.register(P.DynamicShape.__name__)
|
||||
def get_bprop_dynamicshape(self):
|
||||
"""Generate bprop for Shape"""
|
||||
|
||||
|
@ -167,6 +170,7 @@ def get_bprop_split(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Rank)
|
||||
@bprop_getters.register(P.Rank.__name__)
|
||||
def get_bprop_rank(self):
|
||||
"""Generate bprop for Rank"""
|
||||
|
||||
|
@ -620,6 +624,7 @@ def get_bprop_sort(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Identity)
|
||||
@bprop_getters.register(P.Identity.__name__)
|
||||
def get_bprop_identity(self):
|
||||
"""Generate bprop for Identity"""
|
||||
|
||||
|
@ -630,6 +635,7 @@ def get_bprop_identity(self):
|
|||
|
||||
|
||||
@bprop_getters.register(inner.Range)
|
||||
@bprop_getters.register(inner.Range.__name__)
|
||||
def get_bprop_range(self):
|
||||
"""Generate bprop for Range"""
|
||||
|
||||
|
@ -714,6 +720,7 @@ def get_bprop_eye(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Select)
|
||||
@bprop_getters.register(P.Select.__name__)
|
||||
def get_bprop_select(self):
|
||||
"""Generate bprop for Select"""
|
||||
select = P.Select()
|
||||
|
@ -725,6 +732,7 @@ def get_bprop_select(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.OnesLike)
|
||||
@bprop_getters.register(P.OnesLike.__name__)
|
||||
def get_bprop_oneslike(self):
|
||||
"""Generate bprop for OnesLike"""
|
||||
|
||||
|
@ -735,6 +743,7 @@ def get_bprop_oneslike(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ZerosLike)
|
||||
@bprop_getters.register(P.ZerosLike.__name__)
|
||||
def get_bprop_zeroslike(self):
|
||||
"""Generate bprop for ZerosLike"""
|
||||
|
||||
|
@ -830,6 +839,7 @@ def get_bprop_tensor_scatter_add(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ScatterMax)
|
||||
@bprop_getters.register(P.ScatterMax.__name__)
|
||||
def get_bprop_scatter_max(self):
|
||||
"""Generate bprop for ScatterMax"""
|
||||
gather = P.Gather()
|
||||
|
@ -841,6 +851,7 @@ def get_bprop_scatter_max(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Argmax)
|
||||
@bprop_getters.register(P.Argmax.__name__)
|
||||
def get_bprop_argmax(self):
|
||||
"""Generate bprop for Argmax"""
|
||||
|
||||
|
@ -851,6 +862,7 @@ def get_bprop_argmax(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Argmin)
|
||||
@bprop_getters.register(P.Argmin.__name__)
|
||||
def get_bprop_argmin(self):
|
||||
"""Generate bprop for Argmin"""
|
||||
|
||||
|
|
|
@ -217,6 +217,7 @@ def get_bprop_mirror_micro_step_operator(self):
|
|||
|
||||
|
||||
@bprop_getters.register(Broadcast)
|
||||
@bprop_getters.register(Broadcast.__name__)
|
||||
def get_bprop_broad_cast(self):
|
||||
"""Generate bprop for Broadcast."""
|
||||
|
||||
|
|
|
@ -374,6 +374,7 @@ def get_bprop_ceil(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.FloorDiv)
|
||||
@bprop_getters.register(P.FloorDiv.__name__)
|
||||
def get_bprop_floordiv(self):
|
||||
"""Grad definition for `FloorDiv` operation."""
|
||||
|
||||
|
@ -396,6 +397,7 @@ def get_bprop_floormod(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.TruncateDiv)
|
||||
@bprop_getters.register(P.TruncateDiv.__name__)
|
||||
def get_bprop_truncate_div(self):
|
||||
"""Grad definition for `TruncateDiv` operation."""
|
||||
|
||||
|
@ -647,6 +649,7 @@ def get_bprop_expm1(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Minimum)
|
||||
@bprop_getters.register(P.Minimum.__name__)
|
||||
def get_bprop_minimum(self):
|
||||
"""Grad definition for `Minimum` operation."""
|
||||
input_grad = G.MinimumGrad()
|
||||
|
@ -659,6 +662,7 @@ def get_bprop_minimum(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Maximum)
|
||||
@bprop_getters.register(P.Maximum.__name__)
|
||||
def get_bprop_maximum(self):
|
||||
"""Grad definition for `Maximum` operation."""
|
||||
input_grad = G.MaximumGrad()
|
||||
|
@ -768,6 +772,7 @@ def get_bprop_cumprod(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ReduceAll)
|
||||
@bprop_getters.register(P.ReduceAll.__name__)
|
||||
def get_bprop_reduceall(self):
|
||||
"""Grad definition for `ReduceAll` operation."""
|
||||
|
||||
|
@ -778,6 +783,7 @@ def get_bprop_reduceall(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ReduceAny)
|
||||
@bprop_getters.register(P.ReduceAny.__name__)
|
||||
def get_bprop_reduceany(self):
|
||||
"""Grad definition for `ReduceAny` operation."""
|
||||
|
||||
|
@ -862,6 +868,7 @@ def get_bprop_reduce_mean(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.IsFinite)
|
||||
@bprop_getters.register(P.IsFinite.__name__)
|
||||
def get_bprop_isfinite(self):
|
||||
"""Grad definition for `IsFinite` operation."""
|
||||
|
||||
|
@ -872,6 +879,7 @@ def get_bprop_isfinite(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.IsNan)
|
||||
@bprop_getters.register(P.IsNan.__name__)
|
||||
def get_bprop_isnan(self):
|
||||
"""Grad definition for `IsNan` operation."""
|
||||
|
||||
|
@ -882,6 +890,7 @@ def get_bprop_isnan(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.IsInf)
|
||||
@bprop_getters.register(P.IsInf.__name__)
|
||||
def get_bprop_isinf(self):
|
||||
"""Grad definition for `IsInf` operation."""
|
||||
|
||||
|
@ -892,6 +901,7 @@ def get_bprop_isinf(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Equal)
|
||||
@bprop_getters.register(P.Equal.__name__)
|
||||
def get_bprop_equal(self):
|
||||
"""Grad definition for `Equal` operation."""
|
||||
|
||||
|
@ -902,6 +912,7 @@ def get_bprop_equal(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.NotEqual)
|
||||
@bprop_getters.register(P.NotEqual.__name__)
|
||||
def get_bprop_not_equal(self):
|
||||
"""Grad definition for `NotEqual` operation."""
|
||||
|
||||
|
@ -912,6 +923,7 @@ def get_bprop_not_equal(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ApproximateEqual)
|
||||
@bprop_getters.register(P.ApproximateEqual.__name__)
|
||||
def get_bprop_approximate_equal(self):
|
||||
"""Grad definition for `ApproximateEqual` operation."""
|
||||
|
||||
|
@ -922,6 +934,7 @@ def get_bprop_approximate_equal(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Greater)
|
||||
@bprop_getters.register(P.Greater.__name__)
|
||||
def get_bprop_greater(self):
|
||||
"""Grad definition for `Greater` operation."""
|
||||
|
||||
|
@ -932,6 +945,7 @@ def get_bprop_greater(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.GreaterEqual)
|
||||
@bprop_getters.register(P.GreaterEqual.__name__)
|
||||
def get_bprop_greater_equal(self):
|
||||
"""Grad definition for `GreaterEqual` operation."""
|
||||
|
||||
|
@ -942,6 +956,7 @@ def get_bprop_greater_equal(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Less)
|
||||
@bprop_getters.register(P.Less.__name__)
|
||||
def get_bprop_less(self):
|
||||
"""Grad definition for `Less` operation."""
|
||||
|
||||
|
@ -952,6 +967,7 @@ def get_bprop_less(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.LessEqual)
|
||||
@bprop_getters.register(P.LessEqual.__name__)
|
||||
def get_bprop_less_equal(self):
|
||||
"""Grad definition for `LessEqual` operation."""
|
||||
|
||||
|
@ -962,6 +978,7 @@ def get_bprop_less_equal(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.LogicalNot)
|
||||
@bprop_getters.register(P.LogicalNot.__name__)
|
||||
def get_bprop_logical_not(self):
|
||||
"""Grad definition for `LogicalNot` operation."""
|
||||
|
||||
|
@ -972,6 +989,7 @@ def get_bprop_logical_not(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.LogicalAnd)
|
||||
@bprop_getters.register(P.LogicalAnd.__name__)
|
||||
def get_bprop_logical_and(self):
|
||||
"""Grad definition for `LogicalAnd` operation."""
|
||||
|
||||
|
@ -982,6 +1000,7 @@ def get_bprop_logical_and(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.LogicalOr)
|
||||
@bprop_getters.register(P.LogicalOr.__name__)
|
||||
def get_bprop_logical_or(self):
|
||||
"""Grad definition for `LogicalOr` operation."""
|
||||
|
||||
|
@ -1022,6 +1041,7 @@ def get_bprop_npu_clear_float_status(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.AssignAdd)
|
||||
@bprop_getters.register(P.AssignAdd.__name__)
|
||||
def get_bprop_assign_add(self):
|
||||
"""Grad definition for `AssignAdd` operation."""
|
||||
|
||||
|
@ -1032,6 +1052,7 @@ def get_bprop_assign_add(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.AssignSub)
|
||||
@bprop_getters.register(P.AssignSub.__name__)
|
||||
def get_bprop_assign_sub(self):
|
||||
"""Grad definition for `AssignSub` operation."""
|
||||
|
||||
|
@ -1282,6 +1303,7 @@ def get_bprop_scalar_addn(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Sign)
|
||||
@bprop_getters.register(P.Sign.__name__)
|
||||
def get_bprop_sign(self):
|
||||
"""Generate bprop for Sign"""
|
||||
|
||||
|
@ -1292,6 +1314,7 @@ def get_bprop_sign(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.Round)
|
||||
@bprop_getters.register(P.Round.__name__)
|
||||
def get_bprop_round(self):
|
||||
"""Generate bprop for Round"""
|
||||
|
||||
|
@ -1417,6 +1440,7 @@ def get_bprop_inv(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.LinSpace)
|
||||
@bprop_getters.register(P.LinSpace.__name__)
|
||||
def get_bprop_lin_space(self):
|
||||
"""Grad definition for `LinSpace` operation."""
|
||||
|
||||
|
|
|
@ -352,6 +352,7 @@ def get_bprop_avg_pool_3d_grad(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.DropoutGenMask)
|
||||
@bprop_getters.register(P.DropoutGenMask.__name__)
|
||||
def get_bprop_dropout_gen_mask(self):
|
||||
"""Grad definition for `DropoutGenMask` operation."""
|
||||
|
||||
|
@ -362,6 +363,7 @@ def get_bprop_dropout_gen_mask(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.DropoutDoMask)
|
||||
@bprop_getters.register(P.DropoutDoMask.__name__)
|
||||
def get_bprop_dropout_do_mask(self):
|
||||
"""Grad definition for `DropoutDoMask` operation."""
|
||||
do_mask = P.DropoutDoMask()
|
||||
|
@ -425,6 +427,7 @@ def get_bprop_mul_no_nan(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ReLU)
|
||||
@bprop_getters.register(P.ReLU.__name__)
|
||||
def get_bprop_relu(self):
|
||||
"""Grad definition for `ReLU` operation."""
|
||||
input_grad = G.ReluGrad()
|
||||
|
@ -437,6 +440,7 @@ def get_bprop_relu(self):
|
|||
|
||||
|
||||
@bprop_getters.register(G.ReluGrad)
|
||||
@bprop_getters.register(G.ReluGrad.__name__)
|
||||
def get_bprop_relu_grad(self):
|
||||
"""Grad definition for `ReLUGrad` operation."""
|
||||
input_grad = G.ReluGrad()
|
||||
|
@ -461,6 +465,7 @@ def get_bprop_relu6(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.ReLUV2)
|
||||
@bprop_getters.register(P.ReLUV2.__name__)
|
||||
def get_bprop_relu_v2(self):
|
||||
"""Grad definition for `ReLUV2` operation."""
|
||||
input_grad = G.ReluGradV2()
|
||||
|
@ -811,6 +816,7 @@ def get_bprop_resize_bilinear(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.OneHot)
|
||||
@bprop_getters.register(P.OneHot.__name__)
|
||||
def get_bprop_onehot(self):
|
||||
"""Grad definition for `OneHot` operation."""
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ from .grad_base import bprop_getters
|
|||
|
||||
|
||||
@bprop_getters.register(P.Assign)
|
||||
@bprop_getters.register(P.Assign.__name__)
|
||||
def get_bprop_assign(self):
|
||||
"""Generate bprop for Assign"""
|
||||
|
||||
|
@ -43,6 +44,7 @@ def get_bprop_invert_permutation(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.IOU)
|
||||
@bprop_getters.register(P.IOU.__name__)
|
||||
def get_bprop_iou(self):
|
||||
"""Generate bprop for IOU"""
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ def get_bprop_batchnormfold(self):
|
|||
|
||||
|
||||
@bprop_getters.register(P.BNTrainingReduce)
|
||||
@bprop_getters.register(P.BNTrainingReduce.__name__)
|
||||
def get_bprop_bn_training_reduce(self):
|
||||
"""Generate bprop for BNTrainingReduce for Ascend"""
|
||||
|
||||
|
|
|
@ -15,4 +15,4 @@ bprop.33:x*
|
|||
bprop.33:y*
|
||||
bprop.33:out*
|
||||
bprop.33:dout2
|
||||
bprop.33:[CNode]36:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.33:[CNode]36:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.14:x*
|
||||
bprop.14:out*
|
||||
bprop.14:dout2
|
||||
bprop.14:[CNode]16:2:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.14:[CNode]16:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.17:x*
|
||||
bprop.17:out*
|
||||
bprop.17:dout2
|
||||
bprop.17:[CNode]19:2:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.17:[CNode]19:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -15,4 +15,4 @@ bprop.22:x*
|
|||
bprop.22:y*
|
||||
bprop.22:out*
|
||||
bprop.22:dout2
|
||||
bprop.22:[CNode]25:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.22:[CNode]25:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.26:x*
|
|||
bprop.26:y*
|
||||
bprop.26:out*
|
||||
bprop.26:dout2
|
||||
bprop.26:[CNode]29:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.26:[CNode]29:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -12,4 +12,4 @@ bprop.61:x*
|
|||
bprop.61:y*
|
||||
bprop.61:out*
|
||||
bprop.61:dout2
|
||||
bprop.61:[CNode]63:2:@d600ac5742fbd8dc8b4b041517ce58e1beec6270a8d533616d7cfd5b4b178b15P
|
||||
bprop.61:[CNode]63:2:@95e1589c91520e66f639d339cd47d91fc97beeb20be68b44d08ebcf9a49136a9P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.68:x*
|
||||
bprop.68:out*
|
||||
bprop.68:dout2
|
||||
bprop.68:[CNode]70:2:@565f906930f68ca2413e9ad958d105e129e717cd183b95d11d65a8b0b030fc0dP
|
||||
bprop.68:[CNode]70:2:@1e27cd67c72e444d4887e7d7ea00adeb8aff74c5b46357b5181815a61af42ff7P
|
|
@ -6,4 +6,4 @@ l
|
|||
bprop.20:x*
|
||||
bprop.20:out*
|
||||
bprop.20:dout2
|
||||
bprop.20:[CNode]21:1:@96c75d48466ae9dd2ae51ee64181426e1bf1c36337f7c6cf3bdd01083bfb1a6eP
|
||||
bprop.20:[CNode]21:1:@db34e8b984a28af03c6bc0c939187dcb77745f31a9e4555ef7ad6abe300eda8bP
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:§
|
||||
<EFBFBD>
|
||||
bprop.116:xbprop.116:[CNode]117:1bprop.116:[CNode]117:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op84
|
||||
y
|
||||
bprop.116:[CNode]117:1bprop.116:[CNode]118:2bprop.116:[CNode]118:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op85 bprop.116*
|
||||
bprop.116:x*
|
||||
bprop.116:out*
|
||||
bprop.116:dout2
|
||||
bprop.116:[CNode]118:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:¤
|
||||
Ś
|
||||
bprop_depend.177:ybprop_depend.177:[CNode]178:1bprop_depend.177:[CNode]178:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op130
|
||||
Ś
|
||||
bprop_depend.177:dout
|
||||
bprop_depend.177:[CNode]178:1bprop_depend.177:[CNode]179:2bprop_depend.177:[CNode]179:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op131bprop_depend.177*
|
||||
bprop_depend.177:x*
|
||||
bprop_depend.177:y*
|
||||
bprop_depend.177:out*
|
||||
bprop_depend.177:dout2
|
||||
bprop_depend.177:[CNode]179:2:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -17,4 +17,4 @@
|
|||
bprop.111:keep_prob*
|
||||
bprop.111:out*
|
||||
bprop.111:dout2
|
||||
bprop.111:[CNode]115:4:@ff3ca86129a77e54496a41a353e9f6355edfba79f3c040cf990522596d638b7fP
|
||||
bprop.111:[CNode]115:4:@96ae3f8192e3c91377a1d29c2b21ca1b074919e769ac3f2760f56b9db1b17d94P
|
|
@ -11,4 +11,4 @@
|
|||
bprop.51:keep_prob*
|
||||
bprop.51:out*
|
||||
bprop.51:dout2
|
||||
bprop.51:[CNode]54:3:@ff3ca86129a77e54496a41a353e9f6355edfba79f3c040cf990522596d638b7fP
|
||||
bprop.51:[CNode]54:3:@96ae3f8192e3c91377a1d29c2b21ca1b074919e769ac3f2760f56b9db1b17d94P
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:§
|
||||
<EFBFBD>
|
||||
bprop.122:xbprop.122:[CNode]123:1bprop.122:[CNode]123:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op88
|
||||
y
|
||||
bprop.122:[CNode]123:1bprop.122:[CNode]124:2bprop.122:[CNode]124:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op89 bprop.122*
|
||||
bprop.122:x*
|
||||
bprop.122:out*
|
||||
bprop.122:dout2
|
||||
bprop.122:[CNode]124:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -15,4 +15,4 @@ bprop.71:x*
|
|||
bprop.71:y*
|
||||
bprop.71:out*
|
||||
bprop.71:dout2
|
||||
bprop.71:[CNode]74:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.71:[CNode]74:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:å
|
||||
‘
|
||||
bprop.143:xbprop.143:[CNode]144:1bprop.143:[CNode]144:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op104
|
||||
‘
|
||||
bprop.143:ybprop.143:[CNode]145:2bprop.143:[CNode]145:2"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op105
|
||||
’
|
||||
bprop.143:[CNode]144:1
|
||||
bprop.143:[CNode]145:2bprop.143:[CNode]146:3bprop.143:[CNode]146:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op106 bprop.143*
|
||||
bprop.143:x*
|
||||
bprop.143:y*
|
||||
bprop.143:out*
|
||||
bprop.143:dout2
|
||||
bprop.143:[CNode]146:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.83:x*
|
|||
bprop.83:y*
|
||||
bprop.83:out*
|
||||
bprop.83:dout2
|
||||
bprop.83:[CNode]86:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.83:[CNode]86:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.79:x*
|
|||
bprop.79:y*
|
||||
bprop.79:out*
|
||||
bprop.79:dout2
|
||||
bprop.79:[CNode]82:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.79:[CNode]82:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.64:x*
|
|||
bprop.64:y*
|
||||
bprop.64:out*
|
||||
bprop.64:dout2
|
||||
bprop.64:[CNode]67:3:@d600ac5742fbd8dc8b4b041517ce58e1beec6270a8d533616d7cfd5b4b178b15P
|
||||
bprop.64:[CNode]67:3:@95e1589c91520e66f639d339cd47d91fc97beeb20be68b44d08ebcf9a49136a9P
|
|
@ -5,4 +5,4 @@ f
|
|||
bprop.3:x*
|
||||
bprop.3:out*
|
||||
bprop.3:dout2
|
||||
bprop.3:[CNode]4:1:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.3:[CNode]4:1:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.30:x*
|
||||
bprop.30:out*
|
||||
bprop.30:dout2
|
||||
bprop.30:[CNode]32:2:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.30:[CNode]32:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:©
|
||||
‘
|
||||
bprop.164:xbprop.164:[CNode]165:1bprop.164:[CNode]165:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op120
|
||||
z
|
||||
bprop.164:[CNode]165:1bprop.164:[CNode]166:2bprop.164:[CNode]166:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op121 bprop.164*
|
||||
bprop.164:x*
|
||||
bprop.164:out*
|
||||
bprop.164:dout2
|
||||
bprop.164:[CNode]166:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:©
|
||||
‘
|
||||
bprop.161:xbprop.161:[CNode]162:1bprop.161:[CNode]162:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op118
|
||||
z
|
||||
bprop.161:[CNode]162:1bprop.161:[CNode]163:2bprop.161:[CNode]163:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op119 bprop.161*
|
||||
bprop.161:x*
|
||||
bprop.161:out*
|
||||
bprop.161:dout2
|
||||
bprop.161:[CNode]163:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.91:x*
|
|||
bprop.91:y*
|
||||
bprop.91:out*
|
||||
bprop.91:dout2
|
||||
bprop.91:[CNode]94:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.91:[CNode]94:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.87:x*
|
|||
bprop.87:y*
|
||||
bprop.87:out*
|
||||
bprop.87:dout2
|
||||
bprop.87:[CNode]90:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.87:[CNode]90:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@
|
|||
bprop.46:num*
|
||||
bprop.46:out*
|
||||
bprop.46:dout2
|
||||
bprop.46:[CNode]50:4:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.46:[CNode]50:4:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:š
|
||||
¦
|
||||
bprop_load.194:u_monadbprop_load.194:[CNode]195:1bprop_load.194:[CNode]195:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op143
|
||||
ž
|
||||
bprop_load.194:dout
|
||||
bprop_load.194:[CNode]195:1bprop_load.194:[CNode]196:2bprop_load.194:[CNode]196:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op144bprop_load.194*
|
||||
bprop_load.194:param*
|
||||
bprop_load.194:u_monad*
|
||||
bprop_load.194:out*
|
||||
bprop_load.194:dout2
|
||||
bprop_load.194:[CNode]196:2:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -15,4 +15,4 @@ bprop.95:x*
|
|||
bprop.95:y*
|
||||
bprop.95:out*
|
||||
bprop.95:dout2
|
||||
bprop.95:[CNode]98:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.95:[CNode]98:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.40:x*
|
||||
bprop.40:out*
|
||||
bprop.40:dout2
|
||||
bprop.40:[CNode]42:2:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.40:[CNode]42:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -15,4 +15,4 @@ bprop.99:x*
|
|||
bprop.99:y*
|
||||
bprop.99:out*
|
||||
bprop.99:dout2
|
||||
bprop.99:[CNode]102:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.99:[CNode]102:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
Binary file not shown.
Binary file not shown.
|
@ -15,4 +15,4 @@ bprop.75:x*
|
|||
bprop.75:y*
|
||||
bprop.75:out*
|
||||
bprop.75:dout2
|
||||
bprop.75:[CNode]78:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.75:[CNode]78:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -19,4 +19,4 @@
|
|||
bprop.55:off_value*
|
||||
bprop.55:out*
|
||||
bprop.55:dout2
|
||||
bprop.55:[CNode]60:5:@ff3ca86129a77e54496a41a353e9f6355edfba79f3c040cf990522596d638b7fP
|
||||
bprop.55:[CNode]60:5:@96ae3f8192e3c91377a1d29c2b21ca1b074919e769ac3f2760f56b9db1b17d94P
|
|
@ -7,4 +7,4 @@ n
|
|||
bprop.8:x*
|
||||
bprop.8:out*
|
||||
bprop.8:dout2
|
||||
bprop.8:[CNode]10:2:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.8:[CNode]10:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -7,4 +7,4 @@ l
|
|||
bprop.5:x*
|
||||
bprop.5:out*
|
||||
bprop.5:dout2
|
||||
bprop.5:[CNode]7:2:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.5:[CNode]7:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:§
|
||||
<EFBFBD>
|
||||
bprop.125:xbprop.125:[CNode]126:1bprop.125:[CNode]126:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op90
|
||||
y
|
||||
bprop.125:[CNode]126:1bprop.125:[CNode]127:2bprop.125:[CNode]127:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op91 bprop.125*
|
||||
bprop.125:x*
|
||||
bprop.125:out*
|
||||
bprop.125:dout2
|
||||
bprop.125:[CNode]127:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
Binary file not shown.
|
@ -1,11 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:Ü
|
||||
e
|
||||
0.1.0 MindSpore*1.6.0:Î
|
||||
Ö
|
||||
bprop.1:dout
|
||||
bprop.1:outbprop.1:dx:1bprop.1:dx:1"S-Prim-ReluGrad:Default/S-Prim-ReluGrad-op0
|
||||
bprop.1:outbprop.1:dx:1bprop.1:dx:1"S-Prim-ReluGrad*0
|
||||
output_namesZoutputzscalar:List[value1,],€*=
|
||||
input_namesZ
|
||||
y_backpropZxzscalar:List[value1,value2,],€:Default/S-Prim-ReluGrad-op0
|
||||
f
|
||||
bprop.1:dx:1bprop.1:[CNode]2:2bprop.1:[CNode]2:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op1bprop.1*
|
||||
bprop.1:x*
|
||||
bprop.1:out*
|
||||
bprop.1:dout2
|
||||
bprop.1:[CNode]2:2:@ff3ca86129a77e54496a41a353e9f6355edfba79f3c040cf990522596d638b7fP
|
||||
bprop.1:[CNode]2:2:@96ae3f8192e3c91377a1d29c2b21ca1b074919e769ac3f2760f56b9db1b17d94P
|
|
@ -11,4 +11,4 @@
|
|||
bprop.103:axis*
|
||||
bprop.103:out*
|
||||
bprop.103:dout2
|
||||
bprop.103:[CNode]106:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.103:[CNode]106:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -11,4 +11,4 @@
|
|||
bprop.107:axis*
|
||||
bprop.107:out*
|
||||
bprop.107:dout2
|
||||
bprop.107:[CNode]110:3:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.107:[CNode]110:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:¶
|
||||
ä
|
||||
bprop.140:dout
|
||||
bprop.140:ybprop.140:dgrad:1bprop.140:dgrad:1"S-Prim-ReluGrad*0
|
||||
output_namesZoutputzscalar:List[value1,],€*=
|
||||
input_namesZ
|
||||
y_backpropZxzscalar:List[value1,value2,],€:Default/S-Prim-ReluGrad-op101
|
||||
‘
|
||||
bprop.140:ybprop.140:[CNode]141:2bprop.140:[CNode]141:2"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op102
|
||||
<EFBFBD>
|
||||
bprop.140:dgrad:1
|
||||
bprop.140:[CNode]141:2bprop.140:[CNode]142:3bprop.140:[CNode]142:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op103 bprop.140*
|
||||
bprop.140:grad*
|
||||
bprop.140:y*
|
||||
bprop.140:out*
|
||||
bprop.140:dout2
|
||||
bprop.140:[CNode]142:3:@96ae3f8192e3c91377a1d29c2b21ca1b074919e769ac3f2760f56b9db1b17d94P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.43:x*
|
||||
bprop.43:out*
|
||||
bprop.43:dout2
|
||||
bprop.43:[CNode]45:2:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.43:[CNode]45:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
Binary file not shown.
|
@ -0,0 +1,31 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:Â
|
||||
|
||||
“
|
||||
bprop.128:condbprop.128:[CNode]129:1bprop.128:[CNode]129:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op92
|
||||
<EFBFBD>
|
||||
bprop.128:xbprop.128:[CNode]130:2bprop.128:[CNode]130:2"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op93
|
||||
<EFBFBD>
|
||||
bprop.128:cond
|
||||
bprop.128:dout
|
||||
bprop.128:[CNode]130:2bprop.128:[CNode]131:3bprop.128:[CNode]131:3"
S-Prim-Select*0
|
||||
output_namesZoutputzscalar:List[value1,],€*F
|
||||
input_namesZ conditionZxZyz#scalar:List[value1,value2,value3,],€:Default/S-Prim-Select-op94
|
||||
<EFBFBD>
|
||||
bprop.128:ybprop.128:[CNode]132:4bprop.128:[CNode]132:4"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op95
|
||||
<EFBFBD>
|
||||
bprop.128:cond
|
||||
bprop.128:[CNode]132:4
|
||||
bprop.128:doutbprop.128:[CNode]133:5bprop.128:[CNode]133:5"
S-Prim-Select*0
|
||||
output_namesZoutputzscalar:List[value1,],€*F
|
||||
input_namesZ conditionZxZyz#scalar:List[value1,value2,value3,],€:Default/S-Prim-Select-op96
|
||||
©
|
||||
bprop.128:[CNode]129:1
|
||||
bprop.128:[CNode]131:3
|
||||
bprop.128:[CNode]133:5bprop.128:[CNode]134:6bprop.128:[CNode]134:6"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op97 bprop.128*
|
||||
bprop.128:cond*
|
||||
bprop.128:x*
|
||||
bprop.128:y*
|
||||
bprop.128:out*
|
||||
bprop.128:dout2
|
||||
bprop.128:[CNode]134:6:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:§
|
||||
<EFBFBD>
|
||||
bprop.119:xbprop.119:[CNode]120:1bprop.119:[CNode]120:1"!S-Prim-hyper_map[zeros_like_leaf]:.Default/S-Prim-hyper_map[zeros_like_leaf]-op86
|
||||
y
|
||||
bprop.119:[CNode]120:1bprop.119:[CNode]121:2bprop.119:[CNode]121:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op87 bprop.119*
|
||||
bprop.119:x*
|
||||
bprop.119:out*
|
||||
bprop.119:dout2
|
||||
bprop.119:[CNode]121:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -9,4 +9,4 @@ s
|
|||
bprop.37:x*
|
||||
bprop.37:out*
|
||||
bprop.37:dout2
|
||||
bprop.37:[CNode]39:2:@83b099bc427dfabe31c75a63fd6095a27e90066e420c1a3d0680c5db9e31f905P
|
||||
bprop.37:[CNode]39:2:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:±
|
||||
|
||||
©
|
||||
bprop_switch.183:condbprop_switch.183:[CNode]184:1bprop_switch.183:[CNode]184:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op134
|
||||
§
|
||||
bprop_switch.183:tbbprop_switch.183:[CNode]185:2bprop_switch.183:[CNode]185:2"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op135
|
||||
·
|
||||
bprop_switch.183:cond
|
||||
bprop_switch.183:dout
|
||||
bprop_switch.183:[CNode]185:2bprop_switch.183:[CNode]186:3bprop_switch.183:[CNode]186:3"
S-Prim-Switch:Default/S-Prim-Switch-op136
|
||||
§
|
||||
bprop_switch.183:fbbprop_switch.183:[CNode]187:4bprop_switch.183:[CNode]187:4"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op137
|
||||
·
|
||||
bprop_switch.183:cond
|
||||
bprop_switch.183:[CNode]187:4
|
||||
bprop_switch.183:doutbprop_switch.183:[CNode]188:5bprop_switch.183:[CNode]188:5"
S-Prim-Switch:Default/S-Prim-Switch-op138
|
||||
Í
|
||||
bprop_switch.183:[CNode]184:1
|
||||
bprop_switch.183:[CNode]186:3
|
||||
bprop_switch.183:[CNode]188:5bprop_switch.183:[CNode]189:6bprop_switch.183:[CNode]189:6"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op139bprop_switch.183*
|
||||
bprop_switch.183:cond*
|
||||
bprop_switch.183:tb*
|
||||
bprop_switch.183:fb*
|
||||
bprop_switch.183:out*
|
||||
bprop_switch.183:dout2
|
||||
bprop_switch.183:[CNode]189:6:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:å
|
||||
‘
|
||||
bprop.147:xbprop.147:[CNode]148:1bprop.147:[CNode]148:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op107
|
||||
‘
|
||||
bprop.147:ybprop.147:[CNode]149:2bprop.147:[CNode]149:2"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op108
|
||||
’
|
||||
bprop.147:[CNode]148:1
|
||||
bprop.147:[CNode]149:2bprop.147:[CNode]150:3bprop.147:[CNode]150:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op109 bprop.147*
|
||||
bprop.147:x*
|
||||
bprop.147:y*
|
||||
bprop.147:out*
|
||||
bprop.147:dout2
|
||||
bprop.147:[CNode]150:3:@5ef58541543bde1e2825be6f527f29db9de3ef5a82bee9759d6cb85f92271c90P
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:š
|
||||
ž
|
||||
bprop_tuple_getitem.143:data$bprop_tuple_getitem.143:[CNode]144:1$bprop_tuple_getitem.143:[CNode]144:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op104
|
||||
ç
|
||||
$bprop_tuple_getitem.143:[CNode]144:1
|
||||
bprop_tuple_getitem.143:idx
|
||||
bprop_tuple_getitem.143:dout$bprop_tuple_getitem.143:[CNode]145:2$bprop_tuple_getitem.143:[CNode]145:2"S-Prim-tuple_setitem:"Default/S-Prim-tuple_setitem-op105
|
||||
˝
|
||||
bprop_tuple_getitem.143:idx$bprop_tuple_getitem.143:[CNode]146:3$bprop_tuple_getitem.143:[CNode]146:3"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op106
|
||||
Ę
|
||||
$bprop_tuple_getitem.143:[CNode]145:2
|
||||
$bprop_tuple_getitem.143:[CNode]146:3$bprop_tuple_getitem.143:[CNode]147:4$bprop_tuple_getitem.143:[CNode]147:4"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op107bprop_tuple_getitem.143*
|
||||
bprop_tuple_getitem.143:data*
|
||||
bprop_tuple_getitem.143:idx*
|
||||
bprop_tuple_getitem.143:out*
|
||||
bprop_tuple_getitem.143:dout2&
|
||||
$bprop_tuple_getitem.143:[CNode]147:4:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:Á
|
||||
ž
|
||||
bprop_update_state.190:u_monad#bprop_update_state.190:[CNode]191:1#bprop_update_state.190:[CNode]191:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op140
|
||||
¸
|
||||
bprop_update_state.190:x#bprop_update_state.190:[CNode]192:2#bprop_update_state.190:[CNode]192:2"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op141
|
||||
Ć
|
||||
#bprop_update_state.190:[CNode]191:1
|
||||
#bprop_update_state.190:[CNode]192:2#bprop_update_state.190:[CNode]193:3#bprop_update_state.190:[CNode]193:3"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op142bprop_update_state.190*
|
||||
bprop_update_state.190:u_monad*
|
||||
bprop_update_state.190:x*
|
||||
bprop_update_state.190:out*
|
||||
bprop_update_state.190:dout2%
|
||||
#bprop_update_state.190:[CNode]193:3:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -9,4 +9,4 @@ r
|
|||
bprop.11:x*
|
||||
bprop.11:out*
|
||||
bprop.11:dout2
|
||||
bprop.11:[CNode]13:2:@03ba727554b68f632a7320602b4ab4649b05556a1aac96ba69a106bd541d09bbP
|
||||
bprop.11:[CNode]13:2:@c8a644cc520f380808ab8a19d3b5f795ef28e37966296c6941e187e7de28f9d7P
|
|
@ -18,19 +18,26 @@ import shutil
|
|||
import argparse
|
||||
|
||||
from mindspore.ops import operations as P
|
||||
from mindspore.ops import _constants
|
||||
import mindspore.ops._grad as g
|
||||
from mindspore.ops.operations import _grad_ops as G
|
||||
from mindspore.ops.operations import _inner_ops as inner
|
||||
from mindspore._c_expression import _export_bprop_mindir
|
||||
|
||||
serializable_bprop_ops = [P.ReLU(), P.Identity(), inner.Range(1.0), P.OnesLike(), P.ZerosLike(), P.Argmax(), P.Argmin(),
|
||||
P.Broadcast(1), P.AssignAdd(), P.AssignSub(), P.IsFinite(), P.ApproximateEqual(), P.Sign(),
|
||||
P.LogicalNot(), P.Round(), P.LinSpace(), P.DropoutGenMask(), P.OneHot(), P.Assign(), P.IOU(),
|
||||
P.BNTrainingReduce(), P.Equal(), P.NotEqual(), P.Greater(), P.GreaterEqual(), P.Less(),
|
||||
P.LessEqual(), P.LogicalAnd(), P.LogicalOr(), P.ReduceAll(), P.ReduceAny(), P.DropoutDoMask()]
|
||||
serializable_bprop_ops = [P.ReLU, P.Identity, inner.Range, P.OnesLike, P.ZerosLike, P.Argmax, P.Argmin, P.Broadcast,
|
||||
P.AssignAdd, P.AssignSub, P.IsFinite, P.ApproximateEqual, P.Sign, P.LogicalNot, P.Round,
|
||||
P.LinSpace, P.DropoutGenMask, P.OneHot, P.Assign, P.IOU, P.BNTrainingReduce, P.Equal,
|
||||
P.NotEqual, P.Greater, P.GreaterEqual, P.Less, P.LessEqual, P.LogicalAnd, P.LogicalOr,
|
||||
P.ReduceAll, P.ReduceAny, P.DropoutDoMask, P.DType, P.Shape, P.DynamicShape, P.Rank,
|
||||
P.Select, P.ScatterMax, G.ReluGrad, _constants.kTupleGetItem, P.FloorDiv, P.TruncateDiv,
|
||||
P.Minimum, P.Maximum, P.IsNan, P.IsInf, P.ReLUV2, "Depend", "stop_gradient", "Switch",
|
||||
"UpdateState", "Load"]
|
||||
|
||||
|
||||
def run_generate():
|
||||
for op in serializable_bprop_ops:
|
||||
if not isinstance(op, str):
|
||||
op = op.__name__
|
||||
_export_bprop_mindir(op)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
0.1.0 MindSpore*1.6.0:Ä
|
||||
»
|
||||
bprop_stop_gradient.180:x$bprop_stop_gradient.180:[CNode]181:1$bprop_stop_gradient.180:[CNode]181:1"!S-Prim-hyper_map[zeros_like_leaf]:/Default/S-Prim-hyper_map[zeros_like_leaf]-op132
|
||||
¤
|
||||
$bprop_stop_gradient.180:[CNode]181:1$bprop_stop_gradient.180:[CNode]182:2$bprop_stop_gradient.180:[CNode]182:2"S-Prim-MakeTuple:Default/S-Prim-MakeTuple-op133bprop_stop_gradient.180*
|
||||
bprop_stop_gradient.180:x*
|
||||
bprop_stop_gradient.180:out*
|
||||
bprop_stop_gradient.180:dout2&
|
||||
$bprop_stop_gradient.180:[CNode]182:2:@a6c407ad6a3b57190d3702d6a45031d13b97bb6952735edf94fb36f73dbff6cdP
|
|
@ -19,6 +19,7 @@ import numpy as np
|
|||
import mindspore.nn as nn
|
||||
from mindspore import Tensor, Parameter
|
||||
from mindspore.ops import operations as P
|
||||
import mindspore.ops.functional as F
|
||||
import mindspore.ops as ops
|
||||
from mindspore.ops.operations import _inner_ops as inner
|
||||
import mindspore.common.dtype as mstype
|
||||
|
@ -67,7 +68,11 @@ def test_load_mindir_dir():
|
|||
bprop_installed_dir = bprop_path[: bprop_path.rindex('/')]
|
||||
bprop_mindir_export_dir = bprop_installed_dir + "/../bprop_mindir"
|
||||
for op in serializable_bprop_ops:
|
||||
file_name = bprop_mindir_export_dir + "/" + op.name + "_bprop.mindir"
|
||||
if isinstance(op, str):
|
||||
op_name = op
|
||||
else:
|
||||
op_name = op.__name__
|
||||
file_name = bprop_mindir_export_dir + "/" + op_name + "_bprop.mindir"
|
||||
graph = load_mindir(file_name)
|
||||
assert not graph is None
|
||||
|
||||
|
@ -339,3 +344,282 @@ def test_dropout_do_mask():
|
|||
dropout_do_mask = Net(P.DropoutDoMask())
|
||||
grad = GradNet(dropout_do_mask)
|
||||
grad.compile(input_x, mask, keep_prob)
|
||||
|
||||
|
||||
def test_select():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the select op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
input_cond = Tensor([True, False])
|
||||
x = Tensor(np.array([1, 2]), mstype.int32)
|
||||
y = Tensor(np.array([1, 1]), mstype.int32)
|
||||
select = Net(P.Select())
|
||||
grad = GradNet(select)
|
||||
grad.compile(input_cond, x, y)
|
||||
|
||||
|
||||
def test_scatter_max():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the scatter_max op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class ScatterMaxNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(ScatterMaxNet, self).__init__()
|
||||
self.scatter_max = P.ScatterMax()
|
||||
self.input_x = Parameter(Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]), mstype.float32),
|
||||
name="input_x")
|
||||
|
||||
def construct(self, indices, updates):
|
||||
return self.scatter_max(self.input_x, indices, updates)
|
||||
|
||||
indices = Tensor(np.array([[0, 0], [1, 1]]), mstype.int32)
|
||||
updates = Tensor(np.ones([2, 2, 3]) * 88, mstype.float32)
|
||||
scatter_max = ScatterMaxNet()
|
||||
grad = GradNet(scatter_max)
|
||||
grad.compile(indices, updates)
|
||||
|
||||
|
||||
def test_relu_grad():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the relu_grad op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([[[[-1, 1, 10],
|
||||
[1, -1, 1],
|
||||
[10, 1, -1]]]]).astype(np.float32))
|
||||
relu = Net(P.ReLU())
|
||||
grad1 = GradNet(relu)
|
||||
grad2 = GradNet(grad1)
|
||||
grad2.compile(x)
|
||||
|
||||
|
||||
def test_tuple_getitem():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the tuple_getitem op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class TupleGetitemNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(TupleGetitemNet, self).__init__()
|
||||
self.maxpool_arg = P.MaxPoolWithArgmax(pad_mode="VALID", kernel_size=2, strides=1)
|
||||
|
||||
def construct(self, x):
|
||||
output = self.maxpool_arg(x)
|
||||
return output[0]
|
||||
|
||||
x = Tensor(np.arange(1 * 3 * 3 * 4).reshape((1, 3, 3, 4)), mstype.float32)
|
||||
tuple_getitem = TupleGetitemNet()
|
||||
grad = GradNet(tuple_getitem)
|
||||
grad.compile(x)
|
||||
|
||||
|
||||
def test_depend():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the depend op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class DependNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(DependNet, self).__init__()
|
||||
self.softmax = P.Softmax()
|
||||
self.depend = ops.Depend()
|
||||
|
||||
def construct(self, x, y):
|
||||
mul = x * y
|
||||
y = self.depend(y, mul)
|
||||
output = self.softmax(y)
|
||||
return output
|
||||
|
||||
x = Tensor(np.ones([4, 5]), mstype.float32)
|
||||
y = Tensor(np.ones([4, 5]), mstype.float32)
|
||||
depend = DependNet()
|
||||
grad = GradNet(depend)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_stop_gradient():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the stop_gradient op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class StopGradientNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(StopGradientNet, self).__init__()
|
||||
|
||||
def construct(self, x, y):
|
||||
c = x * y
|
||||
c_s = F.stop_gradient(c)
|
||||
return c_s
|
||||
|
||||
x = Tensor(np.ones([4, 5]), mstype.float32)
|
||||
y = Tensor(np.ones([4, 5]), mstype.float32)
|
||||
stop_gradient = StopGradientNet()
|
||||
grad = GradNet(stop_gradient)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_switch():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the switch op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class SwitchNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(SwitchNet, self).__init__()
|
||||
|
||||
def construct(self, x, y):
|
||||
if x > y:
|
||||
return x
|
||||
return y
|
||||
|
||||
x = Tensor(np.array([3]), mstype.float32)
|
||||
y = Tensor(np.array([2]), mstype.float32)
|
||||
switch_net = SwitchNet()
|
||||
grad = GradNet(switch_net)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_update_state():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the update_state op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class UpdateStateNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(UpdateStateNet, self).__init__()
|
||||
self.assign_add = P.AssignAdd()
|
||||
self.variable = Parameter(initializer(1, [1], mstype.int64), name="global_step")
|
||||
|
||||
def construct(self, x):
|
||||
return self.assign_add(self.variable, x)
|
||||
|
||||
value = Tensor(np.ones([1]).astype(np.int64) * 100)
|
||||
update_state = UpdateStateNet()
|
||||
grad = GradNet(update_state)
|
||||
grad.compile(value)
|
||||
|
||||
|
||||
def test_load():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the load op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
|
||||
class LoadNet(nn.Cell):
|
||||
def __init__(self):
|
||||
super(LoadNet, self).__init__()
|
||||
self.add = P.Add()
|
||||
self.variable = Parameter(initializer(1, [1], mstype.int64), name="global_step")
|
||||
|
||||
def construct(self, x):
|
||||
return self.add(self.variable, x)
|
||||
|
||||
value = Tensor(np.ones([1]).astype(np.int64) * 100)
|
||||
load = LoadNet()
|
||||
grad = GradNet(load)
|
||||
grad.compile(value)
|
||||
|
||||
|
||||
def test_floor_div():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the floor_div op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([2, 4, -1]), mstype.int32)
|
||||
y = Tensor(np.array([3, 3, 3]), mstype.int32)
|
||||
floor_div = Net(P.FloorDiv())
|
||||
grad = GradNet(floor_div)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_truncate_div():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the truncate_div op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([2, 4, -1]), mstype.int32)
|
||||
y = Tensor(np.array([3, 3, 3]), mstype.int32)
|
||||
truncate_div = Net(P.TruncateDiv())
|
||||
grad = GradNet(truncate_div)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_minimum():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the minimum op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([1.0, 5.0, 3.0]), mstype.float32)
|
||||
y = Tensor(np.array([4.0, 2.0, 6.0]), mstype.float32)
|
||||
minimum = Net(P.Minimum())
|
||||
grad = GradNet(minimum)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_maximum():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the maximum op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([1.0, 5.0, 3.0]), mstype.float32)
|
||||
y = Tensor(np.array([4.0, 2.0, 6.0]), mstype.float32)
|
||||
maximum = Net(P.Maximum())
|
||||
grad = GradNet(maximum)
|
||||
grad.compile(x, y)
|
||||
|
||||
|
||||
def test_is_nan():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the is_nan op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([np.log(-1), 1, np.log(0)]), mstype.float32)
|
||||
is_nan = Net(P.IsNan())
|
||||
grad = GradNet(is_nan)
|
||||
grad.compile(x)
|
||||
|
||||
|
||||
def test_is_inf():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the is_inf op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([np.log(-1), 1, np.log(0)]), mstype.float32)
|
||||
is_inf = Net(P.IsInf())
|
||||
grad = GradNet(is_inf)
|
||||
grad.compile(x)
|
||||
|
||||
|
||||
def test_relu_v2():
|
||||
"""
|
||||
Feature: Bprop pre-compilation.
|
||||
Description: Compile the backward graph for the relu_v2 op.
|
||||
Expectation: Load the bprop mindir successfully.
|
||||
"""
|
||||
x = Tensor(np.array([[[[1, -2], [-3, 4]], [[-5, 6], [7, -8]]]]), mstype.float32)
|
||||
relu_v2 = Net(P.ReLUV2())
|
||||
grad = GradNet(relu_v2)
|
||||
grad.compile(x)
|
||||
|
|
|
@ -268,6 +268,7 @@ def vm_impl_sum(self):
|
|||
|
||||
|
||||
@vm_impl_getters.register(P.Select)
|
||||
@vm_impl_getters.register(P.Select.__name__)
|
||||
def vm_impl_select(self):
|
||||
"""Generate vm_impl function for Select"""
|
||||
|
||||
|
|
|
@ -220,6 +220,7 @@ def vm_impl_fused_batch_norm_grad(self):
|
|||
|
||||
|
||||
@vm_impl_getters.register(G.ReluGrad)
|
||||
@vm_impl_getters.register(G.ReluGrad.__name__)
|
||||
def vm_impl_relu_grad(self):
|
||||
"""Generate vm_impl function for ReluGrad"""
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Copyright 2021 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.
|
||||
# ============================================================================
|
||||
"""Generate vm_impl function for nn ops without python object"""
|
||||
from mindspore.common.tensor import Tensor
|
||||
from .vm_interface import vm
|
||||
|
||||
def ReluGrad(y_backprop, x):
|
||||
x = x.asnumpy()
|
||||
y_backprop = y_backprop.asnumpy()
|
||||
y_backprop = vm.relu_grad(x.copy()) * y_backprop
|
||||
return Tensor(y_backprop)
|
Loading…
Reference in New Issue