Repository navigation
[WIP] Dynamic Tensor Rematerialization(Checkpointing) - #42056
MarisaKirisame wants to merge 1 commit into
Conversation
Implements CheckpointTensor backend Hook up the overload with a passing test. (pytorch#15) * save * save * review * review * add back files Adding some overload (pytorch#16) * save * save * review * remove outdated file * save * can compile again * save * save * up up array * finsih the overloads * replace vec[n] with vec.at(n) make resnet pass again, adding more logs for logging simulator (pytorch#17) * commit * add more overloads * fix log * save Logging everything for resnet (pytorch#18) * save * save * save * save * use release instead of free Fix logger (special handling for small constants) (pytorch#19) * save * fix comment TreeLSTM overloads (pytorch#21) Overloads for mean and mean.dim (needed for densenet) Add overloads for U-Net Add ability to annotate log and make new log file (pytorch#25) Restore overloads needed for LSTM and GRU Implemented unrolled_gan (pytorch#23) * save * save * save Overload bitwise and for ParityACT Add various overloads for ACT model Log aliases of operator outputs Overloads and changes needed for transformer Overloads for topk functions Add overloads for deepspeech More overloads for ACT DTR implementation first pass (pytorch#37) save before change save before change add aliaspool design, and add weak/strong pointer discussion add more code rebase add allocator hook save metadata to prepare for eviction save refactor: move log to a seprate file add file raii save save comment save save save save find error, bisecting code save save address review comment address comment address comment fix segfault save save pin save save save save save refactor - remove stitch save save [ impl ] overload diag & mv refactor - remove stitch save save restore equivalentclassnode save save save 50% resnet here we go 50% resnet here we go save save save save save save More opts save Try removing pop-ing from loop save save save save mike try this mike try this save undo system optimization for now save save save fix compile error save save
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 00f8475 (more details on the Dr. CI page): Commit 00f8475 was recently pushed. Waiting for builds... This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. |
|
(Haven't forgotten about this, but need time to digest) |
|
We are working on other things so we arent blocked on this (yet). Let us know if there is anything we can do to help! |
|
Hi @MarisaKirisame, this is a really interesting PR. The biggest current problem with the PR is that the recording of replay has all been written out by hand; this will be a hard sell from a maintenance perspective. I think what's realistic is for us to wait until full boxing/unboxing support, and then reimplement the manual codegen part as a boxed fallback. From there, the question is in-tree versus out-of-tree; there are very few other "invasive" changes and so I think this could fairly easily live out of tree. I can help you guys set this up, when boxed fallback is running. If the extension gets quite popular we can then talk about inclusion in core. If you want to take a crack at boxed fallback today (which will actually be a decent thing to try, since we do have a decent amount of op coverage), the best code to look at are these:
|
|
@ezyang is there any way to have it out of tree while not requiring user to recompile pytorch from scratch? compiling pytorch take lots of time and is quite hard to setup for a typical ML researcher that only use python. |
|
Yeah, out of tree would be a C++ extension like torchvision, no need to compile PyTorch from scratch, you can just build based off of the release version of PyTorch. |
|
@ezyang for the dtr to work we must hook all inplace operation. how can i do that with fallback? |
|
Can you tell me more about what kind of hooking you need to do? This may be hard to do. |
|
@ezyang the current way DTR handle mutation rn, is that it pretend all Tensor is a Ref, all inplace operation as clone and inplace on the cloned result, and DTR only work on ImmutableTensor. So I have to hook all mutable call, and figure out what argument is getting changed, and how is it related to the output. |
|
OK. With DTR we should be able to interpose in on calls to inplace (in the same way we interpose on functional calls to record the trace). So you would just need a way to get information about (1) is the op inplace and (2) the correspondence of inputs to outputs. This information can all be derived from the function schema. So yes, in principle it is doable. Not sure how easy it is in practice right now. |
|
So I can get the schema? I think that's what I need - most inplace only modify a single thing and it is easy to figure out. I will see if I hit any problem. |
|
Yup. In backend fallback you'll get an OperatorHandle which you can use to retrieve the schema. I think we even have a few examples of doing this already. |
|
It seems that the above PR is not successfully compiled. Is there a fix for it? |
|
Btw, this implementation adapts global variables to record memory usage, which only supports a single device and might cause a problem for distributed case. |
|
Hi @shenh10, I’ve chatted with Nuno Lopes and @ezyang about this and long term it would be nice to get this feature into PyTorch but it looks like the best path forward involves some refactoring to related systems first. Happy to chat more if you’re interested, and while there’s no roadmap right now for getting DTR into PyTorch, I think there’s interest in moving in that direction. And yes, the code is garbage, we are just trying to make it work for our evaluation, and thus we do not handle multiple device. |
|
@MarisaKirisame Sure, it's my pleasure to have a deeper chat. Except for checkpointing, it would be nice to have some automatic memory-saving choices in PyTorch ecosystem. The current codebase is indeed far from ready for a formal integration and release, cause I have faced some segfaults during testing your codes. Btw, I would like to help if you need more people engaged in. |
|
@shenh10 sure, email me to figure out a time to chat! |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
|
Hi @ezyang , I'm developer from SenseTime, we really needs this MR to allow pytorch training bigger models. we have spent almost half a year to move it forward on pytorch 1.11, we found some pains when developing dtr on pytorch, may you guys give some advice?
|
|
This PR is DTR v2 which uses backend fallback, I'm currently working on DTR v1, trying to decrease DTR overhead and make it more efficiency. Several months later, I will use backend fallback to implement DTR v2 |
|
Hey @Jack47
I also wanted to mention that if you're seriously interested in reviving this PR, we might want to sit down and discuss the overall design of this PR. I think there are ways to do this in a much simpler way (with higher overhead) that might be enough for experimentation and/or non-overhead dominated models. |
Hey @albanD , thanks for quick response, those advices are useful, I'll read CONTRIBUTING.md carefully and use github ci to help me building wheel. for 4, I mean there are existing old pytorch plugins that are using pybind11, so those plugins are not using dispatcher. I'm seriously interested in reviving this PR, so eager to known more about simpler way. I'm currently working on DTR v1 which doesn't use backend fallback, I've spent too much time on wraping pytorch op :(. So I want to try this PR. My goal is to use DTR in production env(A100 10 nodes) finally, so I want to find a little overhead design. |
Can I chime in on that? I aint maintaining this heavily anymore, as I moved onto other research project, but I'd love to share some knowledge/insight and get some design feedback. |
|
Created a slack channel as a higher bandwidth channel to sync on this. |
We had been designing a checkpointing algorithm, Dynamic Tensor Rematerialization, that work for dynamic graph.

With our work, we had successfully save 40%-80% memory with less then double the computation cost.
We want to contribute to pytorch by upstreaming the algorithm, however, we are not pytorch developers and this is our first pytorch pr. Can anyone help and discuss what should be done?
Dynamic Tensor Rematerialization is the paper and https://github.com/uwsampl/dtr-prototype is the artifact evaluation.