create_global_var

paddle.static. create_global_var ( shape: ShapeLike, value: float, dtype: DTypeLike, persistable: bool = False, force_cpu: bool = False, name: str | None = None ) → paddle.Tensor [source]

This function creates a new tensor variable with value in the global block(block 0).

Parameters
  • shape (list[int]|tuple[int]) – Shape of the variable

  • value (float) – The value of the variable. The new created variable will be filled with it.

  • dtype (str) – Data type of the variable

  • persistable (bool, optional) – If this variable is persistable. Default: False

  • force_cpu (bool, optional) – Force this variable to be on CPU. Default: False

  • name (str|None, optional) – For detailed information, please refer to api_guide_Name . Usually name is no need to set and None by default.

Returns

The created Variable

Return type

Variable

Examples

>>> 
>>> import paddle
>>> paddle.enable_static()
>>> main_program = paddle.static.Program()
>>> startup_program = paddle.static.Program()
>>> with paddle.static.program_guard(main_program, startup_program):
...     var = paddle.static.create_global_var(
...         shape=[2, 3],
...         value=1.0,
...         dtype="float32",
...         persistable=True,
...         force_cpu=True,
...     )
>>> var.shape
(2, 3)