ITADN

In-place type mutation (equal_) correctly raises error in Eager but silently downgraded to out-of-place in static_pir

#79144OpenrookieLiu2018 创建于 2026-05-26
status/new-issuetype/bug-report
R
rookieLiu2018commented
### bug描述 Describe the Bug When attempting to perform an illegal in-place operation that mutates a tensor's underlying dtype (e.g., using paddle.equal_ to overwrite a float32 tensor with a bool result), Eager mode correctly enforces type safety and crashes. However, static_pir (full_graph=True) silently bypasses this strict check by downgrading the in-place operation to an out-of-place operation, allowing the execution to succeed inconsistently. This breaks the legality parity between Eager and Static mode. Illegal memory/type mutations in Eager should be rejected by the static compiler during tracing, rather than being silently bypassed via a UserWarning. Minimal Reproducer: ```python import paddle x = paddle.arange(0, 96, dtype='float32').reshape([2, 3, 4, 4]) / 10.0 def core_computation(): # Output is a float32 tensor z0 = paddle.nn.functional.gaussian_nll_loss(input=x, label=x, variance=paddle.ones_like(x)) # In-place operation: attempts to mutate float32 to bool observer = paddle.equal_(z0, z0) return z0, observer if __name__ == "__main__": paddle.disable_static() # 1. Eager Execution try: eager_out = core_computation() print("Eager execution succeeded.") except Exception as e: print(f"Eager failed: {e}") # 2. Static Graph Execution compiled_core = paddle.jit.to_static(core_computation, full_graph=True) try: compiled_out = compiled_core() print("Static execution succeeded.") except Exception as e: print(f"Static failed: {e}") ``` Output: ``` Eager failed: (InvalidArgument) The type of data we are trying to retrieve (float32) does not match the type of data (bool) currently contained in the container. [Hint: Expected dtype() == phi::CppTypeToDataType<T>::Type(), but received dtype():1 != phi::CppTypeToDataType<T>::Type():10.] (at /paddle/paddle/phi/core/dense_tensor.cc:153) Static execution succeeded. /usr/local/lib/python3.12/dist-packages/paddle/pir/math_op_patch.py:241: UserWarning: Tensor do not have 'place' interface for pir graph mode, try not to use it. None will be returned. warnings.warn( /usr/local/lib/python3.12/dist-packages/paddle/utils/inplace_utils.py:61: UserWarning: In static graph mode, equal_() is the same as equal() and does not perform inplace operation. warnings.warn( ``` ### 其他补充信息 Additional Supplementary Information Paddle version: 3.3.0
0 条评论