PaddlePaddle / PaddlePaddle/Paddle
`paddle.static.nn.while_loop` with to_static(full_graph=True) segfaults when body captures an eager tensor
Open
@umiswing is already working on this.
Since Jul 14, 2026.
status/new-issue
type/bug-report
- Dominant language
- C++
- Stars
- 24.1k
- Forks
- 6k
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 60
Description
bug描述 Describe the Bug
Describe the Bug
paddle.static.nn.while_loop can crash the Python process when it is used
inside paddle.jit.to_static(full_graph=True) and the loop body is defined
outside the converted function while capturing an eager Tensor.
Minimal reproducible example
import paddle
cached_features = paddle.ones([2, 4], dtype="float32")
def continue_loop(step):
return step < 2
def update_step(step):
# A common pattern is to read cached state in a loop body. In this
# reproducer the cached tensor is captured from eager mode.
_ = cached_features + 1.0
return step + 1
@paddle.jit.to_static(full_graph=True)
def run_loop():
step = paddle.zeros([], dtype="int32")
return paddle.static.nn.while_loop(continue_loop, update_step, [step])
print(run_loop())
Reproduction result
The program crashes the Python process:
FatalError: `Segmentation fault` is detected by the operating system.
SignalInfo: SIGSEGV (@0x18)
Segmentation fault (core dumped)
exit code: 139
Expected behavior
Paddle should not crash the process. If loop body functions that capture eager
Tensors are unsupported in this static-graph construction path, Paddle should
raise a Python/C++ error explaining the unsupported pattern.
Environment
PaddlePaddle: 3.3.1
Python: 3.13.13
OS: Linux 6.8.0-100-generic x86_64, glibc 2.35
GPU: 2*Nvidia 4090
其他补充信息 Additional Supplementary Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.