The loss.backward() call calculates the gradients you are using in the following line with some intermediate values, which also needs some memory.
Batching might help. Is 25059 your batch size? Do you need it to be that large?
Could you explain the use case a bit more? Maybe the solution is straightforward.