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

torch.jit.script PyG models #346

Open
klieret opened this issue Jun 28, 2023 · 8 comments · Fixed by #380
Open

torch.jit.script PyG models #346

klieret opened this issue Jun 28, 2023 · 8 comments · Fixed by #380
Assignees
Labels
comp: model objective: speed Affecting training speed

Comments

@klieret
Copy link
Member

klieret commented Jun 28, 2023

Javier did it to old IN model

@klieret klieret added objective: speed Affecting training speed comp: model labels Jun 28, 2023
@jmduarte
Copy link

If you want to assign to me, I can give it a shot :)

@klieret
Copy link
Member Author

klieret commented Jun 30, 2023

Sounds great! It seems like we can essentially do it after the model definition and just in the training class?

For future reference, this is your commit from the old repo.

@klieret
Copy link
Member Author

klieret commented Jun 30, 2023

So essentially we might just modify this single line here and do

self.model = torch.jit.script( ...)

@klieret
Copy link
Member Author

klieret commented Jul 3, 2023

I tried that very lazily and got

Module 'InteractionNetwork' has no attribute 'inspector' (This attribute exists on the Python module, but we failed to convert Python type: 'torch_geometric.nn.conv.utils.inspector.Inspector' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type Inspector.. Its type was inferred; try adding a type annotation for the attribute.):

so there might be some things to be sorted out.

So essentially we might just modify this single line here and do

Or instead, we could simply JIT the interaction network step itself somewhere (because that's a much simpler object than the compound models built from INs)

@klieret klieret mentioned this issue Jul 28, 2023
@klieret
Copy link
Member Author

klieret commented Jul 28, 2023

I jit compiled the MLPs within the IN for now (which works out of the box), so hopefully that already gives us some boost.

@klieret
Copy link
Member Author

klieret commented Jul 28, 2023

This is the message if I try to just jit the whole IN:

Module 'InteractionNetwork' has no attribute 'inspector' (This attribute exists on the Python module, but we failed to convert Python type: 'torch_geometric.nn.conv.utils.inspector.Inspector' to a TorchScript type. Only tensors and (possibly nested) tuples of tensors, lists, or dictsare supported as inputs or outputs of traced functions, but instead got value of type Inspector.. Its type was inferred; try adding a type annotation for the attribute.):
  File "/scratch/gpfs/kl5675/micromamba/envs/gnn/lib/python3.10/site-packages/torch_geometric/nn/conv/message_passing.py", line 564

        self._explain = explain
        self.inspector.inspect(self.explain_message, pop_first=True)
        ~~~~~~~~~~~~~~ <--- HERE
        self._user_args = self.inspector.keys(methods).difference(
            self.special_args)

didn't look into this more

@klieret
Copy link
Member Author

klieret commented Sep 29, 2023

I think pytorch no longer works on jit.script/jit.trace. The new way seems to be jit.compile:

https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html#torch-compile-tutorial

@klieret
Copy link
Member Author

klieret commented Sep 29, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: model objective: speed Affecting training speed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants