Hi, because cross entropy can only calculate loss of a single time step, a normal way of training – input a batch of sequences and calculate loss accumulated over each time step of each sequence – should be implemented as follows:

input a batch of sequences, and initialize the hidden state of the model eg., an LSTM;
for each time sequence, iterate through each single time step and calculate its loss using cross entropy function. Do not clear out or re-initialize the hidden state in-between time steps of a sequence;
accumulate the loss, and .backward() once a sequence is consumed by the model.

I am wondering that how is the loss computed in this implementation.
In BPTT, suppose we have 4 time steps per input sequence (hence 4 loss terms corresponding to each time step); BPTT gives us a total loss L = L_4 + L_3 + L_2 + L_1, where L_n corresponds to time step n, in form of L_n = l_n^n + l_(n-1)^(n-1) + … + l_1^1, where n = 1~4.
However, in the implementation, we only have a single time step every time we forward and compute loss for each time step. Does that mean the L_n we get with the implementation is instead of the form L_n = l_1^1, regardless of n?