guard¶
- paddle.fluid.dygraph.base. guard ( place=None ) [source]
- 
         - Api_attr
- 
           imperative 
 This context will create a dygraph context for dygraph to run, using python withstatement.- Parameters
- 
           place (fluid.CPUPlace| fluid.CUDAPlace|str, optional) – Place to execute dygraph. If None, the running place will be determined according to the way of paddle compilation. If placeis string, It can becpu,gpu:xandxpu:x, wherexis the index of the GPUs or XPUs. Default: None
- Returns
- 
           None 
 Examples import numpy as np import paddle.fluid as fluid with fluid.dygraph.guard(): inp = np.ones([3, 1024], dtype='float32') t = fluid.dygraph.base.to_variable(inp) linear1 = fluid.Linear(1024, 4, bias_attr=False) linear2 = fluid.Linear(4, 4) ret = linear1(t) dy_ret = linear2(ret) 
