0
トーチモデルの並列ストリーム間でウェイトを共有する方法はありますか?パラレルストリーム間でウェイトを共有するにはどうすればよいですか?
たとえば、次のモデルがあります。
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)
そして今は、上記nn.Linear
層のi
の異なる数を横切る(したがって、nn.Linear(3,2)[9]
と例えばnn.Linear(3,2)[1]
)(すべて、重量、バイアス、勾配を含む)の重量を共有したいです。 これらを共有するにはどのようなオプションが必要ですか?
また、別のコンテナ/モジュールアプローチを使用することをお勧めしますか?