Skip to content

The conversion of the ANI-2x model to TorchScript fails with PyTorch 1.9 #598

Closed
@raimis

Description

@raimis

The conversion of the ANI-2x model to TorchScript fails with PyTorch 1.9:

import torch
import torchani

print(torch.__version__)
print(torchani.__version__)

torch.jit.script(torchani.models.ANI2x())
$ conda install -c conda-forge pytorch=1.9 torchani
$ python debug.py 
1.9.0
2.2
Traceback (most recent call last):
  File "debug_torchani.py", line 7, in <module>
    torch.jit.script(torchani.models.ANI2x())
  File "/shared/raimis/opt/miniconda/envs/tmp_torchani/lib/python3.8/site-packages/torch/jit/_script.py", line 1096, in script
    return torch.jit._recursive.create_script_module(
  File "/shared/raimis/opt/miniconda/envs/tmp_torchani/lib/python3.8/site-packages/torch/jit/_recursive.py", line 412, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/shared/raimis/opt/miniconda/envs/tmp_torchani/lib/python3.8/site-packages/torch/jit/_recursive.py", line 474, in create_script_module_impl
    script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
  File "/shared/raimis/opt/miniconda/envs/tmp_torchani/lib/python3.8/site-packages/torch/jit/_script.py", line 497, in _construct
    init_fn(script_module)
  File "/shared/raimis/opt/miniconda/envs/tmp_torchani/lib/python3.8/site-packages/torch/jit/_recursive.py", line 437, in init_fn
    cpp_module.setattr(name, orig_value)
RuntimeError: Could not cast attribute 'rev_species' to type Dict[Tensor, int]: Unable to cast Python instance to C++ type (compile in debug mode for details)

But it works with PyTorch 1.8:

$ conda install -c conda-forge pytorch=1.8 torchani
$ python debug.py
1.8.0
2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions