Repository navigation
[PIR][CINN] Tensor.view() backward fails with view_shape_grad kernel output mismatch #79559
Copy link
Copy link
Open
Labels
Description
bug描述 Describe the Bug
Environment
paddlepaddle-gpu==3.3.0- Python 3.10.19, Linux x86_64 (WSL2)
- NVIDIA GeForce RTX 4060 Ti, driver 591.86
- Paddle CUDA 13.0, cuDNN 9.13.0
Reproduction
Save as /tmp/paddle_view_shape_grad_repro.py:
import paddle
class Predictor(paddle.nn.Layer):
def __init__(self):
super().__init__()
self.linear = paddle.nn.Linear(8, 16)
def forward(self, x, mask, label):
x = x[mask.unsqueeze(-1).expand_as(x)].reshape((-1, 8))
logits = self.linear(x).view(-1, 16)
loss = paddle.nn.functional.cross_entropy(logits, label)
return loss
paddle.seed(0)
paddle.set_device("gpu:0")
predictor = paddle.jit.to_static(Predictor())
x = paddle.randn((5, 3, 8))
x.stop_gradient = False
mask = paddle.ones((5, 3), dtype="bool")
label = paddle.arange(15, dtype="int64")
loss = predictor(x, mask, label)
loss.backward()Run:
FLAGS_prim_enable_dynamic=true \
FLAGS_prim_all=true \
FLAGS_use_cinn=true \
FLAGS_print_ir=false \
python -O /tmp/paddle_view_shape_grad_repro.pyExpected behavior
loss.backward() finishes successfully.
Error output
W0727 21:40:15.849781 290492 gpu_resources.cc:116] Please NOTE: device: 0, GPU Compute Capability: 8.9, Driver API Version: 13.1, Runtime API Version: 13.3
W0727 21:40:15.910542 290492 eager_utils.cc:3584] Paddle static graph(PIR) not support input out tensor for now!!!!!
/home/lkyu/miniconda3/envs/paddletorch/lib/python3.10/site-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(
W0727 21:40:16.049400 290492 shape_optimization_pass.cc:292] pd_op.view_shape DOES NOT have InferSymbolicShapeInterface!
W0727 21:40:16.049429 290492 shape_optimization_pass.cc:331] Not found symbolic shape cache for pd_op.view_shape[id:75], op_infer_cache_key is :InferSymbolicShapeCacheKey - pd_op.view_shape
attrs: {[-1,16],
input_shape_or_datas: {shape[Div(S0, 8), 16], data[NULL]}
W0727 21:40:16.049437 290492 shape_analysis.cc:168] Risk on SetSymbolForValueByStaticShape for contain_unknown_dim. The Value is a OpResult, defined by pd_op.view_shape[75], with results index 0
W0727 21:40:16.050021 290492 pattern_rewrite_driver.cc:235] The pattern rewrite did not converge after scanning 10 times
I0727 21:40:16.051407 290492 add_cinn_pass.cc:334] Compiling subgraph with CINN backend ...
W0727 21:40:16.051965 290492 shape_optimization_pass.cc:292] pd_op.view_shape DOES NOT have InferSymbolicShapeInterface!
W0727 21:40:16.051988 290492 shape_optimization_pass.cc:331] Not found symbolic shape cache for pd_op.view_shape[id:212], op_infer_cache_key is :InferSymbolicShapeCacheKey - pd_op.view_shape
attrs: {[-1,16],
input_shape_or_datas: {shape[Div(S0, 8), 16], data[NULL]}
W0727 21:40:16.051995 290492 shape_analysis.cc:168] Risk on SetSymbolForValueByStaticShape for contain_unknown_dim. The Value is a OpResult, defined by pd_op.view_shape[212], with results index 0
W0727 21:40:18.750989 290492 pattern_rewrite_driver.cc:235] The pattern rewrite did not converge after scanning 10 times
I0727 21:40:22.701076 290492 pir_interpreter.cc:1606] New Executor is Running ...
I0727 21:40:22.701825 290492 pir_interpreter.cc:1627] pir interpreter is running by trace mode ...
W0727 21:40:22.743916 290492 backward.cc:685] While running Node (Dy2StGradNode) raises an EnforceNotMet exception
all prim enabled: True
Traceback (most recent call last):
File "/tmp/paddle_view_shape_grad_repro.py", line 26, in <module>
loss.backward()
File "/home/lkyu/miniconda3/envs/paddletorch/lib/python3.10/site-packages/paddle/base/wrapped_decorator.py", line 50, in wrapper
return decorated(*args, **kwargs)
File "/home/lkyu/miniconda3/envs/paddletorch/lib/python3.10/site-packages/paddle/base/framework.py", line 727, in __impl__
return func(*args, **kwargs)
File "/home/lkyu/miniconda3/envs/paddletorch/lib/python3.10/site-packages/paddle/base/dygraph/tensor_patch_methods.py", line 370, in backward
core.eager.run_backward(
RuntimeError: (PreconditionNotMet) op [pd_op.view_shape_grad] kernel output args (0) defs should equal op outputs (1)
[Hint: Expected op_item->num_results() == output_defs.size(), but received op_item->num_results():1 != output_defs.size():0.] (at /paddle/paddle/fluid/pir/transforms/pd_op_to_kernel_pass.cc:2721)
Possible cause
This may be a PIR lowering or kernel metadata issue for pd_op.view_shape_grad:
- The shape optimization pass reports that
pd_op.view_shapehas noInferSymbolicShapeInterfaceimmediately before the failure. - The failing check reports one PIR result but zero kernel output definitions.
- Replacing only
self.linear(x).view(-1, 16)withself.linear(x).reshape((-1, 16))completes forward and backward under the same flags. - Running the same code without
paddle.jit.to_staticalso completes successfully.
The view is shape-preserving in this example because Linear(8, 16) already returns a two-dimensional tensor ending in 16. This makes it less likely that the failure is caused by incompatible user-level reshape semantics, but I may be missing a required constraint for view in PIR mode.
其他补充信息 Additional Supplementary Information
No response
Reactions are currently unavailable
Activity