-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff] Add control flow AD leak checking tests. #25249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AutoDiff] Add control flow AD leak checking tests. #25249
Conversation
3e0a50f
to
68c7cc4
Compare
test/AutoDiff/leakchecking.swift
Outdated
} | ||
|
||
// FIXME: Fix closure capture related memory leak. | ||
testWithLeakChecking(expectedLeakCount: 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it will leak. Try wrapping things in a loop?
for _ in 0..<10 {
let x: Tracked<Float> = 1.0
_ = model.gradient { m in m.applied(to: x) }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more tests in d4691b8.
Loop actually doesn't leak, but I found a test case that does leak.
// TODO: Fix memory leak.
testWithLeakChecking(expectedLeakCount: 1) {
var model = ExampleLeakModel()
let x: Tracked<Float> = 1.0
_ = model.gradient { m in
var model = m
// Next line causes leak.
model.bias = x
return model.applied(to: x)
}
}
Full dump here, in case you have time to look into it along with control flow related memory leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This doesn't seem related to closure checking then. What if you wrote:
_ = model.gradient { m in
let x: Tracked<Float> = 1.0
var model = m
// Next line causes leak.
model.bias = x
return model.applied(to: x)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This doesn't seem related to closure checking then. What if you wrote: ...
The partial snippet you shared also produces a leak (it's pretty similar to the leak that's checked in). Here's the full snippet:
// TODO: Fix memory leak.
testWithLeakChecking(expectedLeakCount: 1) {
var model = ExampleLeakModel()
_ = model.gradient { m in
let x: Tracked<Float> = 1.0
var model = m
// Next line causes leak.
model.bias = x
return model.applied(to: x)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so it should be unrelated to closure captures. It's a mutation differentiation bug. Could you file a bug for this specific issue with a reproducer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed TF-550.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dan's example here of adding tests with expectedLeakCount is a better way to keep track of the leaks and their reproducers. Checking the leaks in would keep track of when they are fixed better. The bug could also contain the reproducer.
Expose memory leak unrelated to control flow.
68c7cc4
to
d4691b8
Compare
@swift-ci Please test tensorflow |
No description provided.