question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not found error for torch_sparse::ptr2ind in torchscript

See original GitHub issue

❓ Questions & Help

I tried to use pytorch model with MessagePassing layer in C++ code. As described in pytorch_geometric documentation, I generate torch model with my own MP layer and successfully convert the model.

But in the process of executing C++ code, I face the error like below:

Unknown builtin op: torch_sparse::ptr2ind.
Could not find any similar ops to torch_sparse::ptr2ind. This op may not exist or may not be currently supported in TorchScript.
:
  File "/home/sr6/kyuhyun9.lee/env_ML/lib/python3.6/site-packages/torch_sparse/storage.py", line 166
        rowptr = self._rowptr
        if rowptr is not None:
            row = torch.ops.torch_sparse.ptr2ind(rowptr, self._col.numel())
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
            self._row = row
            return row
Serialized   File "code/__torch__/torch_sparse/storage.py", line 825
      if torch.__isnot__(rowptr, None):
        rowptr13 = unchecked_cast(Tensor, rowptr)
        row15 = ops.torch_sparse.ptr2ind(rowptr13, torch.numel(self._col))
                ~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        self._row = row15
        _150, _151 = True, row15
'SparseStorage.row' is being compiled since it was called from 'SparseStorage.__init__'
  File "/home/sr6/kyuhyun9.lee/env_ML/lib/python3.6/site-packages/torch_sparse/storage.py", line 133
        if not is_sorted:
            idx = self._col.new_zeros(self._col.numel() + 1)
            idx[1:] = self._sparse_sizes[1] * self.row() + self._col
                                              ~~~~~~~~ <--- HERE
            if (idx[1:] < idx[:-1]).any():
                perm = idx[1:].argsort()
Serialized   File "code/__torch__/torch_sparse/storage.py", line 267
      idx = torch.new_zeros(self._col, [_29], dtype=None, layout=None, device=None, pin_memory=None)
      _30 = (self._sparse_sizes)[1]
      _31 = torch.add(torch.mul((self).row(), _30), self._col, alpha=1)
                                 ~~~~~~~~~~ <--- HERE
      _32 = torch.slice(idx, 0, 1, 9223372036854775807, 1)
      _33 = torch.copy_(_32, _31, False)
'SparseStorage.__init__' is being compiled since it was called from 'GINLayerJittable_d54f76.__check_input____1'
Serialized   File "code/__torch__/GINLayerJittable_d54f76.py", line 40
      pass
    return the_size
  def __check_input____1(self: __torch__.GINLayerJittable_d54f76.GINLayerJittable_d54f76,
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...  <--- HERE
    edge_index: __torch__.torch_sparse.tensor.SparseTensor,
    size: Optional[Tuple[int, int]]) -> List[Optional[int]]:

Aborted (core dumped)

Since I have no experience of pytorch jit, I cannot find any clue to solve this. How can I handle this error?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:32 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
rusty1scommented, Mar 21, 2022

I finally fixed this issue, both for torch-scatter and torch-sparse:

Finally, I added a fully-working “PyG in C++” example to pytorch_geometric/examples/cpp. This example saves a “jittable” GNN model in Python, and loads and executes it in C++.

Thanks for all the help and sorry that it took me so long to fix 😃 Hope that all issues are now resolved!

1reaction
rusty1scommented, Feb 25, 2022

Thanks for the report and sorry for the delay in fixing this. @mananshah99 and I will look into this ASAP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not found error for torch_sparse::ptr2ind in torchscript #1718
I tried to use pytorch model with MessagePassing layer in C++ code. As described in pytorch_geometric documentation, I generate torch model with ...
Read more >
TorchScript — PyTorch 1.13 documentation
This class errors if not all nodes have been fused in inference, or symbolically differentiated in training. save. Save an offline version of...
Read more >
Error when converting PyTorch model to TorchScript
I just figured out that models loaded from torchvision.models are in train mode by default. AlexNet and SqueezeNet both have Dropout layers, ...
Read more >
Torch Script — PyTorch master documentation - API Manual
Torch Script itself is a subset of the Python language, so not all features in python work ... If there is hard-to-debug error...
Read more >
TorchScript and PyTorch JIT | Deep Dive - YouTube
In this talk, we dive deep into TorchScript and PyTorch JIT.For more information on TorchScript, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found