nn.MM
requires a table argument of the matrices that will be multiplied. In my case, one of the matrices is the output of some previously defined model (e.g. an nn.Sequential
) and the other is just a constant matrix. How can I inject a constant into nn
's pipeline and should I be worried that optimizer will start changing it if I do?
I'm aware that I could solve the injection problem by:
nn.Module
. This seems heavy handed.nn.Module
subclass that gets called with :forward(input)
and allows consumers to be blissfully ignorant of the existence of the constant.nn.ParallelTable
, but that would also expose the constant to model consumers.nn.Linear
with no bias and overwriting the weights. I'm just not sure how to prevent the optimizer from performing the update.You can create an nn.Linear and the override the :accGradParameters to be a no-op function
m = nn.Linear(100,200)
-- copy your weights / bias into m.weight / m.bias
m.accGradParameters = function() end
-- m is a constant multiplier thing