-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Python Crashes When Importing Torch With C API #104128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@mahdimedfouni I don't know what you're asking. |
Can you please provide an source code of your example and backtrace of the crash. |
@malfet I'm using a fork of a fork of a five year old GitHub project that's heavily embedded into my own project. The closest I can get to providing source code is linking this line as the one causing issues. I do have a small update as well. I tried attaching my projects .exe file in VS Code for debugging and I found that it isn't the case that Python is crashing. Rather, my C++ file seems to hang midway through importing torch when I call |
This is the output when torch imports properly:
This is the output when torch fails to import:
|
Run "gflags /i MyProject.exe +sls" after compiling your exe, and then debug in Visual Studio, this should show more details on loading the DLLs |
@andreigh I've never used gflags before. I tried running the command in Command Prompt, but I got this error:
Do I need to download something to use gflags? I found these 2 potential sources: Please let me know if either of these are correct or if there's something else I need. |
Yes you need to download it from https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools. This is very helpful to debug various DLL loading issues.
…On Sat, Sep 9, 2023, 5:24 PM tempaccountforissue ***@***.***> wrote:
@andreigh <https://github.com/andreigh> I've never used gflags before. I
tried running the command in Command Prompt, but I got this error:
'gflags' is not recognized as an internal or external command,
operable program or batch file.
Do I need to download something to use gflags?
I found these 2 potential sources:
https://github.com/gflags/gflags/tree/master
https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/
Please let me know if either of these are correct or if there's something
else I need.
—
Reply to this email directly, view it on GitHub
<#104128 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS4G672CMQZ2B5TQDS6FCDXZTUCBANCNFSM6AAAAAAZSB4OTE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I was able to download gflags and run the command. It returned a huge debug log, so I'm only including the last hundred or so lines since that should be where the DLL is failing to load. EDIT: I think this line is what's causing the DLL to fail to load, but I'm not sure what it means.
|
Can you save and attach the entire huge log please ? Thank you |
Sure thing, here it is. Just as a heads up, I made my project with Unreal Engine, so some of the debug might have more to do with Unreal than PyTorch, but idk. |
Nothing related to PyTorch in the log. |
If you do ctrl+f and search for This is the source code for ue_site.py: print("Running ue_site")
import torch
print("Not Running ue_site") |
Yes it does, I wanted to say no errors related to PyTorch in that log :) |
It's weird, even before running gflags it doesn't return an error. It just sort of freezes half way through importing torch. Release mode also has the same issue. If it'd make it easier to debug, I could send you the projects folder to your email? |
@andreigh Hello, it's been about a week so I just wanted to follow up and check if you saw my last comment. |
Sorry, yes please do ! We can also set up a remote debugging session
…On Thu, Sep 21, 2023 at 5:02 PM tempaccountforissue < ***@***.***> wrote:
@andreigh <https://github.com/andreigh> Hello, it's been about a week so
I just wanted to follow up and check if you saw my last comment.
—
Reply to this email directly, view it on GitHub
<#104128 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAS4G63WWTN7LAQ2Z7YX66DX3S2PDANCNFSM6AAAAAAZSB4OTE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@andreigh I just sent over a mega link for my project to the email on your profile page. Please let me know if you received it. If it is able to work on your computer, but not on mine, then a remote debugging session would definitely be good. |
@tempaccountforissue any luck with the debugging session? |
I am closing this issue due to a lack of activity and since I could not reproduce it. Please don't hesitate to open a new issue if you still encounter this issue. |
🐛 Describe the bug
EDIT: Please read my comment to @malfet below. It isn't the case that Python is crashing. Rather, my C++ file seems to hang midway through importing torch when I call
PyImport_ImportModule
.I'm trying to embed Python into a C++ based application using the Python/C API. If I don't include an embedded Python installation inside my projects folder, then the program uses my local Python install by default. Using the local install doesn't result in any errors and torch is able to import successfully. However, if I include a Windows embeddable package (64-bit) version of Python in my projects folder, then Python crashes after calling
PyImport_ImportModule("importsFile")
in my C++ file.Inside of
importsFile.py
I have the following code:If I comment out
import torch
, then the other modules are able to import without error. However, if I leaveimport torch
uncommented, then Python crashes.I'm not sure if this is a bug on Python's side or PyTorch's side. Python only seems to crash when importing torch specifically, so it seems to me like it should be on PyTorch's side, but I may be wrong about this.
Is this a known issue?
How can I fix it?
Versions
PyTorch version: 2.0.1+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A
OS: Microsoft Windows 10 Education
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A
Python version: 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19041-SP0
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3070 Ti
Nvidia driver version: 535.98
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Architecture=9
CurrentClockSpeed=3701
DeviceID=CPU0
Family=107
L2CacheSize=6144
L2CacheSpeed=
Manufacturer=AuthenticAMD
MaxClockSpeed=3701
Name=AMD Ryzen 9 5900X 12-Core Processor
ProcessorType=3
Revision=8448
Versions of relevant libraries:
[pip3] numpy==1.24.1
[pip3] torch==2.0.1+cu118
[pip3] torchaudio==2.0.2+cu118
[pip3] torchvision==0.15.2+cu118
[conda] Could not collect
cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @vladimir-aubrecht @iremyux @Blackhex @cristianPanaite
The text was updated successfully, but these errors were encountered: