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``
()
| 8080 | |
| 8081 | |
| 8082 | def 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 | |
| 8119 | def switch_main_program(program: Program) -> Program: |
no outgoing calls