diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index dc380f83bf71beb3cd935567c0f8c10af091d56e..d5ee0c2a47b00224a0eecbbd8a229ed3b9327afa 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -1921,7 +1921,7 @@ All parameter, weight, gradient are variables in Paddle. Prune the backward part of a program, mostly called in program.clone(for_test=True). - Args: + Args: program (ProgramDesc): The original program. Returns: @@ -1930,6 +1930,17 @@ All parameter, weight, gradient are variables in Paddle. which contains the id pair of pruned block and corresponding origin block. )DOC"); + m.def("get_readable_comile_key", [](const OpDesc &op_desc) { + auto compilation_key = + BOOST_GET_CONST(std::string, op_desc.GetAttr("compilation_key")); + VLOG(4) << std::hash{}(compilation_key) << " " + << compilation_key.size(); + proto::ProgramDesc desc; + desc.ParseFromString(compilation_key); + auto s = desc.DebugString(); + VLOG(4) << s; + return s; + }); m.def("empty_var_name", []() { return std::string(framework::kEmptyVarName); }); m.def("grad_var_suffix", diff --git a/paddle/fluid/pybind/pybind_boost_headers.h b/paddle/fluid/pybind/pybind_boost_headers.h index 3eb4db175a745c8ea7a3afaff919e4f21d430a8b..be9333eb7361b429966250639a18762aeaf2e249 100644 --- a/paddle/fluid/pybind/pybind_boost_headers.h +++ b/paddle/fluid/pybind/pybind_boost_headers.h @@ -45,10 +45,28 @@ struct PYBIND11_HIDDEN paddle_variant_caster_visitor paddle_variant_caster_visitor(return_value_policy policy, handle parent) : policy(policy), parent(parent) {} - template - handle operator()(T const &src) const { + template ::value, + bool>::type* = nullptr> + handle operator()(T const& src) const { return make_caster::cast(src, policy, parent); } + + template ::value, + bool>::type* = nullptr> + handle operator()(T const& src) const { + try { + return make_caster::cast(src, policy, parent); + } catch (std::exception& ex) { + VLOG(4) << ex.what(); + VLOG(4) << src; + // UnicodeDecodeError, src is not utf-8 encoded + // see details: + // https://github.com/pybind/pybind11/blob/master/docs/advanced/cast/strings.rst + return PYBIND11_BYTES_FROM_STRING_AND_SIZE(src.data(), src.size()); + } + } }; template @@ -105,7 +123,7 @@ struct paddle_variant_caster> { return load_success_; } - static handle cast(Type const &src, return_value_policy policy, + static handle cast(Type const& src, return_value_policy policy, handle parent) { paddle_variant_caster_visitor visitor(policy, parent); return boost::apply_visitor(visitor, src); diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 817e742fd1d8a5146a67464f326f007e91d04040..16a5e254725576746995c22defc6f028a676563c 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -2863,8 +2863,22 @@ class Operator(object): attrs_str += ", " continue + # it is bytes of serialized protobuf + if self.type == 'cinn_launch' and name == 'compilation_key': + # value = core.get_readable_comile_key(self.desc) + v = self.desc.attr(name) + prog = Program() + prog = prog.parse_from_string(v) + s = prog._to_readable_code() + lines = s.split('\n') + value = '\n'.join([' ' + line for line in lines]) + value = '\n' + value + else: + value = self.desc.attr(name) + a = "{name} = {value}".format( - name=name, type=attr_type, value=self.desc.attr(name)) + name=name, type=attr_type, value=value) + attrs_str += a if i != len(attr_names) - 1: attrs_str += ", "