paddle.static. Print ( input, first_n=- 1, message=None, summarize=20, print_tensor_name=True, print_tensor_type=True, print_tensor_shape=True, print_tensor_layout=True, print_tensor_lod=True, print_phase='both' ) [source]

Static Graph

Print operator

This creates a print op that will print when a tensor is accessed.

Wraps the tensor passed in so that whenever that a tensor is accessed, the message message is printed, along with the current value of the tensor t.

  • input (Variable) – A Tensor to print.

  • summarize (int) – Number of elements in the tensor to be print. If it’s value is -1, then all elements in the tensor will be print.

  • message (str) – A string message to print as a prefix.

  • first_n (int) – Only log first_n number of times.

  • print_tensor_name (bool, optional) – Print the tensor name. Default: True.

  • print_tensor_type (bool, optional) – Print the tensor type. Defaultt: True.

  • print_tensor_shape (bool, optional) – Print the tensor shape. Default: True.

  • print_tensor_layout (bool, optional) – Print the tensor layout. Default: True.

  • print_tensor_lod (bool, optional) – Print the tensor lod. Default: True.

  • print_phase (str) – Which phase to displace, including ‘forward’, ‘backward’ and ‘both’. Default: ‘both’. If set to ‘backward’, will only print the gradients of input tensor; If set to ‘both’, will both print the input tensor itself and the gradients of input tensor.


Output tensor.

Return type



The input and output are two different variables, and in the following process, you should use the output variable but not the input, otherwise, the print layer doesn’t have backward.


import paddle


x = paddle.full(shape=[2, 3], fill_value=3, dtype='int64')
out = paddle.static.Print(x, message="The content of input layer:")

main_program = paddle.static.default_main_program()
exe = paddle.static.Executor(place=paddle.CPUPlace())
res =, fetch_list=[out])
# Variable: fill_constant_1.tmp_0
#   - message: The content of input layer:
#   - lod: {}
#   - place: CPUPlace
#   - shape: [2, 3]
#   - layout: NCHW
#   - dtype: long
#   - data: [3 3 3 3 3 3]