|
|
|
@ -62,9 +62,12 @@ def variable_to_code(var):
|
|
|
|
|
Returns:
|
|
|
|
|
string: The formatted string.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if var.type == core.VarDesc.VarType.SELECTED_ROWS or var.type == core.VarDesc.VarType.LOD_TENSOR:
|
|
|
|
|
var_str = "{name} : fluid.{type}.shape{shape}.astype({dtype})".\
|
|
|
|
|
format(i="{", e="}", name=var.name, type=var.type, shape=var.shape, dtype=var.dtype)
|
|
|
|
|
else:
|
|
|
|
|
var_str = "{name} : fluid.{type})".\
|
|
|
|
|
format(i="{", e="}", name=var.name, type=var.type)
|
|
|
|
|
|
|
|
|
|
if type(var) == paddle.fluid.framework.Parameter:
|
|
|
|
|
if var.trainable:
|
|
|
|
@ -142,27 +145,17 @@ def op_to_code(op):
|
|
|
|
|
return op_str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def program_to_code(prog):
|
|
|
|
|
"""
|
|
|
|
|
Print readable codes of fluid program.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
prog : A fluid program.
|
|
|
|
|
|
|
|
|
|
An example result like bellow:
|
|
|
|
|
https://github.com/PaddlePaddle/Paddle/pull/12673
|
|
|
|
|
"""
|
|
|
|
|
def block_to_code(block, block_idx):
|
|
|
|
|
indent = 0
|
|
|
|
|
block_idx = 0
|
|
|
|
|
for block in prog.blocks:
|
|
|
|
|
|
|
|
|
|
print("{0}{1} // block {2}".format(
|
|
|
|
|
get_indent_space(indent), '{', block_idx))
|
|
|
|
|
|
|
|
|
|
indent += 1
|
|
|
|
|
# sort all vars
|
|
|
|
|
all_vars = sorted(six.iteritems(block.vars), key=lambda x: x[0])
|
|
|
|
|
all_vars = sorted(block.vars.iteritems(), key=lambda x: x[0])
|
|
|
|
|
for var in all_vars:
|
|
|
|
|
print("{}{}".format(
|
|
|
|
|
get_indent_space(indent), variable_to_code(var[1])))
|
|
|
|
|
print("{}{}".format(get_indent_space(indent), variable_to_code(var[1])))
|
|
|
|
|
|
|
|
|
|
if len(all_vars) > 0:
|
|
|
|
|
print("")
|
|
|
|
@ -170,5 +163,21 @@ def program_to_code(prog):
|
|
|
|
|
for op in block.ops:
|
|
|
|
|
print("{}{}".format(get_indent_space(indent), op_to_code(op)))
|
|
|
|
|
indent -= 1
|
|
|
|
|
|
|
|
|
|
print("{0}{1}".format(get_indent_space(indent), '}'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def program_to_code(prog):
|
|
|
|
|
"""
|
|
|
|
|
Print readable codes of fluid program.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
prog : A fluid program.
|
|
|
|
|
|
|
|
|
|
An example result like bellow:
|
|
|
|
|
https://github.com/PaddlePaddle/Paddle/pull/12673
|
|
|
|
|
"""
|
|
|
|
|
block_idx = 0
|
|
|
|
|
for block in prog.blocks:
|
|
|
|
|
block_to_code(block, block_idx)
|
|
|
|
|
block_idx += 1
|
|
|
|
|