(*args: _InputT.args, **kwargs: _InputT.kwargs)
| 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 |
nothing calls this directly
no test coverage detected