forked from huawei/mindspore2022
Fix bug of ConvertData in data_converter.cc
This commit is contained in:
parent
9b8d38eab4
commit
af22653b60
|
|
@ -81,9 +81,7 @@ PYBIND11_MODULE(_c_expression, m) {
|
|||
.def("has_compiled", &ExecutorPy::HasCompiled, py::arg("phase") = py::str(""), "get if cell compiled.")
|
||||
.def("run_init_graph", &ExecutorPy::RunInitGraph, "Run init Graph.");
|
||||
|
||||
(void)py::class_<EnvInstance, std::shared_ptr<EnvInstance>>(m, "EnvInstance_")
|
||||
.def_readonly(mindspore::PYTHON_ENVINSTANCE_FLAG, &mindspore::EnvInstance::parse_info_)
|
||||
.def(py::init());
|
||||
(void)py::class_<EnvInstance, std::shared_ptr<EnvInstance>>(m, "EnvInstance_").def(py::init());
|
||||
|
||||
(void)m.def("generate_key", &mindspore::pipeline::GenerateKey, "Generate the function graph key.");
|
||||
(void)m.def("real_run_op", &mindspore::pynative::RunOp, "Run op pynatively.");
|
||||
|
|
|
|||
|
|
@ -361,15 +361,15 @@ bool ConvertData(const py::object &obj, ValuePtr *const data, bool use_signature
|
|||
ConvertDataClass(obj, &converted);
|
||||
} else if (py::hasattr(obj, PYTHON_PRIMITIVE_FLAG)) {
|
||||
ret = ConvertPrimitive(obj, &converted, use_signature);
|
||||
} else if (py::hasattr(obj, PYTHON_METAFUNCGRAPH_FLAG)) {
|
||||
} else if (py::isinstance<MetaFuncGraph>(obj)) {
|
||||
ret = ConvertMetaFuncGraph(obj, &converted, use_signature);
|
||||
} else if (py::hasattr(obj, PYTHON_DTYPE_FLAG)) {
|
||||
} else if (py::isinstance<Type>(obj)) {
|
||||
ret = ConvertDataType(obj, &converted);
|
||||
} else if (py::hasattr(obj, PYTHON_TENSOR_FLAG)) {
|
||||
} else if (py::isinstance<Tensor>(obj)) {
|
||||
ret = ConvertTensor(obj, &converted);
|
||||
} else if (py::hasattr(obj, PYTHON_META_TENSOR_FLAG)) {
|
||||
} else if (py::isinstance<MetaTensor>(obj)) {
|
||||
ret = ConvertMetaTensor(obj, &converted);
|
||||
} else if (py::hasattr(obj, PYTHON_ENVINSTANCE_FLAG)) {
|
||||
} else if (py::isinstance<EnvInstance>(obj)) {
|
||||
std::shared_ptr<EnvInstance> env = obj.cast<std::shared_ptr<EnvInstance>>();
|
||||
converted = env;
|
||||
} else if (py::hasattr(obj, PYTHON_CLASS_MEMBER_NAMESPACE)) {
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ py::bool_ VerifyInputSignature(const py::list input_signature, const py::tuple i
|
|||
|
||||
size_t count = 0;
|
||||
for (auto arg_obj : inputs) {
|
||||
if (py::hasattr(arg_obj, PYTHON_TENSOR_FLAG)) {
|
||||
if (py::isinstance<Tensor>(arg_obj)) {
|
||||
MS_LOG(DEBUG) << "Verify Tensor";
|
||||
std::shared_ptr<Tensor> m_tensor = arg_obj.cast<std::shared_ptr<Tensor>>();
|
||||
if (m_tensor == nullptr) {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ void ConvertObjectToTensors(const py::dict &dict, TensorOrderMap *const tensors)
|
|||
// convert int to tensor with shape([1])
|
||||
tensor = std::make_shared<Tensor>(kNumberTypeInt32, std::vector<int>({1}));
|
||||
*(static_cast<float *>(tensor->data_c())) = py::cast<float>(item.second.attr("default_input"));
|
||||
} else if (py::hasattr(item.second.attr("default_input"), PYTHON_TENSOR_FLAG)) {
|
||||
} else if (py::isinstance<Tensor>(item.second.attr("default_input"))) {
|
||||
// cast tensor
|
||||
tensor = py::cast<std::shared_ptr<Tensor>>(item.second.attr("default_input"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@
|
|||
namespace mindspore {
|
||||
|
||||
const char PYTHON_PRIMITIVE_FLAG[] = "__primitive_flag__";
|
||||
const char PYTHON_METAFUNCGRAPH_FLAG[] = "__metafuncgraph_flag__";
|
||||
const char PYTHON_TENSOR_FLAG[] = "__tensor_flag__";
|
||||
const char PYTHON_META_TENSOR_FLAG[] = "__meta_tensor_flag__";
|
||||
const char PYTHON_ENVINSTANCE_FLAG[] = "__envinstance_flag__";
|
||||
const char PYTHON_DTYPE_FLAG[] = "__dtype_flag__";
|
||||
const char PYTHON_CELL_AS_LIST[] = "__cell_as_list__";
|
||||
const char PYTHON_DATACLASS_FIELDS[] = "__dataclass_fields__";
|
||||
const char PYTHON_CLASS_MEMBER_NAMESPACE[] = "__class_member_namespace__";
|
||||
|
|
|
|||
|
|
@ -20,11 +20,6 @@
|
|||
namespace mindspore {
|
||||
|
||||
extern const char PYTHON_PRIMITIVE_FLAG[];
|
||||
extern const char PYTHON_METAFUNCGRAPH_FLAG[];
|
||||
extern const char PYTHON_TENSOR_FLAG[];
|
||||
extern const char PYTHON_META_TENSOR_FLAG[];
|
||||
extern const char PYTHON_ENVINSTANCE_FLAG[];
|
||||
extern const char PYTHON_DTYPE_FLAG[];
|
||||
extern const char PYTHON_CELL_AS_LIST[];
|
||||
extern const char PYTHON_DATACLASS_FIELDS[];
|
||||
extern const char PYTHON_CLASS_MEMBER_NAMESPACE[];
|
||||
|
|
|
|||
|
|
@ -367,8 +367,7 @@ py::object VectorRefToPyData(const VectorRef &value_list) {
|
|||
}
|
||||
|
||||
AbstractBasePtr PyListDtype2AbstractTensor(const py::object &shape_obj, const py::object &type_obj) {
|
||||
if ((py::isinstance<py::list>(shape_obj) || py::isinstance<py::tuple>(shape_obj)) &&
|
||||
py::hasattr(type_obj, PYTHON_DTYPE_FLAG)) {
|
||||
if ((py::isinstance<py::list>(shape_obj) || py::isinstance<py::tuple>(shape_obj)) && py::isinstance<Type>(type_obj)) {
|
||||
auto ret_vec = shape_obj.cast<std::vector<int>>();
|
||||
auto ret_dtype = type_obj.cast<TypePtr>();
|
||||
MS_EXCEPTION_IF_NULL(ret_dtype);
|
||||
|
|
|
|||
|
|
@ -162,8 +162,6 @@ class EnvInstance : public Value {
|
|||
return Len();
|
||||
}
|
||||
|
||||
const bool parse_info_ = true;
|
||||
|
||||
private:
|
||||
EnvInstanceContentsMap contents_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -84,8 +84,6 @@ class Type : public Value {
|
|||
friend std::ostream &operator<<(std::ostream &os, const Type &type);
|
||||
friend std::ostream &operator<<(std::ostream &os, const TypePtr type);
|
||||
|
||||
const bool parse_info_ = true;
|
||||
|
||||
private:
|
||||
TypeId meta_type_;
|
||||
bool is_generic_;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ REGISTER_PYBIND_DEFINE(
|
|||
"dump_type", [](const TypePtr &t) { return t->type_id(); }, "dump type");
|
||||
(void)m_sub.def("str_to_type", &StringToType, "string to typeptr");
|
||||
(void)py::class_<Type, std::shared_ptr<Type>>(m_sub, "Type")
|
||||
.def_readonly(PYTHON_DTYPE_FLAG, &mindspore::Type::parse_info_)
|
||||
.def("__eq__",
|
||||
[](const TypePtr &t1, const py::object &other) {
|
||||
if (!py::isinstance<Type>(other)) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace mindspore {
|
|||
REGISTER_PYBIND_DEFINE(FuncGraph, ([](const pybind11::module *m) {
|
||||
// Define python "MetaFuncGraph_" class
|
||||
(void)py::class_<MetaFuncGraph, std::shared_ptr<MetaFuncGraph>>(*m, "MetaFuncGraph_")
|
||||
.def_readonly(PYTHON_METAFUNCGRAPH_FLAG, &MetaFuncGraph::parse_info_)
|
||||
// .def_readonly(PYTHON_METAFUNCGRAPH_FLAG, &MetaFuncGraph::parse_info_)
|
||||
.def(py::init<std::string &>());
|
||||
// Define python "FuncGraph" class
|
||||
(void)py::class_<FuncGraph, FuncGraphPtr>(*m, "FuncGraph")
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class MetaFuncGraph : public FuncGraphBase {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
const bool parse_info_ = true;
|
||||
// const bool parse_info_ = true;
|
||||
|
||||
protected:
|
||||
template <typename Derived>
|
||||
|
|
|
|||
|
|
@ -163,7 +163,6 @@ class MetaTensor : public Value {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
const bool parse_info_ = true;
|
||||
|
||||
protected:
|
||||
// brief Data type of the tensor.
|
||||
|
|
|
|||
|
|
@ -224,8 +224,6 @@ class Tensor : public MetaTensor {
|
|||
|
||||
std::string id() const { return id_; }
|
||||
|
||||
const bool parse_info_ = true;
|
||||
|
||||
private:
|
||||
bool init_flag_{false};
|
||||
TensorDataPtr data_{nullptr};
|
||||
|
|
|
|||
|
|
@ -214,7 +214,6 @@ REGISTER_PYBIND_DEFINE(Tensor, ([](const py::module *m) {
|
|||
// Define python MetaTensor class.
|
||||
(void)py::class_<MetaTensor, std::shared_ptr<MetaTensor>>(*m, "MetaTensor")
|
||||
.def(py::init<TypePtr, const std::vector<int>>(), py::arg("dtype"), py::arg("shape"))
|
||||
.def_readonly(PYTHON_META_TENSOR_FLAG, &MetaTensor::parse_info_)
|
||||
.def_property_readonly("dtype", &MetaTensor::Dtype, "Get the MetaTensor's dtype.")
|
||||
.def_property_readonly("shape", &MetaTensor::shape, "Get the MetaTensor's shape.")
|
||||
.def(py::pickle(
|
||||
|
|
@ -268,7 +267,6 @@ REGISTER_PYBIND_DEFINE(Tensor, ([](const py::module *m) {
|
|||
return TensorPy::MakeTensor(py::array(input), type_ptr);
|
||||
}),
|
||||
py::arg("input"), py::arg("dtype") = nullptr)
|
||||
.def_readonly(PYTHON_TENSOR_FLAG, &Tensor::parse_info_)
|
||||
.def_property("init_flag", &Tensor::is_init, &Tensor::set_init_flag)
|
||||
.def_property_readonly("dtype", &Tensor::Dtype, R"mydelimiter(
|
||||
Get the tensor's data type.
|
||||
|
|
|
|||
Loading…
Reference in New Issue