【发布时间】:2018-01-01 17:51:54
【问题描述】:
有没有办法在火炬模型的并行流之间共享权重?
例如,我有以下模型。
mlp = nn.Sequential();
c = nn.Parallel(1,2) -- Parallel container will associate a module to each slice of dimension 1
-- (row space), and concatenate the outputs over the 2nd dimension.
for i=1,10 do -- Add 10 Linear+Reshape modules in parallel (input = 3, output = 2x1)
local t=nn.Sequential()
t:add(nn.Linear(3,2)) -- Linear module (input = 3, output = 2)
t:add(nn.Reshape(2,1)) -- Reshape 1D Tensor of size 2 to 2D Tensor of size 2x1
c:add(t)
end
mlp:add(c)
现在我想在不同数量的i 之间共享上面nn.Linear 层的权重(包括所有内容、权重、偏差、梯度)(例如nn.Linear(3,2)[1] 和nn.Linear(3,2)[9])。 我必须分享哪些选项?
还是建议使用不同的容器/模块方法?
【问题讨论】:
标签: lua neural-network torch