Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix amp pooling overflow #9670

Merged
merged 9 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mmdet/models/backbones/csp_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def __init__(self,

def forward(self, x):
x = self.conv1(x)
x = torch.cat([x] + [pooling(x) for pooling in self.poolings], dim=1)
if x.dtype == torch.float16:
x = x.float()
x = torch.cat([x] + [pooling(x) for pooling in self.poolings], dim=1).half()
else:
x = torch.cat([x] + [pooling(x) for pooling in self.poolings], dim=1)
zylo117 marked this conversation as resolved.
Show resolved Hide resolved
x = self.conv2(x)
return x

Expand Down
5 changes: 4 additions & 1 deletion mmdet/models/layers/se_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def __init__(self, channels: int, init_cfg: OptMultiConfig = None) -> None:

def forward(self, x: Tensor) -> Tensor:
"""Forward function for ChannelAttention."""
out = self.global_avgpool(x)
if x.dtype == torch.float16:
out = self.global_avgpool(x.float()).half()
else:
out = self.global_avgpool(x)
out = self.fc(out)
out = self.act(out)
return x * out