Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packing app with Pyinstaller rises OSError: TorchScript requires source access in order to carry out compilation, make sure original .py files are available. #54828

Closed
giuliodz opened this issue Mar 27, 2021 · 3 comments
Assignees
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects

Comments

@giuliodz
Copy link

giuliodz commented Mar 27, 2021

馃悰 Bug

am trying to create an executable for a flask application that uses haystack to serve a QA System. Haystack uses transformers, and transformers library is built using torch.
If I run my API normally using a python interpreterpython app.py it works fine.
When I pack it with PyInstaller pyinstaller --onedir app.spec --clean --distpath distAPP the executable gets created fine. However, when I run it with ./distAPP/app/app I get the following error:

03/27/2021 11:16:39 - INFO - faiss -   Loading faiss with AVX2 support.
03/27/2021 11:16:39 - INFO - faiss -   Loading faiss.
Traceback (most recent call last):
  File "torch/_utils_internal.py", line 49, in get_source_lines_and_file
  File "inspect.py", line 967, in getsourcelines
  File "inspect.py", line 798, in findsource
OSError: could not get source code
....
....
  File "transformers/models/deberta/modeling_deberta.py", line 462, in <module>
  File "torch/jit/_script.py", line 936, in script
  File "torch/jit/frontend.py", line 197, in get_jit_def
  File "torch/_utils_internal.py", line 56, in get_source_lines_and_file
OSError: Can't get source for <function c2p_dynamic_expand at 0x7fb81c95e3a0>. TorchScript requires source access in order to carry out compilation, make sure original .py files are available.

To Reproduce

You can find a minimal repository that will generate the same error here.
You can clone it (it only includes few light .py files) and follow the instructions in the README.md file. This will take you few seconds to get to work as I made it quite easy and light.

Expected behavior

PyInstaller should be able to get the source code at "torch/_utils_internal.py", but torch is not allowing it. My assumption is torch it is determined to use raw .py files.

Environment

PyTorch version: 1.7.1
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect

Python version: 3.8 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.20.0
[pip3] torch==1.7.1
[conda] blas                      1.0                         mkl  
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py38he904b0f_0  
[conda] mkl_fft                   1.2.0            py38h23d657b_0  
[conda] mkl_random                1.1.1            py38h0573a6f_0  
[conda] numpy                     1.19.2           py38h54aff64_0  
[conda] numpy-base                1.19.2           py38hfa32c7d_0  
[conda] numpydoc                  1.1.0              pyhd3eb1b0_1

cc @gmagogsfm

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 27, 2021
@github-actions github-actions bot added this to Need triage in JIT Triage Mar 27, 2021
@giuliodz
Copy link
Author

This bug has also been posted on the PyInstaller github Issue board, where I show a few changes I did in my PyInstaller .spec file that tried to get the source code manually, but that did not work.

@nikithamalgifb nikithamalgifb self-assigned this Mar 30, 2021
@nikithamalgifb nikithamalgifb moved this from Need triage to In discussion in JIT Triage Mar 30, 2021
@nikithamalgifb
Copy link
Contributor

This looks more like PyInstaller issue rather than a TorchScript issue. Since there is an issue tracking this on the PyInstaller GH board, we do not plan on addressing this for now. Feel free to re-open if this turns out to be an issue with TorchScript.

JIT Triage automation moved this from In discussion to Done Apr 16, 2021
@YacobBY
Copy link

YacobBY commented Jul 19, 2021

Having the same issue using the Nuitka compiler. Nuitka/Nuitka#1160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
JIT Triage
  
Done
Development

No branches or pull requests

4 participants