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

Function __impl__

python/paddle/utils/inplace_utils.py:58–87  ·  view source on GitHub ↗
(*args: _InputT.args, **kwargs: _InputT.kwargs)

Source from the content-addressed store, hash-verified

56 func: Callable[_InputT, _RetT],
57) -> Callable[_InputT, _RetT]:
58 def __impl__(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
59 if not in_dynamic_mode():
60 origin_api_name = func.__name__[:-1]
61 warnings.warn(
62 f"In static graph mode, {func.__name__}() is the same as {origin_api_name}() and does not perform inplace operation."
63 )
64 from ..base.dygraph.base import in_to_static_mode
65
66 if in_to_static_mode():
67 stride_in_no_check_dy2st_diff = os.environ.get(
68 "stride_in_no_check_dy2st_diff", "0"
69 )
70 if in_pir_mode():
71 if (
72 stride_in_no_check_dy2st_diff != '1'
73 and check_view_value(args[0])
74 ):
75 raise ValueError(
76 f'Sorry about what\'s happened. In to_static mode, {func.__name__}\'s output variable is a viewed Tensor in dygraph. This will result in inconsistent calculation behavior between dynamic and static graphs. You must find the location of the strided API be called, and call paddle.assign() before inplace input.'
77 )
78 else:
79 for arg in args:
80 if hasattr(arg, "is_view_var") and arg.is_view_var:
81 raise ValueError(
82 f'Sorry about what\'s happened. In to_static mode, {func.__name__}\'s output variable {arg.name} is a viewed Tensor in dygraph. This will result in inconsistent calculation behavior between dynamic and static graphs. You must find the location of the strided API be called, and call {arg.name} = paddle.assign({arg.name}).'
83 )
84
85 origin_func = f"{func.__module__}.{origin_api_name}"
86 return eval(origin_func)(*args, **kwargs)
87 return func(*args, **kwargs)
88
89 return __impl__
90

Callers

nothing calls this directly

Calls 8

in_pir_modeFunction · 0.90
in_to_static_modeFunction · 0.85
check_view_valueFunction · 0.85
ValueErrorClass · 0.85
evalFunction · 0.85
funcFunction · 0.50
warnMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected