paddle.static. default_main_program ( ) [source]

This API can be used to get default main program which store the descriptions of Ops and tensors.

For example z = paddle.add(x, y) will create a new add Op and a new z tensor, and they will be recorded in default main program .

The default main program is the default value for Program parameter in a lot of APIs. For example, the will execute the default_main_program when the program is not specified.

If you want to switch the default main program, you can use api_paddle_base_framework_program_guard .


A Program which holding the descriptions of OPs and tensors in the network.

Return type



>>> import paddle

>>> paddle.enable_static()
>>> # Sample Network:
>>> x ='x', shape=[100, 100], dtype='float32')
>>> y ='y', shape=[100, 100], dtype='float32')
>>> out = paddle.add(x, y)

>>> # print the number of blocks in the program, 1 in this case
>>> print(paddle.static.default_main_program().num_blocks)
>>> # print the default_main_program
>>> print(paddle.static.default_main_program())