Closed
Description
Description
Recently we fixed an issue in the Autodiff runtime due to which PBs w/ loops used to leak memory. A fix for the issue was merged in #67944. While validating the fix on our internal test suite we uncovered another memory related bug (a double free) because of which certain pullbacks w/ loops can segfault.
Below is a minimal reproducer for the issue.
import _Differentiation
@differentiable(reverse) func B(x: Float) -> Float {
var y = x + 1
for _ in 0 ..< 1 {}
return y
}
func f() {
let (_, pb) = valueWithPullback(at: 1.0, of: B)
pb(21.0)
}
f()
Running the above program leads to a segfault.
Expected Behavior
The program should not segfault and pullback of B
should be runnable multiple times.