bug描述 Describe the Bug
Under the new static_pir infrastructure (paddle.jit.to_static(..., full_graph=True)), multiple native in-place operators (methods ending with an underscore) do not mutate the tensor's state as expected.
The compiler appears to drop the Yield/Update state during the SSA graph lowering. Consequently, the static graph silently returns the stale, unmutated tensor. This correctness bug bypasses legality checks and silently corrupts downstream computations, affecting both simple element-wise operations and complex indexed memory operations.
import os
import paddle
paddle.set_device("cpu")
def kernel_inplaces(x_simple, x_complex, idx, src):
# 1. Simple element-wise in-place
x_simple.add_(paddle.to_tensor([10.0, 10.0], dtype="float32"))
# 2. Complex indexed memory in-place
x_complex.scatter_add_(1, idx, src)
return x_simple, x_complex
# Initialize data
x_simple_init = paddle.to_tensor([1.0, 2.0], dtype="float32")
x_complex_init = paddle.zeros([2, 4], dtype="float32")
idx = paddle.to_tensor([[1, 3], [2, 0]], dtype="int64")
src = paddle.to_tensor([[0.5, 1.25], [-3.0, 4.0]], dtype="float32")
# Eager Execution
e_simp, e_comp = kernel_inplaces(x_simple_init.clone(), x_complex_init.clone(), idx, src)
# Static PIR Execution
static_fn = paddle.jit.to_static(kernel_inplaces, full_graph=True)
s_simp, s_comp = static_fn(x_simple_init.clone(), x_complex_init.clone(), idx, src)
print("=== In-place Operators Silent Failure ===")
print(f"[add_] Eager: {e_simp.numpy().tolist()} | Static: {s_simp.numpy().tolist()}")
print(f"[scatter_add_] Eager Sum: {paddle.sum(e_comp).item()} | Static Sum: {paddle.sum(s_comp).item()}")
Output:
=== In-place Operators Silent Failure ===
[add_] Eager: [11.0, 12.0] | Static: [1.0, 2.0]
[scatter_add_] Eager Sum: 2.75 | Static Sum: 0.0
AssertionError: Value mismatch: In-place add_ failed!
其他补充信息 Additional Supplementary Information
No response
bug描述 Describe the Bug
Under the new static_pir infrastructure (paddle.jit.to_static(..., full_graph=True)), multiple native in-place operators (methods ending with an underscore) do not mutate the tensor's state as expected.
The compiler appears to drop the Yield/Update state during the SSA graph lowering. Consequently, the static graph silently returns the stale, unmutated tensor. This correctness bug bypasses legality checks and silently corrupts downstream computations, affecting both simple element-wise operations and complex indexed memory operations.
Output:
其他补充信息 Additional Supplementary Information
No response