jpuigcerver/Laia

Transfer weights of lua model to pytorch model

rafikg opened this issue · 1 comments

@jpuigcerver Thanks for your answer. Actually, I build your model using pytorch and I try to extract the weights form your lua pretrained model and transfer them to my pytorch model. I do the convolution parts correctly but I have a problem about the cudnn.BLSTM in lua and nn.lstm() in pytorch. It seems that in lua, all the parameters are flatten but not in nn.lstm() see my post https://stackoverflow.com/questions/55507905/cudnn-blstm-weight-and-biaises. How to reflatten the Lua weights and put them in the right order and place in pytroch model.

@Gouiaa the parameters are ordered as follows (extracted from https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py#L381):

------------------------------------------------------------
| weights                    | biases                      |
------------------------------------------------------------
\                             \
  \                             \
  -------------------------------
  | layer1     |layer2     |... |
  -------------------------------
  \             \
    ---------------
    |fwd   |bak   |
    ---------------