mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Embedding Layer is expanded every timestep in LSTM

Open Kublai-Jing opened this issue 11 years ago • 8 comments

Hi mxnet,

Not sure if this is true, but the embedding layer, say with shape (10000,256, i.e. 10000 vocabulary, 256-dimensional embedding) seems to be expanded at every timestep for the LSTM, even if the weights are shared. I don't know how to verify this but as far as what I observed I believe this is true, which causes huge memory consumption. I thought if we share weights for every timestep, we only need to allocate memory for the actual embedding (256 x t) for t-step lstm in this case but not allocating (10000 x 256 x t), which for the FullyConnected layer will be true. It seems that the current Embedding layer takes the same amount of memory as a FullyConnected layer, but I am not sure whether it's this issue that causes lots of memory overhead in lstm. I wonder where I should be looking at to try to fix this issue ?

Thanks!

Kublai-Jing avatar Nov 26 '15 01:11 Kublai-Jing

@antinucleon probably this is one of the reason why our lstm isn't fast as expected?

mli avatar Nov 26 '15 02:11 mli

Will check it tomorrow. Today & tomorrow morning I am benchmarking ELU.

antinucleon avatar Nov 26 '15 02:11 antinucleon

This could be the reason, because the weight is binded with a shared variable, and current graph optimizer is yet not smart enough to change the gradient summation to an addto to the original variable. Either we directly bind by ndarray, or make the graph executor smarter to handle the addto case more gracefully

tqchen avatar Nov 26 '15 06:11 tqchen

has this problem been fixed?

JianboTang avatar Dec 02 '15 05:12 JianboTang

Probably not. Seems that solving this will have to dive into mshadow code, which is harder ?

Kublai-Jing avatar Dec 09 '15 20:12 Kublai-Jing

@JianboTang @Kublai-Jing As tqchen pointed out, I think you can replace simple_bind with bind and directly provide the ndarrays as a temporary solution

piiswrong avatar Dec 09 '15 21:12 piiswrong

Yeah that's what I am doing now : )

Kublai-Jing avatar Dec 09 '15 23:12 Kublai-Jing

hopefully fixed by https://github.com/dmlc/mxnet/pull/1697

tqchen avatar Mar 22 '16 05:03 tqchen