Open WGDMS opened 2 years ago
Which could do you try to run? With PyG>=2.0, there was a change in the expected input arguments of data.__inc__
and data.__cat_dim__` (which now expect four arguments rather than three). This is documented here. You can easily fix this by adjusting the function headers to:
def __cat_dim__(self, key, value, *args, **kwargs):
pass
def __inc__(self, key, value, *args, **kwargs):
pass
I am using
pyg>=2.0.5
torch =1.10.0
Python = 3.7.11
OS: Linux
And I am still getting this error.
Pair data is what data contains and i have created sub_g as subgraph from whole graph.
PairData(x=[200, 52], y=[1], pos=[200, 2], sub_g=[16, 50, 52], edge_index=[2, 1335], patch_idx=[1])
PairData(x=[296, 52], y=[1], pos=[296, 2], sub_g=[16, 50, 52], edge_index=[2, 2138], patch_idx=[1])
PairData(x=[279, 52], y=[1], pos=[279, 2], sub_g=[16, 50, 52], edge_index=[2, 2021], patch_idx=[1])
Traceback (most recent call last):
File "train.py", line 491, in
I have checked def __cat_dim and def inc__ as similar in the newer version as you have described above but still getting this error. Any solution?
Did you apply the above suggestion?
def __cat_dim__(self, key, value, *args, **kwargs):
pass
def __inc__(self, key, value, *args, **kwargs):
pass
Yes, In the newer version it already as it is mentioned by you. What other reason could be for this error, is this related to the version or related to the dataset?
I'm not sure which code you are running. But if you changed it as it is mentioned above, you may need to ensure to re-install the package such that the modifications are taken into account.
I'm not sure which code you are running. But if you changed it as it is mentioned above, you may need to ensure to re-install the package such that the modifications are taken into account.
Hi! Thanks so much for your help! But could please provide more details on how to re-install the package?
Do you see the same error? Does adjusting the __cat_dim__
and __inc__
properties as mentioned here not help? You can re-install the package via
pip install --upgrade torch-geometric
Do you see the same error? Does adjusting the
__cat_dim__
and__inc__
properties as mentioned here not help? You can re-install the package viapip install --upgrade torch-geometric
Thanks so much for your reply! But if do so, new problems occur shown as below. This problem is not accidental that I encountered it every time I did the operation you mentioned when dealing with several different projects. Could you please give me some tips about that? Really appreciate it!
env/lib/python3.8/site-packages/torch_geometric/data/separate.py", line 65, in _separate value = value.narrow(cat_dim or 0, start, end - start) IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 43204744)
Is it possible for you to share some of the data
objects with a small reproducible script? I am sure the error is easy to solve.
@rusty1s Thanks so much for your reply! Could you please provide me with an email, so that I can share some files?
At best, you can share the link here so others can chime in as well. Alternatively, you can find my mail on my github profile.
data.txt This is my current data.py file from env/lib/python3.8/site-packages/torch_geometric/data/data.py. I modified the original code from lines 502 - 516.
Oh, it looks like there is some mis-understanding. You do not need to modify the PyG source code (which will in fact result in breaking PyG) - instead, there seems to exist a data
object in your code that inherits from torch_geometric.data.Data
and which re-implements the __cat_dim__
and __inc__
interface. Simply changing these functions to the new function headers
def __cat_dim__(self, key, value, *args, **kwargs):
def __inc__(self, key, value, *args, **kwargs):
should resolve this.
Cool! I will try it out! Thanks so much!!!
On Wed, Sep 7, 2022 at 1:48 AM Matthias Fey @.***> wrote:
Oh, it looks like there is some mis-understanding. You do not need to modify the PyG source code (and will in fact result in breaking PyG) - instead, there seems to be a data object in your code that inherits from torch_geometric.data.Data and which re-implements the __cat_dim and inc__ interface. Simply changing these functions to the new function headers
def __cat_dim(self, key, value, *args, **kwargs):def inc__(self, key, value, *args, **kwargs):
should resolve this.
— Reply to this email directly, view it on GitHub https://github.com/pyg-team/pytorch_geometric/issues/4358#issuecomment-1238934670, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARSRTYYBIR3BIMDDR6FT3JDV5AUEBANCNFSM5RYUEXWQ . You are receiving this because you commented.Message ID: @.***>
In PyG version 2.3, the solution mentioned before doesn't work. However, I solve the problem by arrange the input of the function inc in the collate.py file.
The relative of the function I modified is as follows: anaconda3/envs/${your env name}/lib/python3.9/site-pacakages/torch_geometric/data/collate.py/get_incs
def get_incs(key, values: List[Any], data_list: List[BaseData]), stores: List[BaseStorage]) -> Tensor: """
repeats = [
data.__inc__(key, value, store)
for value, data, store in zip(values, data_list, stores)
]
"""
### modified version, while may cause other problems we do not expect currently
repeats = [
data.__inc__(key, value)
for value, data, store in zip(values, data_list, stores)
]
...
return cumsum(repeats[:-1])
my environment details: python=3.9 torch=1.13.1 + cu116 torch-geometric=2.3
Hope this can help you
Thank you @sirlddf, this problem has been bothering me for a long time, and I finally managed to solve it by using your method.
In PyG version 2.3, the solution mentioned before doesn't work. However, I solve the problem by arrange the input of the function inc in the collate.py file.
The relative of the function I modified is as follows: anaconda3/envs/${your env name}/lib/python3.9/site-pacakages/torch_geometric/data/collate.py/get_incs
def get_incs(key, values: List[Any], data_list: List[BaseData]), stores: List[BaseStorage]) -> Tensor: """ ### original version which will cause TypeError... repeats = [ data.inc(key, value, store) for value, data, store in zip(values, data_list, stores) ] """ ### modified version, while may cause other problems we do not expect currently repeats = [ data.inc(key, value) for value, data, store in zip(values, data_list, stores) ] ... return cumsum(repeats[:-1])
my environment details: python=3.9 torch=1.13.1 + cu116 torch-geometric=2.3
Hope this can help you
It works, thank you.
In PyG version 2.3, the solution mentioned before doesn't work. However, I solve the problem by arrange the input of the function inc in the collate.py file.
The relative of the function I modified is as follows: anaconda3/envs/${your env name}/lib/python3.9/site-pacakages/torch_geometric/data/collate.py/get_incs
def get_incs(key, values: List[Any], data_list: List[BaseData]), stores: List[BaseStorage]) -> Tensor: """ ### original version which will cause TypeError... repeats = [ data.inc(key, value, store) for value, data, store in zip(values, data_list, stores) ] """ ### modified version, while may cause other problems we do not expect currently repeats = [ data.inc(key, value) for value, data, store in zip(values, data_list, stores) ] ... return cumsum(repeats[:-1])
my environment details: python=3.9 torch=1.13.1 + cu116 torch-geometric=2.3
Hope this can help you
It works!!!Thank you very much!!
In PyG version 2.3, the solution mentioned before doesn't work. However, I solve the problem by arrange the input of the function inc in the collate.py file.
The relative of the function I modified is as follows: anaconda3/envs/${your env name}/lib/python3.9/site-pacakages/torch_geometric/data/collate.py/get_incs
def get_incs(key, values: List[Any], data_list: List[BaseData]), stores: List[BaseStorage]) -> Tensor: """ ### original version which will cause TypeError... repeats = [ data.inc(key, value, store) for value, data, store in zip(values, data_list, stores) ] """ ### modified version, while may cause other problems we do not expect currently repeats = [ data.inc(key, value) for value, data, store in zip(values, data_list, stores) ] ... return cumsum(repeats[:-1])
my environment details: python=3.9 torch=1.13.1 + cu116 torch-geometric=2.3
Hope this can help you
I solved the problem sucessfully, thx!!!
😵 Describe the installation problem
Dear Team: I received the following error. Hope that it is a version problem.
---> 19 run_classification(train_dataset, val_dataset, test_dataset, model, num_tasks, epochs, batch_size, vt_batch_size, lr, lr_decay_factor, lr_decay_step_size, weight_decay, early_stopping, loss, metric, log_dir, save_dir,True)
10 frames /usr/local/lib/python3.7/dist-packages/torch_geometric/data/collate.py in(.0)
223 repeats = [
224 data.inc(key, value, store)
--> 225 for value, data, store in zip(values, data_list, stores)
226 ]
227 if isinstance(repeats[0], Tensor):
TypeError: inc() takes 3 positional arguments but 4 were given
Please help me to solve this.
Environment
conda
,pip
, source): !pip install torch torch-scatter torch-sparse torch-cluster torch-spline-conv torchaudio torch-geometric -f https://data.pyg.org/whl/torch-1.10.0+cu111.htmltorch-scatter
):