I miss the warning that grad and param do not obey the gradient layout contract

I have located the line of code that caused this warning, but I do not know how to fix it. I have tried the solutions provided by others, which is to add ‘.contiguous()’, but no matter how I modify it, I can not improve the warning. The code caused this warning is as follows:
x = x + self.drop_path(self.mlp(self.norm(x), H, W))

However, there is also a strange phenomenon that using “x = x + self.drop_path(self.mlp(x, H, W))”, this warning will be solved.

Please help me!

I resolved the warning! The reason for it is not norm. Because I added DWConv to self.mlp, which contains transpose().view(), which is actually the culprit that caused the warning.

The modified code is x = x.transpose(1, 2).contiguous().view(N, C, H, W).