Yeah, i mean i tried all of them non-simultaneously.
Anyway,when i tring to place it into forward method or into training loop i still got “RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.”
Here,how i do it
class LSTMTagger(nn.Module):
    def __init__(self, embedding_dim, hidden_dim, hidden_layers, vocab_size, tagset_size):
        super(LSTMTagger, self).__init__()
        self.hidden_dim = hidden_dim

        self.word_embeddings = nn.Embedding(vocab_size, embedding_dim)

        self.lstm = nn.LSTM(embedding_dim, hidden_dim, hidden_layers)

        self.hidden2tag = nn.Linear(hidden_dim, tagset_size)
        self.hidden = self.init_hidden()
        self.hidden2 = self.init_hidden2()


    def init_hidden(self):
        
        return (autograd.Variable(torch.zeros(1, 1, self.hidden_dim)),
                autograd.Variable(torch.zeros(1, 1, self.hidden_dim)))

    def init_hidden2(self):
        
        return (autograd.Variable(torch.zeros(1, 1, self.hidden_dim)),
                autograd.Variable(torch.zeros(1, 1, self.hidden_dim)))

    def forward(self, sentence):
        embeds = self.word_embeddings(sentence)
        lstm_out, self.hidden = self.lstm(embeds.view(len(sentence), 1, -1), self.hidden)

        lstm_out, self.hidden2 = self.lstm(embeds.view(len(lstm_out), 1, -1), self.hidden2)

        tag_space = self.hidden2tag(lstm_out.view(len(sentence), -1))
        tag_scores = F.log_softmax(tag_space, dim=1)

        # self.hidden[0].detach()
        # self.hidden[1].detach()

        return tag_scores



model = LSTMTagger(EMBEDDING_DIM, HIDDEN_DIM,hidden_layers, len(word_to_ix), len(tag_to_ix))
loss_function = nn.NLLLoss()
optimizer = optim.SGD(model.parameters(), lr=0.1)
inputs = prepare_sequence(training_data[0][0], word_to_ix)
tag_scores = model(inputs)
print(tag_scores)

for epoch in range(300):
    # model.hidden[0].detach()
    # model.hidden[1].detach()
    for sentence, tags in training_data:
        # model.hidden[0].detach()
        # model.hidden[1].detach()
       
        model.zero_grad()
        model.hidden = model.init_hidden()

        sentence_in = prepare_sequence(sentence, word_to_ix)
        targets = prepare_sequence(tags, tag_to_ix)

        tag_scores = model(sentence_in)

        loss = loss_function(tag_scores, targets)
        loss.backward()
        optimizer.step()
        # model.hidden[0].detach()
        # model.hidden[1].detach()

Different commented blocks mean where i tried it but not simultaneously.