!20672 add dump ir for python and add dump more info when dynamic shape

Merge pull request !20672 from lianliguang/add_dump_func
This commit is contained in:
i-robot 2021-07-26 06:53:42 +00:00 committed by Gitee
commit fd7c0c1514
4 changed files with 15 additions and 7 deletions

View File

@ -68,7 +68,7 @@ void PrintNodeOutputType(std::ostringstream &buffer, const AnfNodePtr &nd) {
abstract::ShapePtr shape = dyn_cast<abstract::Shape>(nd->Shape());
TypePtr type = dyn_cast<Type>(nd->Type());
if ((shape != nullptr) && (type != nullptr)) {
buffer << "<" << type << "x" << shape->shape() << ">";
buffer << "<" << type << "x" << shape->ToString() << ">";
} else if (type != nullptr) {
buffer << "<" << type << ">";
} else {

View File

@ -1226,7 +1226,15 @@ void ExportGraph(const std::string &file_name, const std::string &, const std::s
FuncGraphPtr LoadMindIR(const std::string &file_name, char *dec_key, const size_t key_len,
const std::string &dec_mode) {
return mindspore::LoadMindIR(file_name, false, reinterpret_cast<unsigned char *>(dec_key), key_len, dec_mode);
auto func_graph =
mindspore::LoadMindIR(file_name, false, reinterpret_cast<unsigned char *>(dec_key), key_len, dec_mode);
auto context_ptr = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(context_ptr);
bool save_graphs = context_ptr->get_param<bool>(MS_CTX_SAVE_GRAPHS_FLAG);
if (save_graphs) {
DumpIR("load.ir", func_graph);
}
return func_graph;
}
void ReleaseGeTsd() {

View File

@ -67,15 +67,15 @@ std::string Shape::ToString() const {
std::ostringstream buffer;
bool has_dyn_shape = IsDynamic();
if (has_dyn_shape) {
buffer << "{ shape : ";
buffer << "{shape:";
}
buffer << ShapeVectorToStr(shape_);
if (has_dyn_shape) {
buffer << " | min shape: ";
buffer << "|min shape:";
buffer << ShapeVectorToStr(min_shape_);
buffer << " | max shape: ";
buffer << "|max shape:";
buffer << ShapeVectorToStr(max_shape_);
buffer << " }";
buffer << "}";
}
return buffer.str();
}

View File

@ -69,7 +69,7 @@ TEST_F(TestDShape, ToString) {
ASSERT_EQ(shp_3.ToString(), "(1, 2)");
ASSERT_EQ(shp_noshp_1.ToString(), "NoShape");
ASSERT_EQ(shp_tuple_2.ToString(), "TupleShape(NoShape, (1, 1, 1))");
ASSERT_EQ(shp_5.ToString(), "{ shape : (-1, 2) | min shape: (1, 2) | max shape: (3, 3) }");
ASSERT_EQ(shp_5.ToString(), "{shape:(-1, 2)|min shape:(1, 2)|max shape:(3, 3)}");
}
TEST_F(TestDShape, Clone) {