Jump to content
Sign in to follow this  
tomye

HELP ,can not run torch scipt but can be run in Python environment

Recommended Posts

wriiten a scipt,  it can be run in Python environment

 

but run in P4D, got an error

 

error1.thumb.png.de0e52bf5f6511fc275d6d6254b53965.png

 

 

anyone knows?  

Share this post


Link to post
9 hours ago, pyscripter said:

Is there another sqlite dll in your path?

actually , i don't know why the torch uses the SQLite, however , i searched the DLL files, they are all there and all of them are 64bit

 

error3.thumb.png.cbb9a03ff5170dc459b93cdcf21a35cb.png

 

and this error message ( Not a valid win32 application ) is only appear on P4D Demo01, but in my project, there is another error message

 

error4.thumb.png.0da1649ec713da7afafc69702a6cccee.png

 

the error message is :  OSError: [WinError 127] The specified program could not be found

 

same script i could run it in Python envirnoment, but can not be run in P4D , BTW, my project uses P4D thread mode ( TPythonThread.Py_Begin_Allow_Threads; )

 

and then i test the script in P4D Demo01, got an another error message: Not a valid win32 application 😞

 

 

Edited by tomye

Share this post


Link to post
7 hours ago, SwiftExpat said:

Anaconda shows to be 64 bit, what platform are you targeting in Delphi?

my project is 64-bit

the anaconda which i installed is 64-bit

the python dependent libraries are all 64-bit

Share this post


Link to post
16 hours ago, tomye said:

the anaconda which i installed is 64-bit

PythonHome needs to be set even for registered conda distributions
 

See TPythonVersion.AssignTo(PythonEngine: TPersistent); in PythonVersions.pas about this is done.

 

         Note also that for conda distributions to work properly,
         you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath]
         to your Windows path if it is not there already.

Share this post


Link to post
9 hours ago, pyscripter said:

PythonHome needs to be set even for registered conda distributions
 

See TPythonVersion.AssignTo(PythonEngine: TPersistent); in PythonVersions.pas about this is done.

 

Note also that for conda distributions to work properly,
you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath]
to your Windows path if it is not there already.

i found this issue comes from the P4D thread mode

 

i am not sure if it is P4D BUG because now i can run the script in P4D Demo01 after i PIP INSTALL PYSQLITE3,

but still can not be run in my project, will raise an error:

 

erro1.thumb.png.f0229dfa625ef4a7c86d6cedb2df9b13.png

 

could not find cudnn_adv_infer64_8.dll or one of its dependent file

 

the cudnn_adv_infer64_8.dll and all of its dependent files are existing 

 

erro2.thumb.png.0b39052e7035dde8f262b2f27f72eb18.png

as i said,  i set 

 

TPythonThread.Py_Begin_Allow_Threads;

 

in my code, and all running are in thread mode, i don't know if the Python path is lost in thread mode

Edited by tomye

Share this post


Link to post
17 hours ago, tomye said:

as i said,  i set 

 

TPythonThread.Py_Begin_Allow_Threads;

Why are you making things complicated?  Follow the KISS rule.   Using threads in this way requires deep knowledge of the Python API and the complexities of GIL.

 

If do have to use threads, please study Demo  11  and the related posts in this forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net)  

Edited by pyscripter

Share this post


Link to post
15 hours ago, pyscripter said:

Why are you making things complicated?  Follow the KISS rule.   Using threads in this way requires deep knowledge of the Python API and the complexities of GIL.

 

If do have to use threads, please study Demo  11  and the related posts in this forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net)  

 

I don't want it to be that complicated either, but Python's performance is too low

 

if i don't use thread to run , the speed and GPU useage % as below:

 

p1.thumb.png.102de2694a4b0f1a54ab69d28e771f69.png

 

if i lanuch 2 threads :

 

p2.thumb.png.dbb996a39a96854daeb4e534ba13b74e.png

 

if i lanuch 3 threads:

 

p3.thumb.png.4103e9178d0a044f5fb4657071abc972.png

 

single fps will be reduced but Avg fps will be raised if i use 3 threads

 

so this is only way i can figure out to up the speed. 😞

 

acutally, i have finished the thread mode program running in the past months

 

but recently, i changed the AI engine from ONNX to TORCH, after installed pytorch

 

everything becomes unsteady, but if i switch the pythone envirnoment to old path

 

everything comes back , very steady.  i feel the issue comes from CUDA apis and CUDA envirnoment

 

but i still can not find it out, so come here for help .  😞

 

 

 

 

Edited by tomye

Share this post


Link to post

Running python in threads does not increase python code speed due to the GIL.  Only one thread executes at any point in time.  Torch can do its own mutli-threading so again there is no need to use threads.    The main reason for using python threads is to avoid blocking the UI.

Share this post


Link to post
12 hours ago, pyscripter said:

Running python in threads does not increase python code speed due to the GIL.  Only one thread executes at any point in time.  Torch can do its own mutli-threading so again there is no need to use threads.    The main reason for using python threads is to avoid blocking the UI.

 

Yes, Torch is much better than onnx, i have tested.

 

yesterday, i droped the thread mode and create a new project without thread mode

 

but still got this error:

 

erro1.thumb.png.95fa8b93877102ecffd6971183b38a8b.png

 

very strange, if i run the onnx script first and then run the torch script , then will get this error ,

 

but if i run the torch script first and then run the onnx script , all are ok

 

i think it should be an old version of CUDA dlls is called if the onnx script runs first and torch does not support this version

 

but the onnxruntime supports the high version which the torch is used, that's why if i run the torch script first everything is ok. 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×