enable_to_static¶
- paddle.jit. enable_to_static ( enable_to_static_bool ) [source]
-
Enable or disable the converting from imperative to static graph by ProgramTranslator globally.
- Parameters
-
enable_to_static_bool (bool) – True or False to enable or disable converting to static.
- Returns
-
None.
Examples
>>> import paddle >>> @paddle.jit.to_static >>> def func(x): ... if paddle.mean(x) > 0: ... x_v = x - 1 ... else: ... x_v = x + 1 ... return x_v ... >>> paddle.jit.enable_to_static(False) >>> x = paddle.ones([1, 2]) >>> # ProgramTranslator is disabled so the func is run in dygraph >>> print(func(x)) Tensor(shape=[1, 2], dtype=float32, place=Place(cpu), stop_gradient=True, [[0., 0.]])