In your code you are appending the output of the forward method to features which will not only append the output tensor but the entire computation graph with it. Since you are iterating the entire dataset_ your memory usage would then grow in each iteration until you could be running out of memory.
I don’t know what you are doing with features, but the common approach is to train the model using a mini-batch, which would free the computation graph with its intermediate tensors, instead of accumulating the outputs of the entire dataset and potentially call backward() once per epoch.