I’m thinking of writing an encoder-decoder, with shared embedding weights, like:
embedding = nn.Embedding(input_size, hidden_size)
encoder = Encoder(embedding=embedding)
decoder = Decoder(embedding=embedding)

where eg Encoder __init__ would do:
def __init__(self, embedding):
    hidden_size = embedding.weight.size()[1]
    self.embedding = embedding
    self.enc_rnn = nn.RNN(hidden_size, hidden_size)

and then create the optimzer like:
opt = optim.Adam(
    list(embedding.parameters()) +
    list(encoder.parameters()) +
    list(decoder.parameters())
)

To what extent is having the embedding parameters passed to the optimizer multiple times ok/ not ok? Any better way to handle this, in idiomatic pytorch? I want to avoid allocating the embedding multiple times, then deallocating the ones we dont need, ideally.