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 program_guard .


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

Return type



import paddle

# Sample Network:
x ='x', shape=[100, 100], dtype='float32')
y ='x', 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) # 1
#print the default_main_program

Used in the guide/tutorials