MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _to_readable_code

Method _to_readable_code

python/paddle/base/framework.py:4385–4430  ·  view source on GitHub ↗

Get readable debug string of Block. .. note:: If you want to get the debug string in protobuf format, please use :code:`to_string` method. Args: skip_op_callstack(bool): whether to skip parsing Operator's attribute op_cal

(self, skip_op_callstack=True)

Source from the content-addressed store, hash-verified

4383 return self._to_readable_code()
4384
4385 def _to_readable_code(self, skip_op_callstack=True):
4386 """
4387 Get readable debug string of Block.
4388
4389 .. note::
4390 If you want to get the debug string in protobuf format,
4391 please use :code:`to_string` method.
4392
4393 Args:
4394 skip_op_callstack(bool): whether to skip parsing Operator's attribute
4395 op_callstack, default value is True
4396
4397 Returns:
4398 string: The formatted Block string.
4399
4400 Examples:
4401 .. code-block:: pycon
4402
4403 >>> import paddle
4404
4405 >>> paddle.enable_static()
4406 >>> cur_program = paddle.static.Program()
4407 >>> cur_block = cur_program.current_block()
4408 >>> new_var = cur_block.create_var(
4409 ... name="X",
4410 ... shape=[-1, 23, 48],
4411 ... dtype="float32",
4412 ... )
4413 >>> new_op = cur_block.append_op(
4414 ... type="abs",
4415 ... inputs={"X": [new_var]},
4416 ... outputs={"Out": [new_var]},
4417 ... )
4418 >>> print(cur_block._to_readable_code())
4419 """
4420 assert isinstance(skip_op_callstack, bool), (
4421 f"skip_op_callstack parameter's type is error, expect bool, received {type(skip_op_callstack)}"
4422 )
4423 block_str = f"{{ // block_idx:{self.idx} parent_idx:{self.parent_idx} forward_idx:{self.forward_block_idx} backward_idx:{self.backward_block_idx}\n"
4424 for var in list(self.vars.values()):
4425 block_str += f" {var._to_readable_code()}\n"
4426 block_str += "\n"
4427 for op in self.ops:
4428 block_str += f" {op._to_readable_code(skip_op_callstack)}\n"
4429 block_str += "}"
4430 return block_str
4431
4432 def to_string(self, throw_on_error, with_details=False):
4433 """

Callers 3

__str__Method · 0.95
_to_readable_codeMethod · 0.45
__str__Method · 0.45

Calls 3

listFunction · 0.85
typeFunction · 0.50
valuesMethod · 0.45

Tested by

no test coverage detected