Assuming valX is a tensor with the complete validation data, then this approach would be generally right, but you might of course run out of memory, if this tensor is too large.
The usual approach would be to wrap it in a Dataset and DataLoader and get the predictions for each batch. The data loading tutorial 158 gives you some information how to create a Dataset and DataLoader.
Also, to save memory during evaluation and test, you could wrap the validation and test code into a with torch.no_grad() block.