sail-sg / poolformer

PoolFormer: MetaFormer Is Actually What You Need for Vision (CVPR 2022 Oral)
https://arxiv.org/abs/2111.11418
Apache License 2.0
1.3k stars 117 forks source link

Bug on transfer poolformer to detr #16

Closed lucasjinreal closed 2 years ago

lucasjinreal commented 2 years ago

Hi, I got this bug when transformer poolformer to detr-like model (simply replace backbone), It might because of detr using single feature, but I dont know exactly why, can u help take a look?

RuntimeError: 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 0: backbone.norm0.weight, backbone.norm0.bias
Parameter indices which did not receive grad for rank 0: 248 249

this is my config:

model = dict(
    # backbone=dict(
    #     type='PyramidVisionTransformerV2',
    #     embed_dims=64,
    #     _delete_=True,
    #     out_indices=(0, 1, 2, 3,),
    #     num_layers=[2, 2, 2, 2],
    #     init_cfg=dict(checkpoint='https://github.com/whai362/PVT/'
    #                   'releases/download/v2/pvt_v2_b1.pth')),
    backbone=dict(
        type='poolformer_s24_feat',
        style='pytorch',
        out_indices=(0, 1, 2, 3,),
        norm_cfg=dict(type='BN', requires_grad=False),
        init_cfg=dict(
            type='Pretrained',
            checkpoint='https://github.com/sail-sg/poolformer/releases/download/v1.0/poolformer_s24.pth.tar',
        ),
    ),
    neck=dict(
        type='SMCAFPN',
        in_channels=[64, 128, 320, 512],
        out_channels=256,
        start_level=1,
        num_outs=5,
        relu_before_extra_convs=True),
    bbox_head=dict(
        in_channels=512,
    ))
shinya7y commented 2 years ago

FORK_LAST3=1 python -m torch.distributed.launch ... will remove backbone.norm0 parameters. https://github.com/sail-sg/poolformer/blob/348a8b6a8b6fe2377ac3814db74a4a6ef1b527a3/models/poolformer.py#L306-L316

lucasjinreal commented 2 years ago

@shinya7y I fixed by specific a fpn_start_level params to avoid it. Original implementation not very elegant.

yuweihao commented 2 years ago

Hi @jinfagang and @shinya7y , thanks for your useful discussion.