Skip to content

cudagraph trees - #89146

Closed
eellison wants to merge 25 commits into
gh/eellison/356/basefrom
gh/eellison/356/head
Closed

eellison wants to merge 25 commits into
gh/eellison/356/basefrom
gh/eellison/356/head

Conversation

@eellison

@eellison eellison commented Nov 16, 2022 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

CUDA Graph Trees

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

  • Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either PyObject preservation and resurrection for StorageImpl #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

  • Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

  • Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

Differential Revision: D43999887

cc @soumith @voznesenskym @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @desertfire

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 16, 2022 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

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

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

eellison added a commit that referenced this pull request Nov 16, 2022
ghstack-source-id: 0439479
Pull Request resolved: #89146
@eellison
eellison requested review from ezyang, jansel and ngimel November 16, 2022 17:50
@ezyang

ezyang commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

What's the inputs (?) You want inputs in the pool. In conventional usage, we'll be copying in the training data to the cuda graph to kick off the run.

@ezyang

ezyang commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

To avoid overwriting the live output values of a previous invocation, we can either check that the backward has been run for a cudagraph forward (not clear to me this is sufficient ?). We potentially could also do weak-ref ref counting.

For correctness, don't you have to do the "wait until all the incoming refcounts are dead". Doesn't have to be weak-ref, IIRC?

Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved

@eellison eellison left a comment •

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.

What's the inputs (?) You want inputs in the pool. In conventional usage, we'll be copying in the training data to the cuda graph to kick off the run.

the inputs are being copied into the pool

@eellison

Copy link
Copy Markdown
Contributor Author

For correctness, don't you have to do the "wait until all the incoming refcounts are dead". Doesn't have to be weak-ref, IIRC?

Uh, this is a bit outdated, check PR.



cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

This is a first PR implementing the following plan of POR:

