Skip to content

[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

Merged

Conversation

dan-zheng
Copy link
Contributor

No description provided.

@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Jun 4, 2019
@dan-zheng dan-zheng requested a review from rxwei June 4, 2019 23:22
@dan-zheng dan-zheng force-pushed the autodiff-control-flow-leakchecking branch from 3e0a50f to 68c7cc4 Compare June 4, 2019 23:43
}

// FIXME: Fix closure capture related memory leak.
testWithLeakChecking(expectedLeakCount: 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - this test actually has a leak count of 0.
But I recall encountering a test like this that fails with a leak count of 1.

cc @rxwei @pschuh: do you recall any reproducers for the known closure capture related memory leak?

Copy link
Contributor

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) }
}

Copy link
Contributor Author

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.

Copy link
Contributor

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)
    }

Copy link
Contributor Author

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)
    }
  }

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed TF-550.

Copy link
Contributor

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.
@dan-zheng dan-zheng force-pushed the autodiff-control-flow-leakchecking branch from 68c7cc4 to d4691b8 Compare June 5, 2019 00:52
@dan-zheng
Copy link
Contributor Author

@swift-ci Please test tensorflow

@dan-zheng dan-zheng merged commit 6bf823b into swiftlang:tensorflow Jun 5, 2019
@dan-zheng dan-zheng deleted the autodiff-control-flow-leakchecking branch June 5, 2019 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants