Skip to content

Fix TemporaryVariable resource leaks after aborted executor runs - #130329

Open
FredBill1 wants to merge 1 commit into
tensorflow:masterfrom
FredBill1:fix-130303
Open

FredBill1 wants to merge 1 commit into
tensorflow:masterfrom
FredBill1:fix-130303

Conversation

@FredBill1

Copy link
Copy Markdown

Fixes #130303.

Problem

When Grappler rewrites AddN into TemporaryVariable / AssignAdd / DestroyTemporaryVariable, dataset exhaustion can abort execution after the temporary resource is created but before it is destroyed.

Eager function invocations may reuse the same step container, leaving the resource behind and causing AlreadyExistsError on subsequent epochs.

Fix

  • Give each executor invocation a uniquely named, execution-local ScopedStepContainer for temporary variables.
  • Route TemporaryVariable and DestroyTemporaryVariable through this container, ensuring cleanup when execution finishes, including after errors or cancellation.
  • Preserve the existing step-container behavior for other resources, such as TensorArray and Stack.

Tests

Added C++ and Python regression tests covering successful execution, EOF, errors, concurrent invocations, cancellation, and resource lifetime compatibility.

Locally verified on WSL2/Docker (CPU-only):

  • Full executor_test suite: passed.
  • New temporary_variable_test suite: passed.
  • TensorFlow wheel: built successfully.
  • Original EOF reproducer: verified with the locally built wheel; training completes without AlreadyExistsError.

@google-ml-butler google-ml-butler Bot added the size:L CL Change Size: Large label Nov 14, 2026
@google-cla

google-cla Bot commented Nov 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Nov 14, 2026
@google-ml-butler
google-ml-butler Bot requested a review from cantonios November 14, 2026 03:55

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request isolates temporary variables to individual executor invocations by introducing an execution-local temporary_variable_container_ in ExecutorState. This prevents aborted or failed executions (such as those caused by errors, cancellations, or dataset exhaustion) from poisoning subsequent invocations, while ensuring other resources like TensorArray and Stack retain their existing lifetimes. Comprehensive C++ and Python tests have been added to verify these lifetime guarantees. I have no feedback to provide as the implementation is robust and well-tested.

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

Labels

awaiting review Pull request awaiting review size:L CL Change Size: Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grappler MemoryOptimizer TemporaryVariable survives dataset EOF, causing AlreadyExistsError

1 participant