Offload a saved view when it is the last value holding its storage - #8388
Draft
pengdurice wants to merge 1 commit into
Draft
Offload a saved view when it is the last value holding its storage#8388pengdurice wants to merge 1 commit into
pengdurice wants to merge 1 commit into
Conversation
Signed-off-by: pengdurice <pengduhit@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Offload a saved view when it is the last value holding its storage
Fixes #8387
Problem
_eligible_activationsindeepspeed/compile/passes/offload_activation.pydropped everysaved-for-backward value whose target is an aliasing op (
view,permute,slice,expand,detach, and every other aten op whose schema declares an aliasing tensor return):There was no check on whether anything else still held that storage.
The rule is correct when the tensor the view came from is a weight, a graph input, or another
saved value. It is wrong when AOTAutograd saves only the view. The base node is then dead, but its
allocation is not: the returned view still points at it, so the caching allocator cannot reclaim
the block until the backward pass reads the view. Moving the view to the host is what releases the
whole allocation.
The fix
Three helpers, and the single alias skip becomes two narrower ones.
_alias_root_storage_keeper_counts_has_reloadable_layoutThe existing skip for "the base is also saved" is kept, exactly as the issue asks. What changed is
that it is now conditional on a liveness count instead of unconditional.
Tests
Added to
tests/unit/v1/compile/test_offload_activation.py. The first two are the tests named inthe issue; neither existed in the tree or on
master, so both are written as ordinary tests ratherthan one of them as
xfail(strict=True).test_eligible_includes_saved_view_when_base_is_not_saved_skipped["alias"] == 0test_eligible_skips_saved_view_when_base_is_also_savedtest_eligible_skips_a_saved_view_the_host_copy_would_not_reproducealias_layoutThe graph both of the first two use is the one the issue specifies:
x -> relu(base) -> aten.view(viewed) -> sum(out), with AOT-shaped outputs(out, viewed)and(out, base, viewed).The pre-existing
test_fwd_skips_values_that_alias_another_tensorstill passes unchanged. In thatgraph the view's root is a placeholder, so it is still skipped.
Results
tests/unit/v1/compile/test_offload_activation.py, 1 GPUTestOffloadActivation::test_offload_activation_correctness, 2 GPUstorch 2.6.0+cu124, Python 3.10. The end-to-end test compares losses with offloading on and off at
DS_DC_OFFLOAD_ACT_MIN_SIZE_MB=0, so it now exercises the newly eligible views.yapf --diffandflake8 --max-line-length=120are clean on both changed files.