Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradient checkpointing needs static graph #225

Open
rom1504 opened this issue Aug 15, 2022 · 5 comments
Open

gradient checkpointing needs static graph #225

rom1504 opened this issue Aug 15, 2022 · 5 comments

Comments

@rom1504
Copy link
Collaborator

rom1504 commented Aug 15, 2022

RuntimeError: Expected to mark a variable ready only once. This error is caused by one of the following reasons: 1) Use of a module parameter outside the forward function. Please make sure model parameters are not shared across multiple concurrent forward-backward passes. or try to use _set_static_graph() as a workaround if this module graph does not change during training loop.2) Reused parameters in multiple reentrant backward passes. For example, if you use multiple checkpoint functions to wrap the same part of your model, it would result in the same set of parameters been used by different reentrant backward passes multiple times, and hence marking a variable ready multiple times. DDP does not support such use cases in default. You can try to use _set_static_graph() as a workaround if your module graph does not change over iterations.
Parameter at index 753 has been marked as ready twice. This means that multiple autograd engine hooks have fired for this particular parameter during this iteration. You can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print parameter names for further debugging.

https://discuss.pytorch.org/t/ddp-and-gradient-checkpointing/132244/3

https://github.com/mlfoundations/open_clip/blob/c933765dc557d88e15be968e78d7580d95f86af8/src/training/main.py#L156

trying to figure out how to do this with accelerate

@rom1504
Copy link
Collaborator Author

rom1504 commented Aug 15, 2022

huggingface/accelerate#637 here's the fix

  • adding an option here, will PR later

@rom1504
Copy link
Collaborator Author

rom1504 commented Aug 15, 2022

#226

@rom1504
Copy link
Collaborator Author

rom1504 commented Aug 15, 2022

fyi 2x batch increase possible (ram saving) using grad checkpointing once this is fixed

@lucidrains
Copy link
Owner

@rom1504 nice! thanks for figuring this one out!

@Bhavay-2001
Copy link

Hi @rom1504, is there a fix using the pytorchlightning and hydra library as well? I'm using the hydra library to initialise my model which is of type pytorchLightning. Facing similar issue, any workaround possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants