You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Out-of-bounds gradient write in reverse pass of runtime-length while loops #2169
In a runtime-length while loop, the reverse pass writes an array's gradient one element past the end of the array. With the kernel from #2125 and coefficients.requires_grad=True, coefficients.grad stays all zeros, and the gradient lands in the element just past the array. Here coefficients is a 3-element view of a 4-element buffer, so we can see the stray write in storage.grad[3].
A product-style while loop shows the same thing: it writes 144.0 one element past the end of the input's gradient.
It looks like the reverse pass of a forward-order while loop reads its index variable after the final increment, so the adjoint of coefficients[j] is accumulated at index j + 1. Because this writes outside the array, it can silently corrupt memory next to the array. Gradients through dynamic loops are already tracked in #729, but I couldn't find an existing report of the out-of-bounds write specifically.
System Information
Warp built from main at 0c1ed78. Windows 11, RTX 4090. Reproduces on both cpu and cuda:0.
Activity