Solved by ptrblck in post #2 
              
              
                You can use the Python while loop in PyTorch directly. 

PyTorch doesn’t use sessions and will be eagerly executed. I.e. if you run a PyTorch operation (in the default mode), the result is directly available (similar to e.g. numpy).