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

Function default_main_program

python/paddle/base/framework.py:8082–8116  ·  view source on GitHub ↗

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``

()

Source from the content-addressed store, hash-verified

8080
8081
8082def default_main_program() -> Program:
8083 """
8084 This API can be used to get ``default main program`` which store the
8085 descriptions of Ops and tensors.
8086
8087 For example ``z = paddle.add(x, y)`` will create a new ``add``
8088 Op and a new ``z`` tensor, and they will be recorded in ``default main program`` .
8089
8090 The ``default main program`` is the default value for ``Program`` parameter in
8091 a lot of APIs. For example, the :code:`Executor.run()` will execute the
8092 :code:`default_main_program` when the program is not specified.
8093
8094 If you want to switch the ``default main program``, you can use :ref:`api_paddle_base_framework_program_guard` .
8095
8096 Returns:
8097 Program: A ``Program`` which holding the descriptions of OPs and tensors in the network.
8098
8099 Examples:
8100 .. code-block:: pycon
8101
8102 >>> import paddle
8103
8104 >>> paddle.enable_static()
8105 >>> # Sample Network:
8106 >>> x = paddle.static.data(name='x', shape=[100, 100], dtype='float32')
8107 >>> y = paddle.static.data(name='y', shape=[100, 100], dtype='float32')
8108 >>> out = paddle.add(x, y)
8109
8110 >>> # print the number of blocks in the program, 1 in this case
8111 >>> print(paddle.static.default_main_program().num_blocks)
8112 1
8113 >>> # print the default_main_program
8114 >>> print(paddle.static.default_main_program())
8115 """
8116 return _main_program_
8117
8118
8119def switch_main_program(program: Program) -> Program:

Callers 15

load_varsFunction · 0.90
load_vars_pirFunction · 0.90
__init__Method · 0.90
_get_ema_decayMethod · 0.90
updateMethod · 0.90
_init_amp_varMethod · 0.90
_init_amp_varMethod · 0.90
reshardFunction · 0.90
topo_pathFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 12

test_out_and_gradMethod · 0.72
check_static_result_1Method · 0.72
check_static_result_2Method · 0.72
check_static_result_3Method · 0.72
test_read_writeMethod · 0.72
test_varMethod · 0.72
_tostringMethod · 0.72
test_detachMethod · 0.72