Has anyone PyInstaller working for Spacy with CUDA? #10153
-
As it is, using PyInstaller with Spacy is not that difficult. That is, unless you need to have import spacy_legacy, which is not handled by contributed hook-spacy.py. It gets harder when you want to use transformers. Again, a custom hook-transformers.py can be used to import another 8 modules or so. Has anyone used PyInstaller to build Spacy executable with CUDA support? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hi! I don't think any of us have immediate experience with this. Maybe it would be worth asking the Pyinstaller community? |
Beta Was this translation helpful? Give feedback.
-
I just managed to get it all work – with my Spacy 3.1 and NVIDIA CUDA 11.5.
I will post the details (hook-spacy.py, hook-treansformers.py, hook-cupy.py) but right now have to deal with some medical.
The trick is (among others) installing the _right_ combination of torch+cudannn, doing pip install is not enough, one MUST uninstall the ‘wrong’ versions repeatedly.
Martin
|
Beta Was this translation helpful? Give feedback.
-
Here are the details of how I managed to get it to work. Note that it may not work for you, because your venv may already contain some conflicting modules/versions. Neither is it a good 'pythonic' example. My environment:
Most important is getting the 'right' combination of torch and cupy. My CUDA is 11.5 (NVIDIA did not give me much choice - the older releases seem to be well hidden). In my venv, I had to REPATEDLY uninstall any 'not so current versions' of torch and cupy. Note I started with cupy-cuda114 which was not 'right':
Then, when using PyInstaller (the most recent version), I had to add the following hooks. Note PyInstaller comes with a huge lists of hooks, including one for Spacy - but when you add your own, it uses them both. Hooks go into hooks directory specified on command line (default is ./)l
|
Beta Was this translation helpful? Give feedback.
-
Maybe including CUDA dlls in the dist folder of the generated exe could also solve the issue. See these Github issues on the pyinstaller repo: |
Beta Was this translation helpful? Give feedback.
Here are the details of how I managed to get it to work. Note that it may not work for you, because your venv may already contain some conflicting modules/versions. Neither is it a good 'pythonic' example.
Note the final distribution using transformers is a monster - 7.7 GB (including en_core_web_trn and _lg). I gave up on using PyInstaller option --onefile because building the archive takes forever (and so does the first invocation). Besides, my distribution needs some other files, so using --onedir and then zip-ing it is far more convenient and faster.
My environment: