Some problems about the use of pytorch?

1.when i train RNN network in pytorch, the batch size is defined before the training.When i finish training,I want change the batch_size to predict the result of test set.How can i implement it?

2.when i train, i use GPU to train.when i predict the result, i wnat use the GPU, because my cpu’s memory is larger than the GPU’s.How can i implemet it?

I’m confused at them.Can you help me, please!
Thank you.

For 2, assuming you have a nn.Module somewhere that is your model and you’re trying to run on CPU for prediction, you can call model.cpu() and use that on the CPU.

1 Like


For 1, are there some ways?

From the docs, I don’t think there are restrictions on the batch_size for RNNs: .
I don’t know much about RNNs, but why can’t you just pass in an input with a different batch_size than the one you trained with?

If the batch_size is a problem, couldn’t you pad the rows of your input with zeros or random data?