Skip to content

Conversation

@harsh-sutariya
Copy link
Contributor

Proposed changes

Fixes memory leak in function transforms when a container is updated with a tracer and that container element is reused as input (issue #2841).

Root cause: When vjp()/jvp() create tracer copies and a container stores the tracer, subsequent calls create a chain copy(copy(copy(...))) that grows unboundedly, this is what prevents the garbage collection.

Solution: Flatten copy chains from previous (completed) tracing calls by traversing to the original source before creating new tracers. Only applies to non active tracers to preserve nested transform behavior.

Changes:

  • Modified vjp() and jvp() in transforms.cpp to flatten copy chains
  • Added test test_grad_with_container_reuse to verify fix

Follow the discussion in issue #2841 page for more details about the problem and the solution.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant