Skip to content

Instantly share code, notes, and snippets.

@anuradhawick
Created September 3, 2021 00:58
Show Gist options
  • Save anuradhawick/904e7f2d2101f4b76516d04046007426 to your computer and use it in GitHub Desktop.
Save anuradhawick/904e7f2d2101f4b76516d04046007426 to your computer and use it in GitHub Desktop.
SAGE Cora
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wyzhangyuhan
Copy link

When I tried to run your code, the program reported the following error at line class NeighborSampler(RawNeighborSampler):

TypeError                                 Traceback (most recent call last)
[<ipython-input-5-d7579c4a959a>](https://localhost:8080/#) in <module>()
----> 1 class NeighborSampler(RawNeighborSampler):
      2     def sample(self, batch):
      3         batch = torch.tensor(batch)
      4         row, col, _ = self.adj_t.coo()
      5 

TypeError: function() argument 1 must be code, not str

I haven't made any changes to this class or your other code, and the imported package is the same. Google's advice on how to fix this error is also sparse and not very relevant.

Could you please help me to correct this error and run this code correctly?

Your code is very helpful for me to learn GraphSAGE, and I would really appreciate it if you could help me.

@anuradhawick
Copy link
Author

Hi.

This is because the the version of PyTorch Geometric. I may have coded using an older version.

You should be able to find the examples using latest version in their repository. You will see how to use the neighbour sampler with latest version. Unfortunately I cannot provide what changes you need to do as I’m currently busy with other work.

All the best. Feel free to give me an update when you succeed.

Cheers

@Aleksandar1932
Copy link

Aleksandar1932 commented Mar 17, 2022

@wyzhangyuhan

It can be fixed easily by importing from torch_geometric.loader import NeighborSampler as RawNeighborSampler, instead of from torch_geometric.data import NeighborSampler as RawNeighborSampler.

@anuradhawick Can you update your gist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment