Pytorch code can't stop

As long as the code of pytorch is designed to differentiate automatically and calls backward() function, it will cause the program cannot automatically stop, and the key of stop square will become a skeleton. Who can tell me how to solve it? It drives me crazy! The current torch version is 1.3.0. And the IDE I used is pycharm.


This is because pytorch uses c++ code to speed up computations and PyCharm cannot interrupt it while it’s in the c++ code. This is a good sign actually, that means that your code spend most of its time in c++ and is thus very efficient :slight_smile:

Actually I need to use matlab to call the script written by pytorch, so I expect the python script can stop automatically after running. Do you know how to fix this bug? Thank you very much!!!


I am not sure to understand what you mean by “cannot stop autatically” ?

Also which OS are you using?

My Os is window 7. I hope the three figures could explain my confusion. As is show in fig 1, “Process finished with exit code 0”. Just after I execute the backward(), I find the code can’t terminate, although code has finished! (fig 2). And the code can be run perfectly in python console(fig 3). So how to terminate automatically even if I call the backward() function. That’ the point! Again, thanks a lot for your time. It really very kind of you!!!


This may be linked to as well.
I am not sure what to do here as we cannot reproduce this.
Could you give more informations on how you installed pytorch, and which version you use? Do you use cuda?

I installed pytorch on Windows 7 using conda ( conda install pytorch torchvision cpuonly -c pytorch ) in the most recent, stable version (python 3.7, pytorch 1.3.0). And I ever used pytorch 1.2.0, the issue still exited.

This issue is only reproducible on Windows 7 currently. However, we don’t have Windows 7 machines for debugging. So to make it clear, you’ll need to build the debug version of PyTorch, get the stacktrace in the C++ side and then we may know what’s wrong there.