bug描述 Describe the Bug
Description:
When compiling models in static mode, view tensors are not correctly synchronized if their original base tensor is modified in-place.
In Eager execution, modifying a base tensor automatically updates its active views, whether they are shape-changing views, subset views, or offset views. However, in static mode, this alias relationship is broken. The view tensor retains a stale, pre-mutation snapshot of the data, which leads to a critical silent value mismatch.
Minimal Reproducer:
import os
import paddle
def kernel_contiguous_views(x):
# 1. Shape-changing View
v_resh = paddle.reshape(x, [4])
# 2. Subset View
v_slic = x[1, :]
# 3. Offset View
v_diag = paddle.diagonal(x)
# CORE MUTATION: Mutate the base tensor in-place
x[1, 1] = 99.0
return paddle.sum(v_resh), paddle.sum(v_slic), paddle.sum(v_diag)
# Initialize data: [[0.0, 1.0], [2.0, 3.0]]
x_init = paddle.arange(4, dtype="float32").reshape([2, 2])
# Eager Execution
e_resh, e_slic, e_diag = kernel_contiguous_views(x_init.clone())
# Static PIR Execution
static_fn = paddle.jit.to_static(kernel_contiguous_views, full_graph=True)
s_resh, s_slic, s_diag = static_fn(x_init.clone())
print("=== Basic View Alias Tracking Failure ===")
print(f"[reshape] Eager Sum: {e_resh.item():.1f} | Static Sum: {s_resh.item():.1f}")
print(f"[slice] Eager Sum: {e_slic.item():.1f} | Static Sum: {s_slic.item():.1f}")
print(f"[diagonal] Eager Sum: {e_diag.item():.1f} | Static Sum: {s_diag.item():.1f}")
Output:
=== Basic View Alias Tracking Failure ===
[reshape] Eager Sum: 102.0 | Static Sum: 6.0
[slice] Eager Sum: 101.0 | Static Sum: 5.0
[diagonal] Eager Sum: 99.0 | Static Sum: 3.0
其他补充信息 Additional Supplementary Information
Paddle Version: 3.3.0
bug描述 Describe the Bug
Description:
When compiling models in static mode, view tensors are not correctly synchronized if their original base tensor is modified in-place.
In Eager execution, modifying a base tensor automatically updates its active views, whether they are shape-changing views, subset views, or offset views. However, in static mode, this alias relationship is broken. The view tensor retains a stale, pre-mutation snapshot of the data, which leads to a critical silent value mismatch.
Minimal Reproducer:
Output:
其他补充信息 Additional Supplementary Information
Paddle Version: 3.3.0