美文网首页
python decorator的理解

python decorator的理解

作者: 昵称己存在 | 来源:发表于2021-01-18 13:14 被阅读0次
MyModel(nn.Module):
    ...
    @torch.cuda.amp.autocast()
    def forward(self, input):
       ...


model = MyModel()
dp_model = nn.DataParallel(model)

with torch.cuda.amp.autocast(enable=False):  # !!!!!!!!!!!!!
    output = dp_model(input)
    loss = loss_fn(output)

即使在外面使用了enable=False, 如果model定义里面,只是在forward上面加@torch.cuda.amp.autocast(); 还是会启用。

default enable是true。 上层的with torch.cuda.amp.autocast(enable=False): 不能影响到@torch.cuda.amp.autocast();

相关文章

网友评论

      本文标题:python decorator的理解

      本文链接:https://www.haomeiwen.com/subject/crxxzktx.html