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

[Type Hints] utils.train_test_split_edges #5737

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

shhs29
Copy link
Contributor

@shhs29 shhs29 commented Oct 16, 2022

I have a question regarding jit script support for utils.train_test_split_edges. I am getting an issue related to circular imports. My full test is also failing on local (Removing this as TorchScript does not support Data). I would appreciate it if anyone has any suggestions to fix this issue.

Traceback (most recent call last):

File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/sphinx/config.py", line 347, in eval_config_file

exec(code, namespace)

File "/home/runner/work/pytorch_geometric/pytorch_geometric/docs/source/conf.py", line 3, in <module>

import torch_geometric

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/__init__.py", line 4, in <module>

import torch_geometric.data

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/__init__.py", line 1, in <module>

from .data import Data

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/data.py", line 22, in <module>

from torch_geometric.data.feature_store import (

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/feature_store.py", line 33, in <module>

from torch_geometric.utils.mixin import CastMixin

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/utils/__init__.py", line 37, in <module>

from .train_test_split_edges import train_test_split_edges

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/utils/train_test_split_edges.py", line 6, in <module>

from torch_geometric.data import Data

ImportError: cannot import name 'Data' from partially initialized module 'torch_geometric.data' (most likely due to a circular import) (/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/__init__.py)


RuntimeError:
E           Arguments for call are not valid.
E           The following variants are available:
E
E             aten::__contains__.int_list(int[] l, int item) -> (bool):
E             Expected a value of type 'List[int]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             aten::__contains__.str_list(str[] l, str item) -> (bool):
E             Expected a value of type 'List[str]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             aten::__contains__.str(Dict(str, t) dict, str key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[str, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.int(Dict(int, t) dict, int key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[int, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.bool(Dict(bool, t) dict, bool key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[bool, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.float(Dict(float, t) dict, float key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[float, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.complex(Dict(complex, t) dict, complex key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[complex, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.Tensor(Dict(Tensor, t) dict, Tensor key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[Tensor, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.float_list(float[] l, float item) -> (bool):
E             Expected a value of type 'List[float]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             __contains__(str self, str key) -> (bool):
E             Expected a value of type 'str' for argument 'self' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'self' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E           The original call is:
E             File "/Users/shwetajacob/Documents/pyg/pytorch_geometric/torch_geometric/deprecation.py", line 38
E               """
E
E               assert 'batch' not in data  # No batch-mode.
E                      ~~~~~~~~~~~~~~~~~~~ <--- HERE
E
E               num_nodes = data.num_nodes

/opt/homebrew/Caskroom/miniforge/base/envs/pyg_dev/lib/python3.9/site-packages/torch/jit/_script.py:1343: RuntimeError

@shhs29 shhs29 changed the title Add type hints for train_test_split_edges [Type Hints] utils.train_test_split_edges Oct 16, 2022
@rusty1s rusty1s marked this pull request as ready for review October 17, 2022 08:07
@rusty1s rusty1s enabled auto-merge (squash) October 17, 2022 08:10
@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Merging #5737 (5e33438) into master (ee09efe) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 5e33438 differs from pull request most recent head 739e03a. Consider uploading reports for the commit 739e03a to get more accurate results

@@           Coverage Diff           @@
##           master    #5737   +/-   ##
=======================================
  Coverage   84.04%   84.04%           
=======================================
  Files         349      349           
  Lines       19318    19320    +2     
=======================================
+ Hits        16236    16238    +2     
  Misses       3082     3082           
Impacted Files Coverage Δ
torch_geometric/utils/train_test_split_edges.py 98.00% <100.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rusty1s rusty1s merged commit 18b0f0d into pyg-team:master Oct 17, 2022
JakubPietrakIntel pushed a commit to JakubPietrakIntel/pytorch_geometric that referenced this pull request Nov 25, 2022
I have a question regarding jit script support for
utils.train_test_split_edges. I am getting an issue related to circular
imports. My full test is also failing on local (Removing this as
TorchScript does not support Data). I would appreciate it if anyone has
any suggestions to fix this issue.
```
Traceback (most recent call last):

File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/sphinx/config.py", line 347, in eval_config_file

exec(code, namespace)

File "/home/runner/work/pytorch_geometric/pytorch_geometric/docs/source/conf.py", line 3, in <module>

import torch_geometric

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/__init__.py", line 4, in <module>

import torch_geometric.data

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/__init__.py", line 1, in <module>

from .data import Data

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/data.py", line 22, in <module>

from torch_geometric.data.feature_store import (

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/feature_store.py", line 33, in <module>

from torch_geometric.utils.mixin import CastMixin

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/utils/__init__.py", line 37, in <module>

from .train_test_split_edges import train_test_split_edges

File "/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/utils/train_test_split_edges.py", line 6, in <module>

from torch_geometric.data import Data

ImportError: cannot import name 'Data' from partially initialized module 'torch_geometric.data' (most likely due to a circular import) (/home/runner/work/pytorch_geometric/pytorch_geometric/torch_geometric/data/__init__.py)

```
```

RuntimeError:
E           Arguments for call are not valid.
E           The following variants are available:
E
E             aten::__contains__.int_list(int[] l, int item) -> (bool):
E             Expected a value of type 'List[int]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             aten::__contains__.str_list(str[] l, str item) -> (bool):
E             Expected a value of type 'List[str]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             aten::__contains__.str(Dict(str, t) dict, str key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[str, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.int(Dict(int, t) dict, int key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[int, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.bool(Dict(bool, t) dict, bool key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[bool, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.float(Dict(float, t) dict, float key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[float, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.complex(Dict(complex, t) dict, complex key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[complex, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.Tensor(Dict(Tensor, t) dict, Tensor key) -> (bool):
E             Could not match type Tensor (inferred) to Dict[Tensor, t] in argument 'dict': Cannot match a dict to Tensor (inferred).
E
E             aten::__contains__.float_list(float[] l, float item) -> (bool):
E             Expected a value of type 'List[float]' for argument 'l' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'l' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E             __contains__(str self, str key) -> (bool):
E             Expected a value of type 'str' for argument 'self' but instead found type 'Tensor (inferred)'.
E             Inferred the value for argument 'self' to be of type 'Tensor' because it was not annotated with an explicit type.
E
E           The original call is:
E             File "/Users/shwetajacob/Documents/pyg/pytorch_geometric/torch_geometric/deprecation.py", line 38
E               """
E
E               assert 'batch' not in data  # No batch-mode.
E                      ~~~~~~~~~~~~~~~~~~~ <--- HERE
E
E               num_nodes = data.num_nodes

/opt/homebrew/Caskroom/miniforge/base/envs/pyg_dev/lib/python3.9/site-packages/torch/jit/_script.py:1343: RuntimeError
```

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants