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

AttributeError: 'int' object has no attribute 'new_full' #8

Open
firqaaa opened this issue Aug 1, 2022 · 3 comments
Open

AttributeError: 'int' object has no attribute 'new_full' #8

firqaaa opened this issue Aug 1, 2022 · 3 comments

Comments

@firqaaa
Copy link

firqaaa commented Aug 1, 2022

I have tried to run this code in colab, everything fine until i got an error when trying to run main function, here is the details :

Logging to /content/logs/TextGNN_twitter_asian_prejudice_small_0.8_0.1_0.1_2022-07-31T22-02-48.769172
Trying to load but no file /content/save/split/twitter_asian_prejudice_small_train_80_val_10_test_10_seed_3_window_size_10.klepto
Trying to load but no file /content/save/all/twitter_asian_prejudice_small_all_window_10.klepto
100%
1503/1503 [00:00<00:00, 15779.03it/s]
Saving to /content/save/all/twitter_asian_prejudice_small_all_window_10.klepto
Saving to /content/save/split/twitter_asian_prejudice_small_train_80_val_10_test_10_seed_3_window_size_10.klepto
(1183, 1183)
Number params:  237604

AttributeError                            Traceback (most recent call last)
[<ipython-input-22-263240bbee7e>](https://localhost:8080/#) in <module>()
----> 1 main()

9 frames
[<ipython-input-21-6463f33e79c1>](https://localhost:8080/#) in main()
     10     if COMET_EXPERIMENT:
     11         with COMET_EXPERIMENT.train():
---> 12             saved_model, model = train(train_data, val_data, saver)
     13     else:
     14         saved_model, model = train(train_data, val_data, saver)

[<ipython-input-18-4c4921548f33>](https://localhost:8080/#) in train(train_data, val_data, saver)
     18         model.train()
     19         model.zero_grad()
---> 20         loss, preds_train = model(pyg_graph, train_data)
     21         loss.backward()
     22         optimizer.step()

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1128         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1129                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1130             return forward_call(*input, **kwargs)
   1131         # Do not call functions when jit is used
   1132         full_backward_hooks, non_full_backward_hooks = [], []

[<ipython-input-14-a3723756fb22>](https://localhost:8080/#) in forward(self, pyg_graph, dataset)
     31         for i, layer in enumerate(self.layers):
     32             ins = acts[-1]
---> 33             outs = layer(ins, pyg_graph)
     34             acts.append(outs)
     35 

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1128         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1129                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1130             return forward_call(*input, **kwargs)
   1131         # Do not call functions when jit is used
   1132         full_backward_hooks, non_full_backward_hooks = [], []

[<ipython-input-14-a3723756fb22>](https://localhost:8080/#) in forward(self, ins, pyg_graph)
    101                 x = self.conv(ins, pyg_graph.edge_index, edge_weight=pyg_graph.edge_attr)
    102             else:
--> 103                 x = self.conv(ins, pyg_graph.edge_index)
    104         else:
    105             x = self.conv(ins, pyg_graph.edge_index)

[/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in _call_impl(self, *input, **kwargs)
   1128         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1129                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1130             return forward_call(*input, **kwargs)
   1131         # Do not call functions when jit is used
   1132         full_backward_hooks, non_full_backward_hooks = [], []

[<ipython-input-14-a3723756fb22>](https://localhost:8080/#) in forward(self, x, edge_index, edge_weight)
    254         if not self.cached or self.cached_result is None:
    255             edge_index, norm = GCNConv.norm(edge_index, x.size(0), edge_weight,
--> 256                                             self.improved, x.dtype)
    257             self.cached_result = edge_index, norm
    258 

[<ipython-input-14-a3723756fb22>](https://localhost:8080/#) in norm(edge_index, num_nodes, edge_weight, improved, dtype)
    231 
    232         edge_index, edge_weight = remove_self_loops(edge_index, edge_weight)
--> 233         edge_index = add_self_loops(edge_index, num_nodes)
    234         loop_weight = torch.full((num_nodes, ),
    235                                  1 if not improved else 2,

[/usr/local/lib/python3.7/dist-packages/torch_geometric/utils/loop.py](https://localhost:8080/#) in add_self_loops(edge_index, edge_attr, fill_value, num_nodes)
    123     if edge_attr is not None:
    124         if fill_value is None:
--> 125             loop_attr = edge_attr.new_full((N, ) + edge_attr.size()[1:], 1.)
    126 
    127         elif isinstance(fill_value, (int, float)):

AttributeError: 'int' object has no attribute 'new_full'

Why this can happen? can you give me a solution?

@NageshMashette
Copy link

can anyone give the solution, facing same issue here aswell.

@zhuluchangfeng
Copy link

in norm(edge_index, num_nodes, edge_weight, improved, dtype)
231
232 edge_index, edge_weight = remove_self_loops(edge_index, edge_weight)
--> 233 edge_index = add_self_loops(edge_index, num_nodes)
234 loop_weight = torch.full((num_nodes, ),
235 1 if not improved else 2,

233行这里改成edge_index = add_self_loops(edge_index, num_nodes=num_nodes),这里是因为num_nodes没有传递到合适的位置

@slefcourt27
Copy link

slefcourt27 commented Jan 10, 2024

For others, make sure to install the libraries in this way: https://gist.github.com/ameya98/b193856171d11d37ada46458f60e73e7

To solve this problem, specify
edge_index, _ = add_self_loops(edge_index=edge_index, num_nodes=num_nodes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants