Create Python Program. It has at least one :ref:`api_guide_Block_en`, when the control flow op like conditional_block, while :ref:`api_paddle_base_layers_While` is included, it will contain nested block. Please reference the `framework.proto <https://github.com/PaddlePaddle/Pa
| 6015 | |
| 6016 | |
| 6017 | class Program: |
| 6018 | """ |
| 6019 | Create Python Program. It has at least one :ref:`api_guide_Block_en`, when the |
| 6020 | control flow op like conditional_block, while :ref:`api_paddle_base_layers_While` is included, |
| 6021 | it will contain nested block. |
| 6022 | |
| 6023 | Please reference the |
| 6024 | `framework.proto <https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/core/framework/framework.proto>`_ |
| 6025 | for details. |
| 6026 | |
| 6027 | A set of Program usually contains startup program and main program. |
| 6028 | A startup program is set to contain some initial work, eg. initialize the ``Parameter``, and the main |
| 6029 | program will contain the network structure and vars for train. |
| 6030 | |
| 6031 | A set of Program can be used for test or train, in train program , |
| 6032 | Paddle will contain all content to build a train network, in test |
| 6033 | program Paddle will prune some content which is irrelevant to test, eg. |
| 6034 | backward ops and vars. |
| 6035 | |
| 6036 | **Notes**: |
| 6037 | **we have** :ref:`api_paddle_base_framework_default_startup_program` **and** :ref:`api_paddle_base_framework_default_main_program` |
| 6038 | **by default, a pair of them will shared the parameters. The** :ref:`api_paddle_base_framework_default_startup_program` **only run once to initialize parameters,** |
| 6039 | :ref:`api_paddle_base_framework_default_main_program` **run in every mini batch and adjust the weights.** |
| 6040 | |
| 6041 | Returns: |
| 6042 | Program: An empty Program. |
| 6043 | |
| 6044 | Examples: |
| 6045 | .. code-block:: pycon |
| 6046 | |
| 6047 | >>> import paddle |
| 6048 | >>> import paddle.static as static |
| 6049 | |
| 6050 | >>> paddle.enable_static() |
| 6051 | |
| 6052 | >>> main_program = static.Program() |
| 6053 | >>> startup_program = static.Program() |
| 6054 | >>> with static.program_guard(main_program=main_program, startup_program=startup_program): |
| 6055 | ... x = static.data(name="x", shape=[-1, 784], dtype='float32') |
| 6056 | ... y = static.data(name="y", shape=[-1, 1], dtype='int32') |
| 6057 | ... z = static.nn.fc(name="fc", x=x, size=10, activation="relu") |
| 6058 | |
| 6059 | >>> print("main program is: {}".format(main_program)) |
| 6060 | >>> print("start up program is: {}".format(startup_program)) |
| 6061 | |
| 6062 | """ |
| 6063 | |
| 6064 | def __init__(self): |
| 6065 | self.desc = core.ProgramDesc() |
| 6066 | self.blocks = [Block(self, 0)] |
| 6067 | self.current_block_idx = 0 |
| 6068 | global global_prog_seed |
| 6069 | self._seed = global_prog_seed |
| 6070 | self._current_role = core.op_proto_and_checker_maker.OpRole.Forward |
| 6071 | self.__op_role_var = [] |
| 6072 | |
| 6073 | # for distribute training |
| 6074 | # _is_distributed = True if under distributed training |
no outgoing calls