czczup / ViT-Adapter

[ICLR 2023 Spotlight] Vision Transformer Adapter for Dense Predictions
https://arxiv.org/abs/2205.08534
Apache License 2.0
1.27k stars 140 forks source link

RuntimeError: Expected to mark a variable ready only once.Move the whole vitadapter to my own code, and above error emerged #102

Closed RFKxavieryang closed 1 year ago

RFKxavieryang commented 1 year ago

The whole error discrimination is: 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. And when thier is only one block(InteractionBlock) left, it works . When the number >=2, the error appears.

Have anybody encountered this problem and willing 2 help me please.

RFKxavieryang commented 1 year ago

oops Now i realized where i go wrong

Neil7chill commented 1 year ago

Same problem. How did you fix it?

RFKxavieryang commented 1 year ago

My fault due to the 'torch.utils.checkpoint'. In extractor/injector/block class, maybe u put some parameters's requrie_grad=False during training? and the class still use torch.utils.checkpoint warped in forward function??

czczup commented 1 year ago

The module applied with torch.utils.checkpoint can not be forwarded multiple times.