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

Class Program

python/paddle/base/framework.py:6017–7679  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

6015
6016
6017class 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

Callers 15

_serialize_persistablesFunction · 0.90
deserialize_persistablesFunction · 0.90
save_varsFunction · 0.90
load_varsFunction · 0.90
load_program_stateFunction · 0.90
__init__Method · 0.90
__load_persistable_varsFunction · 0.90
get_pserver_programMethod · 0.90
get_startup_programMethod · 0.90
get_pserver_programMethod · 0.90
_get_tablesMethod · 0.90
_build_vpp_sub_programsFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_index_select_apiMethod · 0.72
test_errorsMethod · 0.72
test_errorsMethod · 0.72
test_errorsMethod · 0.72
test_errorsMethod · 0.72
test_errorsMethod · 0.72
test_errorsMethod · 0.72
test_unbindMethod · 0.72
test_layers_unbindMethod · 0.72
test_errorsMethod · 0.72
test_apiMethod · 0.72
test_errorsMethod · 0.72