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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i patch the torch.jit in the second solution? Could not figure out entrypoint ? #89386

Open
Mindtrip-Inno opened this issue Nov 20, 2022 · 1 comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue

Comments

@Mindtrip-Inno
Copy link

Mindtrip-Inno commented Nov 20, 2022

    Here are the workarounds I found to make things work.

Solution 1: patch torchvision 0.2.2 (dirty and painful)

Pyinstaller works well with torchvision 0.2.2, thus if you do not use too many functionnalities of more recent version of torchvision, you can "patch" old torchvision 0.2.2 by adding the needed new tools. Note that this may need you first use compiled file of torchvision >= 3.0 (_C.so).

Solution 2: Keep recent torchvision & patch torch.jit in your entry point

I found some monkey patch on stackoverflow and dev blogs that simply overwrite 2 methods of torch.jit.
Simply add this path at the beginning of your entry point:

def script_method(fn, _rcb=None):
    return fn
def script(obj, optimize=True, _frames_up=0, _rcb=None):
    return obj    
import torch.jit
torch.jit.script_method = script_method 
torch.jit.script = script

I still think there should be a more direct way to do that with pyinstaller, but this works for me.
I hope it will help others too.

Originally posted by @Sstrap in pytorch/vision#1899 (comment)

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel

@Mindtrip-Inno Mindtrip-Inno changed the title How can i patch the torch.jit in the solution? Could not figure out entrypoint ? How can i patch the torch.jit in the second solution? Could not figure out entrypoint ? Nov 20, 2022
@samdow samdow added the oncall: jit Add this issue/PR to JIT oncall triage queue label Nov 21, 2022
@SMAntony
Copy link

SMAntony commented Feb 22, 2024

If I am not wrong, entry point is the file which you use to compile a exe. For example: pyinstaller "main.py" --onefile. Hope this helps.

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
None yet
Development

No branches or pull requests

3 participants