From f0a0bbb123435cb14746fa783e22fd912233bb08 Mon Sep 17 00:00:00 2001 From: Hyunsoo Luke HA Date: Thu, 14 Jul 2022 18:10:44 +0900 Subject: [PATCH] Fix torch.clamp() issue #237 --- models/swin_transformer_v2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/swin_transformer_v2.py b/models/swin_transformer_v2.py index a429d0a2c..e5697d877 100644 --- a/models/swin_transformer_v2.py +++ b/models/swin_transformer_v2.py @@ -153,7 +153,7 @@ def forward(self, x, mask=None): # cosine attention attn = (F.normalize(q, dim=-1) @ F.normalize(k, dim=-1).transpose(-2, -1)) - logit_scale = torch.clamp(self.logit_scale, max=torch.log(torch.tensor(1. / 0.01))).exp() + logit_scale = torch.clamp(self.logit_scale, max=torch.log(torch.tensor(1. / 0.01)).to(self.logit_scale.get_device())).exp() attn = attn * logit_scale relative_position_bias_table = self.cpb_mlp(self.relative_coords_table).view(-1, self.num_heads)