open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
28.5k stars 9.28k forks source link

Is it possible to pass allow_unused and materialize_grad to optim_wrapper? #11745

Closed ashkanaev closed 1 month ago

ashkanaev commented 1 month ago

Hi, there!

Im deal with a custom train pipeline which forward model partly from batch to batch. And when i trying to run a distributed train script, an error occurs

Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument find_unused_parameters=True to torch.nn.parallel.DistributedDataParallel, and by making sure all forward function outputs participate in calculating loss. If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's forward function. Please include the loss function and the structure of the return value of forward of your module when reporting this issue (e.g. list, dict, iterable). Parameters which did not receive grad for rank 1: pipeline.neck_segmentation.spatial_path.conv_7x7.conv.weight ... ....... ...... Parameter indices which did not receive grad for rank 1: 45 46 47 ...

Possible solution doc is to pass allow_unused=True and materialize_grads=True into optim_wrapper.

Is it possible to pass those args by Config or somehow?

Looking forward for reply Thanks :)

ashkanaev commented 1 month ago

Solved by find_unused_parameters = True