bug描述 Describe the Bug
Handling non-contiguous/strided views is a known complex area in compiler lowering. Currently, in static mode, the alias tracking fails to synchronize strided views when their underlying base tensor is mutated in-place.
While this causes silent numerical errors (similar to contiguous views), it carries a much more severe consequence: it fundamentally corrupts the compiler's dynamic shape and control-flow inference. When a stale strided view is passed into shape-dynamic operators like nonzero, it results in a critical Structure Mismatch (e.g., producing a tensor with incorrect dimensions compared to Eager mode).
Minimal Reproducer:
import os
import paddle
def kernel_strided_views(x, x_bool):
# Create strided views
y = paddle.transpose(x, [1, 0])
y_bool = paddle.transpose(x_bool, [1, 0])
# CORE MUTATION: Mutate the base tensors
x[0, :] = paddle.to_tensor([99.0, 99.0], dtype="float32")
x_bool[0, :] = paddle.to_tensor([False, False], dtype="bool")
return (
paddle.nonzero(y_bool),
paddle.sort(y),
paddle.sum(y)
)
# Initialize data
x_init = paddle.arange(4, dtype="float32").reshape([2, 2])
x_bool_init = paddle.to_tensor([[True, True], [False, True]], dtype="bool")
# Eager Execution
e_nz, e_sort, e_sum = kernel_strided_views(x_init.clone(), x_bool_init.clone())
# Static Execution
static_fn = paddle.jit.to_static(kernel_strided_views, full_graph=True)
s_nz, s_sort, s_sum = static_fn(x_init.clone(), x_bool_init.clone())
print("=== Strided View Structure & Value Corruption ===")
print(f"[nonzero] Structure Mismatch! Eager Shape: {e_nz.shape} | Static Shape: {s_nz.shape}")
print("-" * 50)
print(f"[sort] Eager Output:\n{e_sort.numpy().tolist()}")
print(f"[sort] Static Output:\n{s_sort.numpy().tolist()}")
print(f"[sum] Eager Sum: {e_sum.item():.1f} | Static Sum: {s_sum.item():.1f}")
Output:
=== Strided View Structure & Value Corruption ===
[nonzero] Structure Mismatch! Eager Shape: [1, 2] | Static Shape: [3, 2]
--------------------------------------------------
[sort] Eager Output:
[[2.0, 99.0], [3.0, 99.0]]
[sort] Static Output:
[[0.0, 2.0], [1.0, 3.0]]
[sum] Eager Sum: 203.0 | Static Sum: 6.0
AssertionError: Structure mismatch: [1, 2] vs [3, 2]
其他补充信息 Additional Supplementary Information
Paddle Version: 3.3.0
bug描述 Describe the Bug
Handling non-contiguous/strided views is a known complex area in compiler lowering. Currently, in static mode, the alias tracking fails to synchronize strided views when their underlying base tensor is mutated in-place.
While this causes silent numerical errors (similar to contiguous views), it carries a much more severe consequence: it fundamentally corrupts the compiler's dynamic shape and control-flow inference. When a stale strided view is passed into shape-dynamic operators like nonzero, it results in a critical Structure Mismatch (e.g., producing a tensor with incorrect dimensions compared to Eager mode).
Minimal Reproducer:
Output:
其他补充信息 Additional Supplementary Information
Paddle Version: 3.3.0