小编use*_*491的帖子

pytorch动态计算图中的权重更新是如何工作的?

当权重分片(=多次重复使用)时,动态计算图的 Pytorch 代码中的权重更新如何工作

https://pytorch.org/tutorials/beginner/examples_nn/dynamic_net.html#sphx-glr-beginner-examples-nn-dynamic-net-py

import random
import torch

class DynamicNet(torch.nn.Module):
    def __init__(self, D_in, H, D_out):
    """
    In the constructor we construct three nn.Linear instances that we will use
    in the forward pass.
    """
    super(DynamicNet, self).__init__()
    self.input_linear = torch.nn.Linear(D_in, H)
    self.middle_linear = torch.nn.Linear(H, H)
    self.output_linear = torch.nn.Linear(H, D_out)

def forward(self, x):
    """
    For the forward pass of the model, we randomly choose either 0, 1, 2, or 3
    and reuse the middle_linear Module that many times to compute hidden layer
    representations. …
Run Code Online (Sandbox Code Playgroud)

deep-learning pytorch computation-graph

2
推荐指数
1
解决办法
628
查看次数

标签 统计

computation-graph ×1

deep-learning ×1

pytorch ×1