Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debuger bugs. #9705

Merged
merged 3 commits into from
Apr 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions python/paddle/fluid/debuger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
from graphviz import GraphPreviewGenerator
import proto.framework_pb2 as framework_pb2
from google.protobuf import text_format

_vartype2str_ = [
"UNK",
Expand Down Expand Up @@ -100,7 +101,7 @@ def repr_var(vardesc):

def pprint_program_codes(program_desc):
reprs = []
for block_idx in range(program_desc.num_blocks()):
for block_idx in range(program_desc.desc.num_blocks()):
block_desc = program_desc.block(block_idx)
block_repr = pprint_block_codes(block_desc)
reprs.append(block_repr)
Expand All @@ -127,7 +128,7 @@ def is_var_backward(var_desc):

if type(block_desc) is not framework_pb2.BlockDesc:
block_desc = framework_pb2.BlockDesc.FromString(
block_desc.serialize_to_string())
block_desc.desc.serialize_to_string())
var_reprs = []
op_reprs = []
for var in block_desc.vars:
Expand Down Expand Up @@ -237,13 +238,13 @@ def need_highlight(name):
# draw parameters and args
vars = {}
for var in desc.vars:
shape = [str(i) for i in var.lod_tensor.tensor.dims]
if not shape:
shape = ['null']
# TODO(gongwb): format the var.type
# create var
if var.persistable:
varn = graph.add_param(
var.name, var.type, shape, highlight=need_highlight(var.name))
var.name,
str(var.type).replace("\n", "<br />", 1),
highlight=need_highlight(var.name))
else:
varn = graph.add_arg(var.name, highlight=need_highlight(var.name))
vars[var.name] = varn
Expand All @@ -268,4 +269,4 @@ def add_op_link_var(op, var, op2var=False):
for var in op.outputs:
add_op_link_var(opn, var, True)

graph(path, show=True)
graph(path, show=False)
9 changes: 2 additions & 7 deletions python/paddle/fluid/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def compile(self, dot_path):
file = open(dot_path, 'w')
file.write(self.__str__())
image_path = os.path.join(
os.path.dirname(__file__), dot_path[:-3] + "pdf")
os.path.dirname(dot_path), dot_path[:-3] + "pdf")
cmd = ["dot", "-Tpdf", dot_path, "-o", image_path]
subprocess.Popen(
cmd,
Expand Down Expand Up @@ -199,7 +199,7 @@ def __call__(self, path='temp.dot', show=False):
else:
self.graph.show(path)

def add_param(self, name, data_type, shape, highlight=False):
def add_param(self, name, data_type, highlight=False):
label = '\n'.join([
'<<table cellpadding="5">',
' <tr>',
Expand All @@ -214,11 +214,6 @@ def add_param(self, name, data_type, shape, highlight=False):
str(data_type),
' </td>'
' </tr>',
' <tr>',
' <td>',
'[%s]' % 'x'.join(shape),
' </td>'
' </tr>',
'</table>>',
])
return self.graph.node(
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/fluid/tests/unittests/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def test_debug_str(self):
outputs={"Out": mul_out},
attrs={"x_num_col_dims": 1})

print(debuger.pprint_program_codes(p.desc))
print(debuger.pprint_program_codes(p))

debuger.draw_block_graphviz(p.block(0), path="./test.dot")


if __name__ == '__main__':
Expand Down