I assume that the model output and target tensors contain a temporal dimension, which represents the logits and targets for each time step, respectively?
If so, you could create the unreduced loss by specifying reduction='none' while creating the criterion, and weight the loss using a custom weight tensor indicating the “importance” for each time step.
Afterwards you could reduce the loss (e.g. by using the mean) and calculate the gradients via the backward operation.