pytorch
大指挥官
你的代码,就是我的代码
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PyTorch 分布式训练 DistributedDataParallel 注意事项
最近写代码,用的pytorch的DDP分布式工具。发现一个问题,如果在代码中,模型在一次训练中有两次前项传播,如下:model = Model()for i, (x1, x2, y) in enumerate(trloader): x = x.cuda() y = y.cuda() p1 = model(x1) p2 = model(x2) ...程序会爆如下错误:RuntimeError: one of the variables needed for gradient compu原创 2021-04-23 11:40:19 · 850 阅读 · 0 评论 -
PyTorch Bug 记录:one of the variables needed for gradient computation has been modified by an inplace
有一段代码在 pytorch 1.2 上没有问题,但是移植到 pytorch 1.8 就会报如下错误:RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3136, 10]], which is output 0 of TBackward, is at version 2; expecte原创 2021-04-02 18:29:38 · 4493 阅读 · 5 评论 -
在 nn.Sequential 中使用 reshape
pytorch中没有nn.Reshape层,如果想使用 reshape 功能,通常:class Net(nn.Module): def __init__(self): super().__init__() ... def forward(self, x): ... h = h.view(-1, 128) ...如果要想在 nn.Sequential 中使用 Reshape 功能,可以自定义Reshape层:class Reshape(nn.Module): def _原创 2021-01-05 11:10:20 · 5464 阅读 · 1 评论
分享