- We will use a single Memory Pool across all cudagraphs. The memory pool will contain inputs (?), intermediates, and outputs. CUDAGraphs memory pool ensures that memory allocated within graph capture is not allocated outside of the memory pool, so that memory addresses remain static during graph replay. However, within the memory pool, normal storage allocation occurs, so there is no memory overhead. So long as we invoke separate CUDAGraphs in a consistent order as they are recorded, and do not retain extraneous references to Tensors, there should be no overhead. We will keep a global tape of the initial graph recordings and subsequent usages. Enforcing consistent CUDAGraph usage will also allow us to avoid copying over inputs to a CUDAGraph that are the outputs of a prior one. 
- To avoid “static outputs” being permanently allocated, which interferes with both memory being reclaimed within CUDAGraphs and [gradient stealing](https://github.com/pytorch/pytorch/blob/master/torch/csrc/autograd/functions/accumulate_grad.h#L52), we will reconstruct output tensors Tensors with the appropriate fixed storage data pointers and other metadata on each cudagraph invocation. 
- When a CUDAGraph usage diverges from the existing tape we can 1. free the memory pool to the rest of the cuda allocator, invalidating the CUDAGraphs of our tape but keeping the existing Tensors alive or 2. Run torch inductor without cudagraphs for the remainder of the tape. The latter would have some memory penalty because it would not use memory from the memory pool 
- Because cudagraphs freeze memory addresses, the invocation of a cudagraph will replace whatever values the memory had previously. To avoid overwriting the live output values of a previous invocation, we can either check that the backward has been run for a cudagraph forward (not clear to me this is sufficient ?). We potentially could also do weak-ref ref counting.

Not everything is implemented yet, and I will not land this pr without subsequent follow ups. 

Follows ups, for correctness/minimal viable product in terms of priority include :
- Registering the cudagraphs as thread local state that needs to be copied over in autograd
- Ensuring clean up works successfully
- Adding tests for all the edge cases provided reviewers are okay with approach
- Handling subsequent usage when a graph invariant is broken, i.e. moving cuda graph allocations from the private memory pool to eager

And then further work would be:
- Allowing multiple, separate cudagraph paths by making the cuda caching allocator resumable and doing new recordings. 
- Adding configs to weaken some of the correctness conditions (for power user who can verify correctness)



[ghstack-poisoned]
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread test/inductor/test_torchinductor.py Resolved


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

This is a first PR implementing the following plan of POR:

- We will use a single Memory Pool across all cudagraphs. The memory pool will contain inputs (?), intermediates, and outputs. CUDAGraphs memory pool ensures that memory allocated within graph capture is not allocated outside of the memory pool, so that memory addresses remain static during graph replay. However, within the memory pool, normal storage allocation occurs, so there is no memory overhead. So long as we invoke separate CUDAGraphs in a consistent order as they are recorded, and do not retain extraneous references to Tensors, there should be no overhead. We will keep a global tape of the initial graph recordings and subsequent usages. Enforcing consistent CUDAGraph usage will also allow us to avoid copying over inputs to a CUDAGraph that are the outputs of a prior one. 
- To avoid “static outputs” being permanently allocated, which interferes with both memory being reclaimed within CUDAGraphs and [gradient stealing](https://github.com/pytorch/pytorch/blob/master/torch/csrc/autograd/functions/accumulate_grad.h#L52), we will reconstruct output tensors Tensors with the appropriate fixed storage data pointers and other metadata on each cudagraph invocation. 
- When a CUDAGraph usage diverges from the existing tape we can 1. free the memory pool to the rest of the cuda allocator, invalidating the CUDAGraphs of our tape but keeping the existing Tensors alive or 2. Run torch inductor without cudagraphs for the remainder of the tape. The latter would have some memory penalty because it would not use memory from the memory pool 
- Because cudagraphs freeze memory addresses, the invocation of a cudagraph will replace whatever values the memory had previously. To avoid overwriting the live output values of a previous invocation, we can either check that the backward has been run for a cudagraph forward (not clear to me this is sufficient ?). We potentially could also do weak-ref ref counting.

Not everything is implemented yet, and I will not land this pr without subsequent follow ups. 

Follows ups, for correctness/minimal viable product in terms of priority include :
- Registering the cudagraphs as thread local state that needs to be copied over in autograd
- Ensuring clean up works successfully
- Adding tests for all the edge cases provided reviewers are okay with approach
- Handling subsequent usage when a graph invariant is broken, i.e. moving cuda graph allocations from the private memory pool to eager

And then further work would be:
- Allowing multiple, separate cudagraph paths by making the cuda caching allocator resumable and doing new recordings. 
- Adding configs to weaken some of the correctness conditions (for power user who can verify correctness)



[ghstack-poisoned]


cc mlazos soumith voznesenskym yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx peterbell10 desertfire

This is a first PR implementing the following plan of POR:

- We will use a single Memory Pool across all cudagraphs. The memory pool will contain inputs (?), intermediates, and outputs. CUDAGraphs memory pool ensures that memory allocated within graph capture is not allocated outside of the memory pool, so that memory addresses remain static during graph replay. However, within the memory pool, normal storage allocation occurs, so there is no memory overhead. So long as we invoke separate CUDAGraphs in a consistent order as they are recorded, and do not retain extraneous references to Tensors, there should be no overhead. We will keep a global tape of the initial graph recordings and subsequent usages. Enforcing consistent CUDAGraph usage will also allow us to avoid copying over inputs to a CUDAGraph that are the outputs of a prior one. 
- To avoid “static outputs” being permanently allocated, which interferes with both memory being reclaimed within CUDAGraphs and [gradient stealing](https://github.com/pytorch/pytorch/blob/master/torch/csrc/autograd/functions/accumulate_grad.h#L52), we will reconstruct output tensors Tensors with the appropriate fixed storage data pointers and other metadata on each cudagraph invocation. 
- When a CUDAGraph usage diverges from the existing tape we can 1. free the memory pool to the rest of the cuda allocator, invalidating the CUDAGraphs of our tape but keeping the existing Tensors alive or 2. Run torch inductor without cudagraphs for the remainder of the tape. The latter would have some memory penalty because it would not use memory from the memory pool 
- Because cudagraphs freeze memory addresses, the invocation of a cudagraph will replace whatever values the memory had previously. To avoid overwriting the live output values of a previous invocation, we can either check that the backward has been run for a cudagraph forward (not clear to me this is sufficient ?). We potentially could also do weak-ref ref counting.

Not everything is implemented yet, and I will not land this pr without subsequent follow ups. 

Follows ups, for correctness/minimal viable product in terms of priority include :
- Registering the cudagraphs as thread local state that needs to be copied over in autograd
- Ensuring clean up works successfully
- Adding tests for all the edge cases provided reviewers are okay with approach
- Handling subsequent usage when a graph invariant is broken, i.e. moving cuda graph allocations from the private memory pool to eager

And then further work would be:
- Allowing multiple, separate cudagraph paths by making the cuda caching allocator resumable and doing new recordings. 
- Adding configs to weaken some of the correctness conditions (for power user who can verify correctness)



[ghstack-poisoned]
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Outdated
assert isinstance(inputs, (list, tuple))
self.graph = torch.cuda.CUDAGraph()
self.model = model
static_input_idxs = remove_unaligned_input_idxs(inputs, static_input_idxs)

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 know this is old code, but it occurs to me we should probably warn when an unaligned parameter induces copies into cuda graphs

Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
Comment thread torch/_inductor/compile_fx.py Resolved
@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.

Comment thread torch/_inductor/cudagraph_trees.py Resolved
id: GraphID,
parent: Optional[CUDAGraphNode],
inputs: List[Tensor],
cuda_graphs_pool: Tuple[int, int],

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.

What's this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lol I was surprised by that too, it's an Opaque token (returned by a call to [graph_pool_handle()] or [other_Graph_instance.pool()]) according to the doc, but it looks like an (int, int)

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.

If this is derivable from Graph, then I guess this is purely for caching?

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 is the memory pool handle to use a single pool across separate recordings

)

# we preserve a single reference to executed outputs that is then referenced
# in children to avoid children having to chase parent pointers in the hot path

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.

There seems to be some invariant here, it would be nice if it was explicitly written out

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.

In particular, according to the comment, it should be possible to recompute the output weakrefs by chasing parent pointers. We should implement this and have a debug mode to actually check that this is consistent.

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.

Can implement this. I dont think there is any invariant here besides what is commented.

# the cudagraphify_fns. Reference to the Graph is needed to keep the private pool from
# deallocation.
self.live_tensors_count = 0
self.graph: Optional[torch.cuda.CUDAGraph] = None

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.

Not sure what this is

@eellison eellison Mar 13, 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.

"Reference to the Graph is needed to keep the private pool from deallocation."

All the cudagraphify_fns are dead, but we keep graph around to prevent deallocation. i simplify this in a later PR.. can merge that change back here.

Comment thread torch/_inductor/cudagraph_trees.py Resolved
Comment thread torch/_inductor/cudagraph_trees.py Resolved
id: GraphID,
parent: Optional[CUDAGraphNode],
inputs: List[Tensor],
cuda_graphs_pool: Tuple[int, int],

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.

If this is derivable from Graph, then I guess this is purely for caching?

Comment thread torch/_inductor/cudagraph_trees.py Outdated

self.device: int = next(
(x.device.index for x in inputs if is_cuda_tensor), None
)

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't cuda graphs be multi device?

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 it an error if we can't infer the device?

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 is cleaned up in the last pr of the stack.. hard to iterate on the stack but also keep things separate and applied to all applicable prs :/

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'm OK with squashing all of the PRs past this.

Comment thread torch/_inductor/cudagraph_trees.py Outdated
# in children to avoid children having to chase parent pointers in the hot path
# DO NOT reassign output_weakrefs, only call `clear()`
self.outputs_weakrefs: List[Optional[TensorWeakRef]] = []
self.path_weakrefs: List[List[Optional[TensorWeakRef]]] = [

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 don't understand what the graph index means here

Comment thread torch/_inductor/cudagraph_trees.py Outdated
self.recorded_liveness_before_graph: List[List[bool]] = []
self.recorded_liveness_after_graph: List[List[bool]] = []

# indices into node at level i for output j

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 have no idea, at thisnpoint, what a "level" is

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.

lol took that terminology from wikipedia. the level of the tree is distance from the root. maybe depth is more idiomatic. or i'll just spell out with the full description..

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 agree level is unambiguous for this. It's surprising though because you don't have a root, you would traverse parent pointers to populate this.

@eellison eellison Mar 14, 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 might be cleaner for me to pass in a root, instead of a parent. it doesn't matter perf wise (dont traverse on hot path) but it would be cleaner perhaps. Edit i dont really think so, since that complicates finding the right path. Could pass in parent and root I guess

self.live_indices_after_graph: List[Tuple[int, int]] = []

if self.parent is not None:
previous_liveness = self.parent.recorded_liveness_after_graph

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.

Paradoxically, I think the names here are a bit too long, and shorter names would have helped me for clarity here

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.

what do you think would be better ?


if self.parent is not None:
previous_liveness = self.parent.recorded_liveness_after_graph
curr_liveness = self._get_liveness(self.path_weakrefs)

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.

If these methods don't actually depend on entries in self, I might suggest declaring them as top level functions to make it clear they don't access self in an unrestricted way.

previous_liveness = self.parent.recorded_liveness_after_graph
curr_liveness = self._get_liveness(self.path_weakrefs)

different_indices = self._get_different_indices(

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.

A small data structure for indices might help with code organization here

Comment thread torch/_inductor/cudagraph_trees.py Outdated

# graph needs to be kept alive for the duration of the model
# otherwise the memory pool would be freed on the first recording
inps_alloc_graph = torch.cuda.CUDAGraph()

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.

Needing two cuda graphs is surprising

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 is cleaned up in a later pr

CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
Comment thread test/inductor/test_torchinductor.py Resolved

@dynamo_utils.dynamo_timed
def cudagraphify(model, inputs, static_input_idxs=()):
from torch._inductor.cudagraph_trees import (

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.

Perhaps move all the cudagraphs related stuff (including this function) to the same file so we don't need to workaround circular imports like this.

@eellison eellison mentioned this pull request Mar 14, 2023
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
CUDA Graph Trees 

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either #91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

[ghstack-poisoned]
eellison added a commit that referenced this pull request Mar 16, 2023
ghstack-source-id: c2aa27e
Pull Request resolved: #89146

Use Storages for Cudagraph liveness

ghstack-source-id: c2aa27e
Pull Request resolved: #96154

Do warmup in cudagraph pool

ghstack-source-id: c2aa27e
Pull Request resolved: #96433

Comments for cuda graph trees

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: c2aa27e
Pull Request resolved: #96932
@eellison

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 16, 2023
@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

cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 23, 2023
CUDA Graph Trees

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either pytorch/pytorch#91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

Pull Request resolved: pytorch/pytorch#89146
Approved by: https://github.com/ezyang
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 27, 2023
CUDA Graph Trees

Design doc: https://docs.google.com/document/d/1ZrxLGWz7T45MSX6gPsL6Ln4t0eZCSfWewtJ_qLd_D0E/edit

Not currently implemented :

- Right now, we are using weak tensor refs from outputs to check if a tensor has dies. This doesn't work because a) aliasing, and b) aot_autograd detaches tensors (see note [Detaching saved tensors in AOTAutograd]). Would need either pytorch/pytorch#91395 to land to use storage weak refs or manually add a deleter fn that does what I want. This is doable but theres some interactions with the caching allocator checkpointing so saving for a stacked pr.

- Reclaiming memory from the inputs during model recording. This isn't terribly difficult but deferring to another PR. You would need to write over the input memory during warmup, and therefore copy the inputs to cpu. Saving for a stacked pr.

- Warning on overwriting previous generation outputs. and handling nested torch.compile() calls in generation tracking

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

Pull Request resolved: pytorch/pytorch#89146
Approved by: https://github.com/ezyang
@facebook-github-bot
facebook-github-bot deleted the gh/eellison/356/head branch June 8, 2023 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants