Browse Source

!18110 secure check

Merge pull request !18110 from zhangzhaoju/ms_master_sec_review
tags/v1.3.0
i-robot Gitee 4 years ago
parent
commit
674f8101db
4 changed files with 5 additions and 25 deletions
  1. +2
    -17
      mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc
  2. +0
    -3
      mindspore/ccsrc/pybind_api/ir/base_ref_py.h
  3. +3
    -3
      mindspore/ccsrc/pybind_api/ir/cell_py.cc
  4. +0
    -2
      mindspore/ccsrc/pybind_api/ir/primitive_py.h

+ 2
- 17
mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc View File

@@ -480,26 +480,11 @@ py::dict ConvertAbstractToPython(const AbstractBasePtr &abs_base) {

namespace {
py::tuple PreparePyInputs(const PrimitivePyPtr &prim_py, const AbstractBasePtrList &args) {
const AbstractBasePtrList *args_ptr;

if (prim_py->is_tuple_input_) {
if (args.empty()) {
MS_LOG(EXCEPTION) << "Primitive args is empty";
}
if (args[0] == nullptr || !args[0]->isa<AbstractTuple>()) {
MS_LOG(EXCEPTION) << "Custom Primitive inputs should be packed into a Tuple after converting"
"prim convert pass for GE.";
}
args_ptr = &(args[0]->cast<AbstractTuplePtr>()->elements());
} else {
args_ptr = &args;
}

// The monad parameter is defined at the end of the parameter and needs to be ignored
std::size_t size_args = args_ptr->size() - GetAbstractMonadNum(*args_ptr);
std::size_t size_args = args.size() - GetAbstractMonadNum(args);
py::tuple py_args(size_args);
for (size_t i = 0; i < size_args; i++) {
auto arg_i = (*args_ptr)[i];
auto arg_i = (args)[i];
py_args[i] = ConvertAbstractToPython(arg_i);
}
return py_args;


+ 0
- 3
mindspore/ccsrc/pybind_api/ir/base_ref_py.h View File

@@ -26,9 +26,6 @@
namespace py = pybind11;

namespace mindspore {
class PyObjectRef;
inline std::shared_ptr<PyObjectRef> MakeNode(const py::object &a) { return std::make_shared<PyObjectRef>(a); }
inline std::shared_ptr<PyObjectRef> MakeNode(const py::tuple &a) { return std::make_shared<PyObjectRef>(a); }

class PyObjectRef : public BaseRef {
public:


+ 3
- 3
mindspore/ccsrc/pybind_api/ir/cell_py.cc View File

@@ -23,8 +23,8 @@

namespace mindspore {
void CellPy::AddAttr(CellPtr cell, const std::string &name, const py::object &obj) {
std::string attr_name = name;
ValuePtr converted_ret = nullptr;
MS_EXCEPTION_IF_NULL(cell);
if (py::isinstance<py::module>(obj)) {
MS_LOG(EXCEPTION) << "Cell set_attr failed, attr should not be py::module";
}
@@ -32,8 +32,8 @@ void CellPy::AddAttr(CellPtr cell, const std::string &name, const py::object &ob
if (!converted) {
MS_LOG(DEBUG) << "Attribute convert error with type: " << std::string(py::str(obj));
} else {
MS_LOG(DEBUG) << cell->ToString() << " add attr " << attr_name << converted_ret->ToString();
cell->AddAttr(attr_name, converted_ret);
MS_LOG(DEBUG) << cell->ToString() << " add attr " << name << converted_ret->ToString();
cell->AddAttr(name, converted_ret);
}
}
// Define python 'Cell' class.


+ 0
- 2
mindspore/ccsrc/pybind_api/ir/primitive_py.h View File

@@ -71,11 +71,9 @@ class PrimitivePy : public Primitive {
py::dict RunInfer(const py::tuple &args);
void RunCheck(const py::tuple &args);
py::object RunInferValue(const py::tuple &args);
bool ObjHasAttr(const char *attr_name) { return py::hasattr(python_obj_, attr_name); }
bool HasPyObj() { return python_obj_.operator bool(); }
PrimitivePtr Clone() override;
PrimitivePyAdapterPtr adapter() const { return adapter_; }
bool is_tuple_input_ = false;

private:
py::function GetComputeFunction() const;


Loading…
Cancel
Save