Thanks for the response. I am mentioning below the forward_flex function.
def forward_flex(self, x):
    b, c, h, w = x.shape

    pos_embed = self._resize_pos_embed(self.pos_embed, 
                                        h // self.patch_size[1], 
                                        w // self.patch_size[0])

    B = x.shape[0]
    x = self.patch_embed.proj(x).flatten(2).transpose(1, 2)
    cls_tokens = self.cls_token.expand(B, -1, -1)  
    x = torch.cat((cls_tokens, x), dim=1)

    x = x + pos_embed
    x = self.pos_drop(x)

    for blk in self.blocks:
        x = blk(x)

    x = self.norm(x)

    return x

I also observed similar issues of dataparallel with types.MethodType has been reported here 1.