pytorch with torch.no_grad():
时间: 2023-09-20 13:14:39 浏览: 108
在PyTorch中,使用`with torch.no_grad():`可以创建一个上下文环境,在这个环境中计算的结果不会被自动求导。这在需要进行前向传播但不需要计算梯度的情况下非常有用。例如,当我们只是想对测试数据进行推断时,可以使用`with torch.no_grad():`来禁止自动求导以节省计算资源。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Pytorch 中的 with torch.no_grad(): 详解](https://blog.csdn.net/Z2572862506/article/details/128648752)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [pytorch中with torch.no_grad():](https://blog.csdn.net/weixin_42769131/article/details/113106280)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文