Skip to content

Handle additional live allocations not in checkpointed state - #94943

Closed
eellison wants to merge 15 commits into
gh/eellison/389/basefrom
gh/eellison/389/head
Closed

eellison wants to merge 15 commits into
gh/eellison/389/basefrom
gh/eellison/389/head

Conversation

@eellison

@eellison eellison commented Feb 15, 2023 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.

Differential Revision: D43999886

@pytorch-bot

pytorch-bot Bot commented Feb 15, 2023 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/94943

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b0dff0c:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the release notes: distributed (c10d) release notes category label Feb 15, 2023
@eellison eellison removed the release notes: distributed (c10d) release notes category label Feb 15, 2023
eellison added a commit that referenced this pull request Feb 15, 2023
@eellison eellison added the topic: not user facing topic category label Feb 16, 2023
@eellison
eellison requested a review from zdevito February 16, 2023 22:41
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
eellison added a commit that referenced this pull request Feb 16, 2023
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
@eellison
eellison removed the request for review from kwen2501 February 21, 2023 21:40
Comment thread test/test_cuda.py
def foo():
small_buffers = [int8_cuda(MIN_BLOCK_SIZE) for _ in range(11)]
return small_buffers[5]
return small_buffers[5].add_(2)

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.

hmm?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will revert

Comment thread test/test_cuda.py
gc.collect()
torch.cuda.empty_cache()

# TODO: re-enable

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.

You gonna reenable?

@eellison eellison Mar 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is another comment thread that I commented on this about. To enable this we would have to leak Storages as a concept to the allocator, so i'm not sure. Explanation here: #94943 (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.

ok, just breadcrumb it in the comment here, so we can find it later

freed_pointer_set.insert((ptr));
}
// that block has already been freed,
// so even those this will error, so too will the allcoator

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.

allocator

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.

  • allcoator
  • correponding
  • even those this
  • so too will the allcoator

// when the corresponding tensor dies because there is no
// live tensor correponding to it
TORCH_CHECK(
ptr_set.size() >= definite_freed_count,

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.

Is this a >=, or is it an exact equality test? Why is this an inequality?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could be larger in the case that there is a Block which is removed and freed with the same pointer address.


// returns the pointers freed in the pool
// and the pointers allocated. Note: a pointer
// may appear in both freed and allocated

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.

So what does it mean if a pointer appears in both freed and allocated? Is it live coming out or not?

@eellison eellison Mar 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could be reallocated as a separate size, with a tensor stale that is dead now and a new tensor now live using that address.

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.

Can I have the opposite situation? A tensor is allocated and then freed internally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that is possible. We pass in the stale storages to the api and them swap their deleters with no-ops so they are not freed twice.

bool succeeded = stale_storage->data_ptr().compare_exchange_deleter(
t->raw_deleter(), &no_op_delete);

TORCH_CHECK(

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.

So, when can this happen? Is this if I pass garbage tensors to the checkpoint function? If I only ever pass tensors that are allocated out of the pool, the deleter should always be as expected, right? Can we describe the preconditions for the checkpoint tensor list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This error means that you had a non-standard deleter fn, and so it's not safe for us to blindly remove it. As the comment in Allocator.h says:

   * Compare the deleter in a DataPtr to expected_deleter.
   * If it matches, replace the deleter with new_deleter
   * and return true; otherwise, does nothing and returns
   * false.
   *
   * In general, it is not safe to unconditionally set the
   * deleter on a DataPtr, because you don't know what
   * the deleter is, and thus will have a hard time properly
   * disposing of the deleter without storing the original
   * deleter

@zdevito zdevito 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.

Looks nice and clean now. Thanks for the changes!

Comment thread c10/cuda/CUDACachingAllocator.cpp Outdated
constexpr size_t kRoundLarge = 2097152; // round up large allocations to 2 MiB
constexpr size_t kRoundUpPowerOfTwoIntervals = 16;

void local_raw_delete(void* ptr);

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.

nit: don't think this is needed anymore, though it isn't doing any harm to be pre-declared...

"_cuda_setCheckpointPoolState",
[](int device,
std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState> pps) {
std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState> pps,

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.

I think for now this is ok, and when the APIs are all in place we can ask what series of actions can lead to this state and figure out the right guards then.

We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.


[ghstack-poisoned]
@davidberard98

Copy link
Copy Markdown
Contributor

@davidberard98 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.

Differential Revision: [D43999886](https://our.internmc.facebook.com/intern/diff/D43999886)

[ghstack-poisoned]
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.

Differential Revision: [D43999886](https://our.internmc.facebook.com/intern/diff/D43999886)

[ghstack-poisoned]
@eellison eellison added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 13, 2023
@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@eellison eellison mentioned this pull request Mar 14, 2023
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 23, 2023
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.

Differential Revision: [D43999886](https://our.internmc.facebook.com/intern/diff/D43999886)
Pull Request resolved: pytorch/pytorch#94943
Approved by: https://github.com/zdevito
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 27, 2023
We choose to ignore certain blocks that are currently allocated when we set the pool to its checkpoint. For those blocks, we need to swap out the deleter function of their corresponding blocks so that a deallocation is not triggered when they die.

Differential Revision: [D43999886](https://our.internmc.facebook.com/intern/diff/D43999886)
Pull Request resolved: pytorch/pytorch#94943
Approved by: https://github.com/zdevito
@facebook-github-bot
facebook-github-bot deleted the gh/eellison/389/head branch June 8, 2023 16:19
@apivovarov

apivovarov commented Aug 9, 2023 •

Copy link
Copy Markdown
Contributor

@eellison Can you look again at the comments in Module.cpp? It has the following typos/mistakes:

  • allcoator
  • correponding
  • even those this
  • so too will the allcoator

@eellison

eellison commented Aug 9, 2023

Copy link
Copy Markdown
Contributor Author

Will accept a pr to fix.

@apivovarov

Copy link
Copy Markdown
Contributor

Should we replace
so even those this will error, so too will the allocator
with
Although this will result in an error, the allocator will also encounter the same issue.
?

@eellison

eellison commented Aug 9, 2023

Copy link
Copy Markdown
Contributor Author

sure, that works.

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

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants