小编SLu*_*uck的帖子

Pytorch动态层数?

我试图指定动态的层数,但我似乎做错了。我的问题是,当我在这里定义 100 层时,我会在前进步骤中收到错误。但是当我正确定义图层时它会起作用吗?下面是简化的示例

class PredictFromEmbeddParaSmall(LightningModule):
    def __init__(self, hyperparams={'lr': 0.0001}):
        super(PredictFromEmbeddParaSmall, self).__init__()
        #Input is something like tensor.size=[768*100]
        self.TO_ILLUSTRATE = nn.Linear(768, 5)
        self.enc_ref=[]
        for i in range(100):
            self.enc_red.append(nn.Linear(768, 5))
        # gather the layers output sth
        self.dense_simple1 = nn.Linear(5*100, 2)
        self.output = nn.Sigmoid()
    def forward(self, x):
        # first input to enc_red
        x_vecs = []
        for i in range(self.para_count):
            layer = self.enc_red[i]
            # The first dim is the batch size here, output is correct
            processed_slice = x[:, i * 768:(i + 1) * 768] …
Run Code Online (Sandbox Code Playgroud)

pytorch pytorch-lightning

7
推荐指数
2
解决办法
7421
查看次数

标签 统计

pytorch ×1

pytorch-lightning ×1