Created by: chenwhql
In order to get simpler and clearer debug strings, add _to_readable_code
method to Program
, Block
, Operator
, Variable
, and change method __str__
to call to_readable_code
method by default.
-
There is almost no information loss in this conversion, but the information density is increased
-
why add new API instead of changing old method
to_string
?-
to_string
interface has been existed for a long time, not sure if changing it will cause compatibility problems for some users - keep
to_string
interface unchanged, users still can easily get the original ptotobuf string throughto_string
, orprint(Program.to_string())
-
For a same program:
- The new debug string example:
{ // block 0
var X : fluid.VarType.LOD_TENSOR.shape(-1, 23, 48).astype(VarType.FP32)
persist trainable param W : fluid.VarType.LOD_TENSOR.shape(23, 48).astype(VarType.FP32)
{Out=['X']} = abs(inputs={X=['X']}, op_device = , op_namescope = /, op_role = 0, op_role_var = [], use_cudnn = False, use_mkldnn = False)
}
- The old debug string example:
blocks {
idx: 0
parent_idx: -1
vars {
name: "W"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: 23
dims: 48
}
}
}
persistable: true
}
vars {
name: "X"
type {
type: LOD_TENSOR
lod_tensor {
tensor {
data_type: FP32
dims: -1
dims: 23
dims: 48
}
lod_level: 0
}
}
}
ops {
inputs {
parameter: "X"
arguments: "X"
}
outputs {
parameter: "Out"
arguments: "X"
}
type: "abs"
attrs {
name: "op_device"
type: STRING
s: ""
}
attrs {
name: "use_cudnn"
type: BOOLEAN
b: false
}
attrs {
name: "op_role"
type: INT
i: 0
}
attrs {
name: "op_role_var"
type: STRINGS
}
attrs {
name: "op_callstack"
type: STRINGS
strings: " File \"/usr/local/lib/python3.5/dist-packages/paddle/fluid/framework.py\", line 2730, in append_op\n attrs=kwargs.get(\"attrs\", None))\n"
strings: " File \"../python/paddle/fluid/tests/unittests/test_program_code.py\", line 90, in setUp\n type=\"abs\", inputs={\"X\": [self.var]}, outputs={\"Out\": [self.var]})\n"
strings: " File \"/usr/lib/python3.5/unittest/case.py\", line 596, in run\n self.setUp()\n"
strings: " File \"/usr/lib/python3.5/unittest/case.py\", line 648, in __call__\n return self.run(*args, **kwds)\n"
strings: " File \"/usr/lib/python3.5/unittest/suite.py\", line 122, in run\n test(result)\n"
strings: " File \"/usr/lib/python3.5/unittest/suite.py\", line 84, in __call__\n return self.run(*args, **kwds)\n"
strings: " File \"/usr/lib/python3.5/unittest/suite.py\", line 122, in run\n test(result)\n"
strings: " File \"/usr/lib/python3.5/unittest/suite.py\", line 84, in __call__\n return self.run(*args, **kwds)\n"
strings: " File \"/usr/lib/python3.5/unittest/runner.py\", line 176, in run\n test(result)\n"
strings: " File \"/usr/lib/python3.5/unittest/main.py\", line 255, in runTests\n self.result = testRunner.run(self.test)\n"
strings: " File \"/usr/lib/python3.5/unittest/main.py\", line 94, in __init__\n self.runTests()\n"
strings: " File \"../python/paddle/fluid/tests/unittests/test_program_code.py\", line 117, in <module>\n unittest.main()\n"
}
attrs {
name: "op_namescope"
type: STRING
s: "/"
}
attrs {
name: "use_mkldnn"
type: BOOLEAN
b: false
}
}
}
version {
version: 0
}