declarative programming (static graph), shape, append_batch_size=True, dtype='float32', lod_level=0, type=VarType.LOD_TENSOR, stop_gradient=True)[source]

Data Layer

This operator creates the global variable. The global variables can be accessed by all the following operators in the graph.

Note is deprecated as it will be removed in a later version. Please use .

This set shape and dtype at compile time but does NOT check the shape or the dtype of fed data, the checks the shape and the dtype of data fed by Executor or ParallelExecutor during run time.

To feed variable size inputs, users can feed variable size inputs directly to this and PaddlePaddle will fit the size accordingly. Or set -1 on the variable dimension when using .

The default stop_gradient attribute of the Variable created by this API is true, which means the gradient won’t be passed backward through the data Varaible. Set var.stop_gradient = False If user would like to pass backward gradient.

  • name (str) – The name/alias of the variable, see Name for more details.

  • shape (list|tuple) – Tuple declaring the shape. If append_batch_size is True and there is no -1 inside shape, it should be considered as the shape of the each sample. Otherwise, it should be considered as the shape of the batched data.

  • append_batch_size (bool) –

    1. If true, it prepends -1 to the shape.

    System Message: WARNING/2 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/ of, line 36)

    Enumerated list ends without a blank line; unexpected unindent.

    For example if shape=[1], the resulting shape is [-1, 1]. This will be useful to set different batch size at run time.

    System Message: WARNING/2 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/ of, line 38)

    Block quote ends without a blank line; unexpected unindent.

    1. If shape contains -1, such as shape=[1, -1].

    System Message: WARNING/2 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/ of, line 39)

    Enumerated list ends without a blank line; unexpected unindent.

    append_batch_size will be enforced to be be False (ineffective) because PaddlePaddle cannot set more than 1 unknown number on the shape.

  • dtype (np.dtype|VarType|str) – The type of the data. Supported dtype: bool, float16, float32, float64, int8, int16, int32, int64, uint8.

  • type (VarType) – The output type. Supported dtype: VarType.LOD_TENSOR, VarType.SELECTED_ROWS, VarType.NCCL_ID. Default: VarType.LOD_TENSOR.

  • lod_level (int) – The LoD Level. 0 means the input data is not a sequence. Default: 0.

  • stop_gradient (bool) – A boolean that mentions whether gradient should flow. Default: True.


The global variable that gives access to the data.

Return Type:



import paddle.fluid as fluid
data ='x', shape=[784], dtype='float32')