Geometric Deep Learning Extension Library for PyTorch

Overview


PyPI Version Build Status Docs Status Code Coverage Contributing Slack

Documentation | Paper | Colab Notebooks | External Resources | OGB Examples

PyTorch Geometric (PyG) is a geometric deep learning extension library for PyTorch.

It consists of various methods for deep learning on graphs and other irregular structures, also known as geometric deep learning, from a variety of published papers. In addition, it consists of an easy-to-use mini-batch loader for many small and single giant graphs, multi gpu-support, a large number of common benchmark datasets (based on simple interfaces to create your own), and helpful transforms, both for learning on arbitrary graphs as well as on 3D meshes or point clouds. Click here to join our Slack community!


PyTorch Geometric makes implementing Graph Neural Networks a breeze (see here for the accompanying tutorial). For example, this is all it takes to implement the edge convolutional layer:

import torch
from torch.nn import Sequential as Seq, Linear as Lin, ReLU
from torch_geometric.nn import MessagePassing

class EdgeConv(MessagePassing):
    def __init__(self, F_in, F_out):
        super(EdgeConv, self).__init__(aggr='max')  # "Max" aggregation.
        self.mlp = Seq(Lin(2 * F_in, F_out), ReLU(), Lin(F_out, F_out))

    def forward(self, x, edge_index):
        # x has shape [N, F_in]
        # edge_index has shape [2, E]
        return self.propagate(edge_index, x=x)  # shape [N, F_out]

    def message(self, x_i, x_j):
        # x_i has shape [E, F_in]
        # x_j has shape [E, F_in]
        edge_features = torch.cat([x_i, x_j - x_i], dim=1)  # shape [E, 2 * F_in]
        return self.mlp(edge_features)  # shape [E, F_out]

In detail, the following methods are currently implemented:


Head over to our documentation to find out more about installation, data handling, creation of datasets and a full list of implemented methods, transforms, and datasets. For a quick start, check out our examples in the examples/ directory.

If you notice anything unexpected, please open an issue and let us know. If you have any questions or are missing a specific feature, feel free to discuss them with us. We are motivated to constantly make PyTorch Geometric even better.

Installation

We provide pip wheels for all major OS/PyTorch/CUDA combinations, see here.

PyTorch 1.8.0

To install the binaries for PyTorch 1.8.0, simply run

$ pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+${CUDA}.html
$ pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+${CUDA}.html
$ pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+${CUDA}.html
$ pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+${CUDA}.html
$ pip install torch-geometric

where ${CUDA} should be replaced by either cpu, cu101, cu102, or cu111 depending on your PyTorch installation.

cpu cu101 cu102 cu111
Linux
Windows
macOS

PyTorch 1.7.0/1.7.1

To install the binaries for PyTorch 1.7.0 and 1.7.1, simply run

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+${CUDA}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+${CUDA}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.7.0+${CUDA}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.7.0+${CUDA}.html
pip install torch-geometric

where ${CUDA} should be replaced by either cpu, cu92, cu101, cu102, or cu110 depending on your PyTorch installation.

cpu cu92 cu101 cu102 cu110
Linux
Windows
macOS

Note: Binaries of older versions are also provided for PyTorch 1.4.0, PyTorch 1.5.0 and PyTorch 1.6.0 (following the same procedure).

From master

In case you want to experiment with the latest PyG features which did not get released yet, you can install PyG from master via

pip install git+https://github.com/rusty1s/pytorch_geometric.git

Running examples

cd examples
python gcn.py

Cite

Please cite our paper (and the respective papers of the methods used) if you use this code in your own work:

@inproceedings{Fey/Lenssen/2019,
  title={Fast Graph Representation Learning with {PyTorch Geometric}},
  author={Fey, Matthias and Lenssen, Jan E.},
  booktitle={ICLR Workshop on Representation Learning on Graphs and Manifolds},
  year={2019},
}

Feel free to email us if you wish your work to be listed in the external resources.

Running tests

python setup.py test
Comments
  • Issue reproducing the results of the original ecc implementation. Pooling layer and conv layer are giving different results of the original implementation

    Issue reproducing the results of the original ecc implementation. Pooling layer and conv layer are giving different results of the original implementation

    As I mentioned in #319 I have problems to reproduce the ecc implemenation using pytorch_geometric. I found some differences between the results obtained, first one is that the results of both convolution operations using the same weights have different results. Moreover, the results of the pooling layers are also different.

    I created a test that checks this things. Basically, the scripts load the same weights to both implementations. These weights are obtained from train a network using the ecc_implementation. Below you can see the output of my test.

    ECC Weights and PyGeometric weights are equal: True #I am only doing a re-check in order to be sure that both weights are equal before to load to the models.
    Loading weights 
    Starting validation:
    ecc features conv1:  (997, 16) #Shape of the output of first conv in ecc implementation
    pygeometric features conv1:  (997, 16) #Shape of the output of first conv in pygeometric implementation
    Max difference between features of first conv 2.549824
    Output of ecc pooling:  (398, 32)
    Output of PyGeometric pooling:  (385, 32)
    Pygeomtric Acc:  41.51982378854625  Ecc accuracy:  63.65638766519823
    Pygeomtric Loss:  2.435516586519023  Ecc Loss:  0.9878960176974138
    

    As you can observe this difference has an impact to the accuracy using the same weights. You can find the source code here. One important thing, the data used for this tests is obtained from the original code of the ecc.

    opened by dhorka 93
  • Not found error for torch_sparse::ptr2ind in torchscript

    Not found error for torch_sparse::ptr2ind in torchscript

    ❓ 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?

    bug feature help wanted 
    opened by Nanco-L 32
  • Segmentation Fault in Forward Loop of Edge Conv

    Segmentation Fault in Forward Loop of Edge Conv

    Hey there!

    I'm testing out edge conv and am running into some issues. I'm getting a segmentation fault during the knn_graph generation:

    line 13: 14361 Segmentation fault      (core dumped) CUDA_VISIBLE_DEVICES="$gpuNum" python ...
    

    Here's output using pysnooper, I traced the error to this location:

    Starting var:.. batch = None
    Starting var:.. pos = tensor([[-3.1472e-01, -7.1309e-01, -1.5181e-01,  1.3493e+00,  1.0879e+00,          4.9691e-01, -1.54...
    Starting var:.. self = Net(  (conv1): EdgeConv(nn=Sequential(    (0): Linear(in_features=50, out_features=64, bias=True)   ...
    17:39:03.629809 call        41  def forward(self, pos, batch):
    17:39:03.680347 line        42          edge_index = knn_graph(pos, k=20, batch=batch)
    ~
    

    Last line is where error is happening.

    As more context, I'm generating my point cloud using a CNN, batch and positions are shown above, cannot seem to make it through the generation of the edge index.

    Can you please help me out here?

    opened by jlevy44 31
  • Data Batch problem in PyG

    Data Batch problem in PyG

    🐛 Describe the bug

    Hi. I am a computational physics researcher and was using PyG very well. my pyg code was working well a few weeks ago, but now that I run my code, it is not working anymore without any changes.

    the problem is like below. I have many material structures and in my "custom_dataset" class, these are preprocessed and all graph informations (node features, edge features, edge index etc) are inserted into "Data" object in PyTorch geometric. You can see that each preprocessed sample with index $i$ was printed normal "Data" object in pyg

    캡처2

    But When I insert my custom dataset class into pyg DataLoader and I did like below,

    sample = next(iter(train_loader)) # batch sample
    

    batch sample is denoted by "DataDataBatch". I didn't see this kind of object name. and i can't use "sample.x' or "sample.edge_index" command. Instead I need to do like this

    캡처3

    I want to use expressions like "sample.x", "sample.edge_index" or "sample.edge_attr" as like before. I expect your kind explanations. Thank you.

    Environment

    • PyG version: 2.0.5
    • PyTorch version: 1.11.0+cu113
    • OS: GoogleColab Pro Plus
    • Python version: Python 3.7.13 in colab
    • CUDA/cuDNN version:
    • How you installed PyTorch and PyG (conda, pip, source):
    # Install required packages.
    import os
    import torch
    os.environ['TORCH'] = torch.__version__
    print(torch.__version__)
    !pip install -q torch-scatter -f https://data.pyg.org/whl/torch-${TORCH}.html
    !pip install -q torch-sparse -f https://data.pyg.org/whl/torch-${TORCH}.html
    !pip install -q git+https://github.com/pyg-team/pytorch_geometric.git
    !pip install -q pymatgen==2020.11.11  
    
    • Any other relevant information (e.g., version of torch-scatter):
    bug 
    opened by Amadeus-System 29
  • Link-level `NeighborLoader`

    Link-level `NeighborLoader`

    🚀 The feature, motivation and pitch

    Currently, NeighborLoader is designed to be applied in node-level tasks and there exists no option for mini-batching in link-level tasks.

    To achieve this, users currently rely on a simple but hacky workaround, first utilized in ogbl-citation2 in this example.

    The idea is straightforward and simple: For input_nodes, we pass in both the source and destination nodes for every link we want to do link prediction on (both positive and negative):

    loader = NeighborLoader(data, input_nodes=edge_label_index.view(-1), ...)
    

    Nonetheless, PyG should provide a dedicated class to perform mini-batch on link-level tasks, re-using functionality from NeighborLoader under-the-hood. An API could look like:

    class LinkLevelNeighborLoader(
        data,
         input_edges=...
         input_edge_labels=...
         with_negative_sampling=True,
         **kwargs,
    )
    

    NOTE: This workaround currently only works for homogenous graphs!

    @RexYing @JiaxuanYou

    feature 0 - Priority P0 
    opened by rusty1s 28
  • [WIP] MessagePassing.jittable()

    [WIP] MessagePassing.jittable()

    This is a new feature pursuant to issue #997.

    Difficulty -> the MessagePassing base class is highly dynamic (and really useful) and relies heavily on kwargs parsing to do its job. This means that it is manifestly not jittable, resulting in having to duplicate models and code outside of PyG if you want to run these models as a service (on nVidia TRITON or similar).

    However, once a convolutional operation is written and input/output widths are defined its control flow is known. Therefore you can synthesize a concrete implementation of the control flow from the user's written model and an appropriate adaptation of the propagate() function of the MessagePassing base class. This is achieved using object inheritance and dynamic loading of python modules based on synthesized code.

    This use of this functionality proceeds right now as follows:

    1. write your convolution op (MyConvOp)+ some model (MyNet) that uses it
    2. instead of self.conv1 = MyConvOp(params) you do:
         conv1_class = MyConvOp(params).jittable(args_to_forward)
         self.conv1 = conv1_class(params)
      

      where args_to_forward are the parameters you would normally pass to forward.

    3. model = torch.jit.script(MyNet())

    I would like to make it so that 2 works without needing example data, but it was the simplest way to implement a partial trace.

    This PR is functional and tests for all existing conv models are being extended to include jitting tests. So far each conv layer has needed a little tweaking to make it jit compatible, typically just adding a few type annotations. Occasionally some more type-static code needs to be re-written in the layer.

    Checklist of conv layers tested for with jitting functionality in CI:

    • [x] Basic test in test/nn/conv/test_message_passing.py
    • [x] AGNNConv
    • [x] APPNP
    • [ ] ARMAConv
    • [x] CGConv
    • [x] ChebConv
    • [x] DNAConv
    • [x] EdgeConv
    • [ ] DynamicEdgeConv - NB: this needs to wait on https://github.com/rusty1s/pytorch_cluster/pull/42
    • [x] FeaStConv
    • [x] GATConv
    • [x] GatedGraphConv
    • [x] GCNConv
    • [x] GINConv
    • [x] GINEConv
    • [x] GMMConv
    • [x] GraphConv
    • [ ] GravNetConv - NB: this needs to wait on https://github.com/rusty1s/pytorch_cluster/pull/42
    • [ ] HypergraphConv
    • [x] NNConv
    • [x] PointConv
    • [x] PPFConv
    • [x] RGCNConv
    • [x] SAGEConv
    • [x] SGConv
    • [x] SignedConv
    • [x] SplineConv
    • [x] TAGConv
    • [ ] XConv - NB: this needs to wait on https://github.com/rusty1s/pytorch_cluster/pull/42
    opened by lgray 28
  • Can not install torch-scatter using 'conda install'

    Can not install torch-scatter using 'conda install'

    📚 Installation

    I am able to install torch-scatter using 'pip3 install torch-scatter'.

    But it failed when I use 'conda install torch-scatter' and 'pip install torch-scatter'

    By using pip3, I cannot install torch-scatter to my anaconda3 environment. Then, when I run the examples/code, I aways get 'PackagesNotFoundError' for torch-scatter

    Environment

    • OS: macOS
    • Python version: 10.14.5
    • PyTorch version: 1.1.0
    • CUDA/cuDNN version: NO
    • GCC version: 4.2.1
    • How did you try to install PyTorch Geometric and its extensions (pip, source): I tried pip, and it is not success. Then, I changed to pip3, it is working. But I still get module not found error when I run code/example. And I cannot install using 'conda install torch-scatter'
    • Any other relevant information:

    Checklist

    • [x] I followed the installation guide.
    • [ ] I cannot find my error message in the FAQ.
    • [ ] I set up CUDA correctly and can compile CUDA code via nvcc.
    • [ ] I have cloned the repository and tried a manual installation from source.
    • [ ] I do have multiple CUDA versions on my machine.
    • [ ] I checked if the official extension example runs on my machine.
    • [ ] The offical extension example runs on my machine.

    Error logs:

    Thank you very much!

    opened by Shane-2015 28
  • Error running VGAE

    Error running VGAE

    🐛 Bug

    There seems to be a problem running the encoder.

    data=graph.graph
    
    gvae= VGAE(Encoder(data.num_features,5))
    
    model=gvae
    
    optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
    
    
    def train():
        model.train()
        optimizer.zero_grad()
        print(x)
        print(edge_index)
        z = model.encode(x, edge_index)
        print(z)
        loss = model.recon_loss(model.decoder(z), data.train_pos_edge_index,
                                data.train_neg_adj_mask)
        loss.backward()
        optimizer.step()
    
    
    def test(pos_edge_index, neg_edge_index):
        model.eval()
        with torch.no_grad():
            z = model.encode(x, edge_index)
        return model.test(model.decoder(z), pos_edge_index, neg_edge_index)
    
    
    for epoch in range(1, 201):
        train()
        auc, ap = test(data.val_pos_edge_index, data.val_neg_edge_index)
        print('Epoch: {:03d}, AUC: {:.4f}, AP: {:.4f}'.format(epoch, auc, ap))
    
    auc, ap = test(data.test_pos_edge_index, data.test_neg_edge_index)
    print('Test AUC: {:.4f}, Test AP: {:.4f}'.format(auc, ap))
    

    Got this error:


    RuntimeError Traceback (most recent call last) in () 25 26 for epoch in range(1, 201): ---> 27 train() 28 auc, ap = test(data.val_pos_edge_index, data.val_neg_edge_index) 29 print('Epoch: {:03d}, AUC: {:.4f}, AP: {:.4f}'.format(epoch, auc, ap))

    in train() 9 print(x) 10 print(edge_index) ---> 11 z = model.encode(x, edge_index) 12 print(z) 13 loss = model.recon_loss(model.decoder(z), data.train_pos_edge_index,

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch_geometric-1.0.3-py3.6.egg/torch_geometric/nn/models/autoencoder.py in encode(self, *args, **kwargs) 31 def encode(self, *args, **kwargs): 32 r"""Runs the encoder and computes latent variables for each node.""" ---> 33 return self.encoder(*args, **kwargs) 34 35 def decode(self, z):

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) 487 result = self._slow_forward(*input, **kwargs) 488 else: --> 489 result = self.forward(*input, **kwargs) 490 for hook in self._forward_hooks.values(): 491 hook_result = hook(self, input, result)

    in forward(self, x, edge_index) 28 29 def forward(self, x, edge_index): ---> 30 x = F.relu(self.conv1(x, edge_index)) 31 return self.conv2(x, edge_index) 32

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) 487 result = self._slow_forward(*input, **kwargs) 488 else: --> 489 result = self.forward(*input, **kwargs) 490 for hook in self._forward_hooks.values(): 491 hook_result = hook(self, input, result)

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch_geometric-1.0.3-py3.6.egg/torch_geometric/nn/conv/gcn_conv.py in forward(self, x, edge_index, edge_weight) 94 edge_index, norm = GCNConv.norm(edge_index, 95 x.size(0), edge_weight, ---> 96 self.improved, x.dtype) 97 self.cached_result = edge_index, norm 98

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch_geometric-1.0.3-py3.6.egg/torch_geometric/nn/conv/gcn_conv.py in norm(edge_index, num_nodes, edge_weight, improved, dtype) 81 82 row, col = edge_index ---> 83 deg = scatter_add(edge_weight, row, dim=0, dim_size=num_nodes) 84 deg_inv_sqrt = deg.pow(-0.5) 85 deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch_scatter/add.py in scatter_add(src, index, dim, out, dim_size, fill_value) 70 [2, 4, 4, 0, 0, 0]]) 71 """ ---> 72 src, out, index, dim = gen(src, index, dim, out, dim_size, fill_value) 73 return out.scatter_add_(dim, index, src)

    /anaconda2/envs/py36/lib/python3.6/site-packages/torch_scatter/utils/gen.py in gen(src, index, dim, out, dim_size, fill_value) 9 index_size = list(repeat(1, src.dim())) 10 index_size[dim] = src.size(dim) ---> 11 index = index.view(index_size).expand_as(src) 12 13 # Generate output tensor if not given.

    RuntimeError: shape '[340]' is invalid for input of size 307

    opened by jlevy44 28
  • Unpooling layers and generative architectures

    Unpooling layers and generative architectures

    Hey there! Thanks for your hard work with this project, it's super cool. In the end of the splineCNN paper, it was mentioned that unpooling layers were a future possibility. I'd love to try generating graphs from a continuous latent space. Any ideas for where I might start? Any projects like this one that you're aware of with generative capabilities? Thanks.

    feature 
    opened by robclouth 27
  • ERROR: No matching distribution found for torch-spine-conv

    ERROR: No matching distribution found for torch-spine-conv

    Hello, I am trying to install the pytorch_geometric on my computer which doesn't have GPU. When I try to run:

    !pip3 install torch-scatter
    !pip3 install torch-sparse
    !pip3 install torch-cluster
    !pip3 install torch-spine-conv
    !pip3 install torch-geometric
    

    I get the following error:

    ERROR: Could not find a version that satisfies the requirement torch-spine-conv (from versions: none) ERROR: No matching distribution found for torch-spine-conv

    By doing: python -c "import torch; print(torch.__version__)"

    I get:

    1.10.0+cu102

    installation 
    opened by samahwaleed 24
  • OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found

    OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found

    📚 Installation

    I have followed the instructions on the pytorch geometric website, and am repeatedly getting this error. The issues opened about this haven't been helpful either. I simply copy and paste the installation commands and get the error. Here's what I do

    pip3 install torch torchvision torchaudio
    
    

    and

    pip3 install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.10.0+cu102.html
    

    and when I import torch-spline-conv, I get the following

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/gpfs/home/hzaki1/celltypefromgrn/env/lib/python3.7/site-packages/torch_spline_conv/__init__.py", line 15, in <module>
        torch.ops.load_library(spec.origin)
      File "/gpfs/home/hzaki1/celltypefromgrn/env/lib/python3.7/site-packages/torch/_ops.py", line 110, in load_library
        ctypes.CDLL(path)
      File "/gpfs/runtime/opt/python/3.7.4/lib/python3.7/ctypes/__init__.py", line 364, in __init__
        self._handle = _dlopen(self._name, mode)
    OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /gpfs/home/hzaki1/celltypefromgrn/env/lib/python3.7/site-packages/torch_spline_conv/_basis_cuda.so)
    

    Environment

    • OS: Linux
    • Python version: 3.7
    • PyTorch version: 1.10.0
    • CUDA/cuDNN version: 10.2
    • GCC version: 10.2
    • How did you try to install PyTorch Geometric and its extensions (wheel, source): Via the wheel and guide on the website
    • Any other relevant information:

    Checklist

    • [x] I followed the installation guide.
    • [x] I cannot find my error message in the FAQ.
    • [x] I set up CUDA correctly and can compile CUDA code via nvcc.
    • [ ] I do have multiple CUDA versions on my machine.

    Additional context

    opened by hossam-zaki 24
  • Add `assortativity` to `torch_geometric.utils`

    Add `assortativity` to `torch_geometric.utils`

    This PR implements the computation of degree assortativity coefficient, as described in Mixing patterns in networks. Assortativity is a preference for a network's nodes to attach to others that are similar in some way. A larger assortativity indicates nodes tend to be connected with other nodes with similar degree values, and vice versa. Link to Slack Discussion

    The implementation is based on networkx.degree_assortativity_coefficient but much faster than using networkx.

    Test

    • Generate a graph (without duplicated edges)
    import torch
    from torch_geometric.utils import coalesce
    
    torch.manual_seed(12345)
    num_nodes = 10000
    num_edges = 1000000
    edge_index = torch.randint(0, num_nodes, size=(2, num_edges))
    edge_index = coalesce(edge_index)
    
    • networkx.degree_assortativity_coefficient
    import networkx as nx
    nxg = nx.from_edgelist(edge_index.t().tolist(), create_using=nx.DiGraph)
    t = time.perf_counter()
    result = nx.degree_assortativity_coefficient(nxg)
    print(f"result={result}, time={time.perf_counter()-t}")
    
    >>> result=-0.0007873635931715391, time=0.48579016700000466
    
    • torch_geometric.utils.assortativity (On CPU)
    from torch_geometric.utils import assortativity
    t = time.perf_counter()
    result = assortativity(edge_index)
    print(f"result={result}, time={time.perf_counter()-t}")
    
    >>> result=-0.0007878749747760594, time=0.07563883299985719
    
    • torch_geometric.utils.assortativity (On GPU)
    >>> result=-0.0007857615128159523, time=0.0036659350153058767
    

    The slight difference in results is caused by two different frameworks (Numpy and PyTorch).

    feature 1 - Priority P1 
    opened by EdisonLeeeee 0
  • a bug about Backpropagation

    a bug about Backpropagation

    🐛 Describe the bug

    Hi, I focus on contrastive learning, and I seem to have found some problems with back propagation, and here I give you my code. My model consists of two parts, an encoder and a projection head. The encoder is 5-layers GIN model, and the project head is a 2-layers MLP. I first try to generate four subgraphs, two big graph and two small graph, eg global and local, and then I first compare the two big graph to learn.

    Then, I found the problem, which was that if I covered up the highlighted parts or not, it would affect the performance of the model, but I didn't understand why. In my opinion, the two local subgraphs in the code are not involved in the calculation of the loss function, and therefore do not affect the backpropagation. May I ask if you know the reason?

    image image image

    Environment

    • PyG version:2.0.4
    • PyTorch version:1.9
    • OS:linux server
    • Python version:3.8
    • CUDA/cuDNN version:10.2
    • How you installed PyTorch and PyG (conda, pip, source):pip
    • Any other relevant information (e.g., version of torch-scatter): image
    bug 
    opened by ZhaoYuTJPU 9
  • RandomLinkSplit gives no `neg_edge_label` on dense graphs

    RandomLinkSplit gives no `neg_edge_label` on dense graphs

    🐛 Describe the bug

    Context: I'm programmatically creating undirected graphs for training a Graph Autoencoder (GAE). Some graphs are very dense, containing 90% of all possible edges.

    Training the GAE requires sampling missing edges as follows: T.RandomLinkSplit(num_val=0.15, num_test=0, is_undirected=True, split_labels=True, add_negative_train_samples=True, neg_sampling_ratio=1.0)

    Issue: Because the graphs are too dense, there aren't enough missing edges to sample negative edges. Consider a graph with 100 nodes and 9000 edges (from a maximum of 9900 edges). There are only 900 missing edges to sample as negative edges, but because I'm setting neg_sampling_ratio=1.0, PyG expected to find 9000 missing edges.

    The issue is that PyG doesn't check there aren't enough missing edges, and it creates training datasets without setting neg_edge_label. When creating the training data, the current code doesn't assign any neg_edge_index to the training data. See below the train/valid/test data.

    (Data(x=[141, 141], edge_index=[2, 16072], pos_edge_label=[8036], pos_edge_label_index=[2, 8036]), # Train; notice no negative edges
     Data(x=[141, 141], edge_index=[2, 16072], pos_edge_label=[1417], pos_edge_label_index=[2, 1417], neg_edge_label=[834], neg_edge_label_index=[2, 834]), # Validation
     Data(x=[141, 141], edge_index=[2, 18906], pos_edge_label=[0], pos_edge_label_index=[2, 0])) # Test
    

    Error: When creating a dataloader comes the KeyError: 'neg_edge_label' because the training data is missing this key.

    gnn_dataloader = tg.loader.DataLoader(graphs_dataset, batch_size=len(graphs_dataset), shuffle=True)
    gnn_batch_train, _, _ = next(iter(gnn_dataloader))
    
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    /tmp/ipykernel_175984/1912375602.py in <module>
          1 gnn_dataloader = tg.loader.DataLoader(graphs_dataset, batch_size=len(graphs_dataset), shuffle=True) # exclude_keys=['neg_edge_label']
    ----> 2 gnn_batch_train, _, _ = next(iter(gnn_dataloader))
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch/utils/data/dataloader.py in __next__(self)
        519             if self._sampler_iter is None:
        520                 self._reset()
    --> 521             data = self._next_data()
        522             self._num_yielded += 1
        523             if self._dataset_kind == _DatasetKind.Iterable and \
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch/utils/data/dataloader.py in _next_data(self)
        559     def _next_data(self):
        560         index = self._next_index()  # may raise StopIteration
    --> 561         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
        562         if self._pin_memory:
        563             data = _utils.pin_memory.pin_memory(data)
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
         50         else:
         51             data = self.dataset[possibly_batched_index]
    ---> 52         return self.collate_fn(data)
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/loader/dataloader.py in __call__(self, batch)
         32             return type(elem)(*(self(s) for s in zip(*batch)))
         33         elif isinstance(elem, Sequence) and not isinstance(elem, str):
    ---> 34             return [self(s) for s in zip(*batch)]
         35 
         36         raise TypeError(f'DataLoader found invalid type: {type(elem)}')
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/loader/dataloader.py in <listcomp>(.0)
         32             return type(elem)(*(self(s) for s in zip(*batch)))
         33         elif isinstance(elem, Sequence) and not isinstance(elem, str):
    ---> 34             return [self(s) for s in zip(*batch)]
         35 
         36         raise TypeError(f'DataLoader found invalid type: {type(elem)}')
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/loader/dataloader.py in __call__(self, batch)
         18         if isinstance(elem, BaseData):
         19             return Batch.from_data_list(batch, self.follow_batch,
    ---> 20                                         self.exclude_keys)
         21         elif isinstance(elem, torch.Tensor):
         22             return default_collate(batch)
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/data/batch.py in from_data_list(cls, data_list, follow_batch, exclude_keys)
         72             add_batch=not isinstance(data_list[0], Batch),
         73             follow_batch=follow_batch,
    ---> 74             exclude_keys=exclude_keys,
         75         )
         76 
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/data/collate.py in collate(cls, data_list, increment, add_batch, follow_batch, exclude_keys)
         68                 continue
         69 
    ---> 70             values = [store[attr] for store in stores]
         71 
         72             # The `num_nodes` attribute needs special treatment, as we need to
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/data/collate.py in <listcomp>(.0)
         68                 continue
         69 
    ---> 70             values = [store[attr] for store in stores]
         71 
         72             # The `num_nodes` attribute needs special treatment, as we need to
    
    ~/miniconda3/envs/low-data/lib/python3.7/site-packages/torch_geometric/data/storage.py in __getitem__(self, key)
         68 
         69     def __getitem__(self, key: str) -> Any:
    ---> 70         return self._mapping[key]
         71 
         72     def __setitem__(self, key: str, value: Any):
    
    KeyError: 'neg_edge_label'
    

    Suggested solution: I suggest a two-step solution:

    1. Raise a Warning that there aren't enough missing edges to sample negative edges
    2. If one of train/valid/test contains the keys neg_edge_label and neg_edge_label_index, then all three datasets shall contain it. In the above example, valid/test contain these keys, but the training dataset doesn't.

    Environment

    • PyG version: 2.1.0
    • PyTorch version: 1.10.1
    • Python version: 3.7.9
    bug transform 
    opened by andreimargeloiu 1
  • Add Typehinting and checking for PyG Data and Batch #5172

    Add Typehinting and checking for PyG Data and Batch #5172

    As per #5172

    Includes functionality to use torchtyping to check dimensions of tensors.

    Looking for general feedback on implementation and style. Specifically, should we add required attributes for Batches (like ptr and batch)?

    The dev.ipynb notebook contains some examples that can be deleted or used as a starting point for documentation.

    opened by a-r-j 1
  • Error while importing pytorch_geometric on Apple silicon M1

    Error while importing pytorch_geometric on Apple silicon M1

    😵 Describe the installation problem

    I'm installing pytorch_geometric on apple M1. I use pip to install it on a conda environment.

    /opt/anaconda3/envs/MyEnv/bin/pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.12.0+cpu.html

    Installation is completed with no issue. Upon running

    import torch_geometric as tg

    I get the error

    Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

    Environment

    • PyG version: 1.12.0
    • PyTorch version: Nightly
    • OS: macOS 11.5.2 BigSur
    • Python version: 3.7
    • CUDA/cuDNN version: NA
    • How you installed PyTorch and PyG (conda, pip, source): Both pip through conda, as shown above
    • Any other relevant information (e.g., version of torch-scatter): NA
    installation 
    opened by nshervt 1
Releases(2.1.0)
  • 2.1.0(Aug 17, 2022)

    We are excited to announce the release of PyG 2.1.0 🎉🎉🎉

    PyG 2.1.0 is the culmination of work from over 60 contributors who have worked on features and bug-fixes for a total of over 320 commits since torch-geometric==2.0.4.

    Highlights

    Principled Aggregations

    See here for the accompanying tutorial.

    Aggregation functions play an important role in the message passing framework and the readout functions of Graph Neural Networks. Specifically, many works in the literature (Hamilton et al. (2017), Xu et al. (2018), Corso et al. (2020), Li et al. (2020), Tailor et al. (2021), Bartunov et al. (2022)) demonstrate that the choice of aggregation functions contributes significantly to the representational power and performance of the model.

    To facilitate further experimentation and unify the concepts of aggregation within GNNs across both MessagePassing and global readouts, we have made the concept of Aggregation a first-class principle in PyG (#4379, #4522, #4687, #4721, #4731, #4762, #4749, #4779, #4863, #4864, #4865, #4866, #4872, #4927, #4934, #4935, #4957, #4973, #4973, #4986, #4995, #5000, #5021, #5034, #5036, #5039, #4522, #5033, #5085, #5097, #5099, #5104, #5113, #5130, #5098, #5191). As of now, PyG provides support for various aggregations — from simple ones (e.g., mean, max, sum), to advanced ones (e.g., median, var, std), learnable ones (e.g., SoftmaxAggregation, PowerMeanAggregation), and exotic ones (e.g., LSTMAggregation, SortAggregation, EquilibriumAggregation). Furthermore, multiple aggregations can be combined and stacked together:

    from torch_geometric.nn import MessagePassing, SoftmaxAggregation
    
    class MyConv(MessagePassing):
        def __init__(self, ...):
            # Combines a set of aggregations and concatenates their results.
            # The interface also supports automatic resolution.
            super().__init__(aggr=['mean', 'std', SoftmaxAggregation(learn=True)])
    

    Link-level Neighbor Loader

    We added a new LinkNeighborLoader class for training scalable GNNs that perform edge-level predictions on giant graphs (#4396, #4439, #4441, #4446, #4508, #4509, #4868). LinkNeighborLoader comes with automatic support for both homogeneous and heterogenous data, and supports link prediction via automatic negative sampling as well as edge-level classification and regression models:

    from torch_geometric.loader import LinkNeighborLoader
    
    loader = LinkNeighborLoader(
        data,
        num_neighbors=[30] * 2,  # Sample 30 neighbors for each node for 2 iterations
        batch_size=128,  # Use a batch size of 128 for sampling training links
        edge_label_index=data.edge_index,  # Use the entire graph for supervision
        negative_sampling_ratio=1.0,  # Sample negative edges
    )
    
    sampled_data = next(iter(loader))
    print(sampled_data)
    >>> Data(x=[1368, 1433], edge_index=[2, 3103], edge_label_index=[2, 256], edge_label=[256])
    

    Neighborhood Sampling based on Temporal Constraints

    Both NeighborLoader and LinkNeighborLoader now support temporal sampling via the time_attr argument (#4025, #4877, #4908, #5137, #5173). If set, temporal sampling will be used such that neighbors are guaranteed to fulfill temporal constraints, i.e. neighbors have an earlier timestamp than the center node:

    from torch_geometric.loader import NeighborLoader
    
    data['paper'].time = torch.arange(data['paper'].num_nodes)
    
    loader = NeighborLoader(
        data,
        input_nodes='paper',
        time_attr='time',  # Only sample papers that appeared before the seed paper
        num_neighbors=[30] * 2,
        batch_size=128,
    )
    

    Note that this feature requires torch-sparse>=0.6.14.

    Functional DataPipes

    See here for the accompanying example.

    PyG now fully supports data loading using the newly introduced concept of DataPipes in PyTorch for easily constructing flexible and performant data pipelines (#4302, #4345, #4349). PyG provides DataPipe support for batching multiple PyG data objects together and for applying any PyG transform:

    datapipe = FileOpener(['SMILES_HIV.csv'])
    datapipe = datapipe.parse_csv_as_dict()
    datapipe = datapipe.parse_smiles(target_key='HIV_active')
    datapipe = datapipe.in_memory_cache()  # Cache graph instances in-memory.
    datapipe = datapipe.shuffle()
    datapipe = datapipe.batch_graphs(batch_size=32)
    
    datapipe = FileLister([root_dir], masks='*.off', recursive=True)
    datapipe = datapipe.read_mesh()
    datapipe = datapipe.in_memory_cache()  # Cache graph instances in-memory.
    datapipe = datapipe.sample_points(1024)  # Use PyG transforms from here.
    datapipe = datapipe.knn_graph(k=8)
    datapipe = datapipe.shuffle()
    datapipe = datapipe.batch_graphs(batch_size=32)
    

    Breaking Changes

    Deprecations

    Features

    Layers, Models and Examples

    Transformations

    Datasets

    General Improvements

    Bugfixes

    • Fixed a bug in RGATConv that produced device mismatches for "f-scaled" mode (#5187]
    • Fixed a bug in GINEConv bug for non-Sequential neural network layers (#5154]
    • Fixed a bug in HGTLoader which produced outputs with missing edge types, will require torch-sparse>=0.6.15 (#5067)
    • Fixed a bug in load_state_dict for Linear with strict=False mode (5094)
    • Fixed data.num_node_features computation for sparse matrices (5089)
    • Fixed a bug in which GraphGym did not create new non-linearity functions but re-used existing ones (4978)
    • Fixed BasicGNN for num_layers=1, which now respects a desired number of out_channels (#4943)
    • Fixed a bug in data.subgraph for 0-dim tensors (#4932)
    • Fixed a bug in InMemoryDataset inferring wrong length for lists of tensors (#4837)
    • Fixed a bug in TUDataset where pre_filter was not applied whenever pre_transform was present (#4842)
    • Fixed access of edge types in HeteroData via two node types when there exists multiple relations between them (#4782)
    • Fixed a bug in HANConv in which destination node features rather than source node features were propagated (#4753)
    • Fixed a ranking protocol bug in the RGCN link prediction example (#4688)
    • Fixed the interplay between TUDataset and pre_transform transformations that modify node features (#4669)
    • The bias argument in TAGConv is now correctly applied (#4597)
    • Fixed filtering of attributes in samplers in case __cat_dim__ != 0 (#4629)
    • Fixed SparseTensor support in NeighborLoader (#4320)
    • Fixed average degree handling in PNAConv (#4312)
    • Fixed a bug in from_networkx in case some attributes are PyTorch tensors (#4486)
    • Fixed a missing clamp in the DimeNet model (#4506, #4562)
    • Fixed the download link in DBP15K (#4428)
    • Fixed an autograd bug in DimeNet when resetting parameters (#4424)
    • Fixed bipartite message passing in case flow="target_to_source" (#4418)
    • Fixed a bug in which num_nodes was not properly updated in the FixedPoints transform (#4394)
    • Fixed a bug in which GATConv was not jittable (#4347)
    • Fixed a bug in which nn.models.GAT did not produce out_channels many output channels (#4299)
    • Fixed a bug in mini-batching with empty lists as attributes (#4293)
    • Fixed a bug in which GCNConv could not be combined with to_hetero on heterogeneous graphs with one node type (#4279)

    Full Changelog

    Added
    • Added edge_label_time argument to LinkNeighborLoader (#5137, #5173)
    • Let ImbalancedSampler accept torch.Tensor as input (#5138)
    • Added flow argument to gcn_norm to correctly normalize the adjacency matrix in GCNConv (#5149)
    • NeighborSampler supports graphs without edges (#5072)
    • Added the MeanSubtractionNorm layer (#5068)
    • Added pyg_lib.segment_matmul integration within RGCNConv (#5052, #5096)
    • Support SparseTensor as edge label in LightGCN (#5046)
    • Added support for BasicGNN models within to_hetero (#5091)
    • Added support for computing weighted metapaths in AddMetapaths (#5049)
    • Added inference benchmark suite (#4915)
    • Added a dynamically sized batch sampler for filling a mini-batch with a variable number of samples up to a maximum size (#4972)
    • Added fine grained options for setting bias and dropout per layer in the MLP model (#4981)
    • Added EdgeCNN model (#4991)
    • Added scalable inference mode in BasicGNN with layer-wise neighbor loading (#4977)
    • Added inference benchmarks (#4892, #5107)
    • Added PyTorch 1.12 support (#4975)
    • Added unbatch_edge_index functionality for splitting an edge_index tensor according to a batch vector (#4903)
    • Added node-wise normalization mode in LayerNorm (#4944)
    • Added support for normalization_resolver (#4926, #4951, #4958, #4959)
    • Added notebook tutorial for torch_geometric.nn.aggr package to documentation (#4927)
    • Added support for follow_batch for lists or dictionaries of tensors (#4837)
    • Added Data.validate() and HeteroData.validate() functionality (#4885)
    • Added LinkNeighborLoader support to LightningDataModule (#4868)
    • Added predict() support to the LightningNodeData module (#4884)
    • Added time_attr argument to LinkNeighborLoader (#4877, #4908)
    • Added a filter_per_worker argument to data loaders to allow filtering of data within sub-processes (#4873)
    • Added a NeighborLoader benchmark script (#4815, #4862)
    • Added support for FeatureStore and GraphStore in NeighborLoader (#4817, #4851, #4854, #4856, #4857, #4882, #4883, #4929, #4992, #4962, #4968, #5037, #5088)
    • Added a normalize parameter to dense_diff_pool (#4847)
    • Added size=None explanation to jittable MessagePassing modules in the documentation (#4850)
    • Added documentation to the DataLoaderIterator class (#4838)
    • Added GraphStore support to Data and HeteroData (#4816)
    • Added FeatureStore support to Data and HeteroData (#4807, #4853)
    • Added FeatureStore and GraphStore abstractions (#4534, #4568)
    • Added support for dense aggregations in global_*_pool (#4827)
    • Added Python version requirement (#4825)
    • Added TorchScript support to JumpingKnowledge module (#4805)
    • Added a max_sample argument to AddMetaPaths in order to tackle very dense metapath edges (#4750)
    • Test HANConv with empty tensors (#4756, #4841)
    • Added the bias vector to the GCN model definition in the "Create Message Passing Networks" tutorial (#4755)
    • Added transforms.RootedSubgraph interface with two implementations: RootedEgoNets and RootedRWSubgraph (#3926)
    • Added ptr vectors for follow_batch attributes within Batch.from_data_list (#4723)
    • Added torch_geometric.nn.aggr package (#4687, #4721, #4731, #4762, #4749, #4779, #4863, #4864, #4865, #4866, #4872, #4934, #4935, #4957, #4973, #4973, #4986, #4995, #5000, #5034, #5036, #5039, #4522, #5033, #5085, #5097, #5099, #5104, #5113, #5130, #5098, #5191)
    • Added the DimeNet++ model (#4432, #4699, #4700, #4800)
    • Added an example of using PyG with PyTorch Ignite (#4487)
    • Added GroupAddRev module with support for reducing training GPU memory (#4671, #4701, #4715, #4730)
    • Added benchmarks via wandb (#4656, #4672, #4676)
    • Added unbatch functionality (#4628)
    • Confirm that to_hetero() works with custom functions, e.g., dropout_adj (4653)
    • Added the MLP.plain_last=False option (4652)
    • Added a check in HeteroConv and to_hetero() to ensure that MessagePassing.add_self_loops is disabled (4647)
    • Added HeteroData.subgraph() support (#4635)
    • Added the AQSOL dataset (#4626)
    • Added HeteroData.node_items() and HeteroData.edge_items() functionality (#4644)
    • Added PyTorch Lightning support in GraphGym (#4511, #4516 #4531, #4689, #4843)
    • Added support for returning embeddings in MLP models (#4625)
    • Added faster initialization of NeighborLoader in case edge indices are already sorted (via is_sorted=True) (#4620, #4702)
    • Added AddPositionalEncoding transform (#4521)
    • Added HeteroData.is_undirected() support (#4604)
    • Added the Genius and Wiki datasets to nn.datasets.LINKXDataset (#4570, #4600)
    • Added nn.aggr.EquilibrumAggregation implicit global layer (#4522)
    • Added support for graph-level outputs in to_hetero (#4582)
    • Added CHANGELOG.md (#4581)
    • Added HeteroData support to the RemoveIsolatedNodes transform (#4479)
    • Added HeteroData.num_features functionality (#4504)
    • Added support for projecting features before propagation in SAGEConv (#4437)
    • Added Geom-GCN splits to the Planetoid datasets (#4442)
    • Added a LinkNeighborLoader for training scalable link predictions models #4396, #4439, #4441, #4446, #4508, #4509)
    • Added an unsupervised GraphSAGE example on PPI (#4416)
    • Added support for LSTM aggregation in SAGEConv (#4379)
    • Added support for floating-point labels in RandomLinkSplit (#4311, #4383)
    • Added support for torch.data DataPipes (#4302, #4345, #4349)
    • Added support for the cosine argument in the KNNGraph/RadiusGraph transforms (#4344)
    • Added support graph-level attributes in networkx conversion (#4343)
    • Added support for renaming node types via HeteroData.rename (#4329)
    • Added an example to load a trained PyG model in C++ (#4307)
    • Added a MessagePassing.explain_message method to customize making explanations on messages (#4278, #4448))
    • Added support for GATv2Conv in the nn.models.GAT model (#4357)
    • Added HeteroData.subgraph functionality (#4243)
    • Added the MaskLabel module and a corresponding masked label propagation example (#4197)
    • Added temporal sampling support to NeighborLoader (#4025)
    • Added an example for unsupervised heterogeneous graph learning based on "Deep Multiplex Graph Infomax" (#3189)
    Changed
    • Changed docstring for RandomLinkSplit (#5190)
    • Switched to PyTorch scatter_reduce implementation - experimental feature (#5120)
    • Fixed RGATConv device mismatches for f-scaled mode (#5187]
    • Allow for multi-dimensional edge_labels in LinkNeighborLoader (#5186]
    • Fixed GINEConv bug with non-sequential input (#5154]
    • Improved error message (#5095)
    • Fixed HGTLoader bug which produced outputs with missing edge types (#5067)
    • Fixed dynamic inheritance issue in data batching (#5051)
    • Fixed load_state_dict in Linear with strict=False mode (5094)
    • Fixed typo in MaskLabel.ratio_mask (5093)
    • Fixed data.num_node_features computation for sparse matrices (5089)
    • Fixed torch.fx bug with torch.nn.aggr package (#5021))
    • Fixed GenConv test (4993)
    • Fixed packaging tests for Python 3.10 (4982)
    • Changed act_dict (part of graphgym) to create individual instances instead of reusing the same ones everywhere (4978)
    • Fixed issue where one-hot tensors were passed to F.one_hot (4970)
    • Fixed bool arugments in argparse in benchmark/ (#4967)
    • Fixed BasicGNN for num_layers=1, which now respects a desired number of out_channels (#4943)
    • len(batch) will now return the number of graphs inside the batch, not the number of attributes (#4931)
    • Fixed data.subgraph generation for 0-dim tensors (#4932)
    • Removed unnecssary inclusion of self-loops when sampling negative edges (#4880)
    • Fixed InMemoryDataset inferring wrong len for lists of tensors (#4837)
    • Fixed Batch.separate when using it for lists of tensors (#4837)
    • Correct docstring for SAGEConv (#4852)
    • Fixed a bug in TUDataset where pre_filter was not applied whenever pre_transform was present (#4842)
    • Renamed RandomTranslate to RandomJitter - the usage of RandomTranslate is now deprecated (#4828)
    • Do not allow accessing edge types in HeteroData with two node types when there exists multiple relations between these types (#4782)
    • Allow edge_type == rev_edge_type argument in RandomLinkSplit (#4757)
    • Fixed a numerical instability in the GeneralConv and neighbor_sample tests (#4754)
    • Fixed a bug in HANConv in which destination node features rather than source node features were propagated (#4753)
    • Fixed versions of checkout and setup-python in CI (#4751)
    • Fixed protobuf version (#4719)
    • Fixed the ranking protocol bug in the RGCN link prediction example (#4688)
    • Math support in Markdown (#4683)
    • Allow for setter properties in Data (#4682, #4686)
    • Allow for optional edge_weight in GCN2Conv (#4670)
    • Fixed the interplay between TUDataset and pre_transform that modify node features (#4669)
    • Make use of the pyg_sphinx_theme documentation template (#4664, #4667)
    • Refactored reading molecular positions from sdf file for qm9 datasets (4654)
    • Fixed MLP.jittable() bug in case return_emb=True (#4645, #4648)
    • The generated node features of StochasticBlockModelDataset are now ordered with respect to their labels (#4617)
    • Fixed typos in the documentation (#4616, #4824, #4895, #5161)
    • The bias argument in TAGConv is now actually applied (#4597)
    • Fixed subclass behaviour of process and download in Datsaet (#4586)
    • Fixed filtering of attributes for loaders in case __cat_dim__ != 0 (#4629)
    • Fixed SparseTensor support in NeighborLoader (#4320)
    • Fixed average degree handling in PNAConv (#4312)
    • Fixed a bug in from_networkx in case some attributes are PyTorch tensors (#4486)
    • Added a missing clamp in DimeNet (#4506, #4562)
    • Fixed the download link in DBP15K (#4428)
    • Fixed an autograd bug in DimeNet when resetting parameters (#4424)
    • Fixed bipartite message passing in case flow="target_to_source" (#4418)
    • Fixed a bug in which num_nodes was not properly updated in the FixedPoints transform (#4394)
    • PyTorch Lightning >= 1.6 support (#4377)
    • Fixed a bug in which GATConv was not jittable (#4347)
    • Fixed a bug in which the GraphGym config was not stored in each specific experiment directory (#4338)
    • Fixed a bug in which nn.models.GAT did not produce out_channels-many output channels (#4299)
    • Fixed mini-batching with empty lists as attributes (#4293)
    • Fixed a bug in which GCNConv could not be combined with to_hetero on heterogeneous graphs with one node type (#4279)
    Removed
    • Remove internal metrics in favor of torchmetrics (#4287)

    Full commit list: https://github.com/pyg-team/pytorch_geometric/compare/2.0.4...2.1.0

    Source code(tar.gz)
    Source code(zip)
  • 2.0.4(Mar 12, 2022)

    PyG 2.0.4 🎉

    A new minor PyG version release, bringing PyTorch 1.11 support to PyG. It further includes a variety of new features and bugfixes:

    Features

    • Added Quiver examples for multi-GU training using GraphSAGE (#4103), thanks to @eedalong and @luomai
    • nn.model.to_captum: Full integration of explainability methods provided by the Captum library (#3990, #4076), thanks to @RBendias
    • nn.conv.RGATConv: The relational graph attentional operator (#4031, #4110), thanks to @fork123aniket
    • nn.pool.DMoNPooling: The spectral modularity pooling operator (#4166, #4242), thanks to @fork123aniket
    • nn.*: Support for shape information in the documentation (#3739, #3889, #3893, #3946, #3981, #4009, #4120, #4158), thanks to @saiden89 and @arunppsg and @konstantinosKokos
    • loader.TemporalDataLoader: A dataloader to load a TemporalData object in mini-batches (#3985, #3988), thanks to @otaviocx
    • loader.ImbalancedSampler: A weighted random sampler that randomly samples elements according to class distribution (#4198)
    • transforms.VirtualNode: A transform that adds a virtual node to a graph (#4163)
    • transforms.LargestConnectedComponents: Selects the subgraph that corresponds to the largest connected components in the graph (#3949), thanks to @abojchevski
    • utils.homophily: Support for class-insensitive edge homophily (#3977, #4152), thanks to @hash-ir and @jinjh0123
    • utils.get_mesh_laplacian: Mesh Laplacian computation (#4187), thanks to @daniel-unyi-42

    Datasets

    • Added a dataset cheatsheet to the documentation that collects import graph statistics across a variety of datasets supported in PyG (#3807, #3817) (please consider helping us filling its remaining content)
    • datasets.EllipticBitcoinDataset: A dataset of Bitcoin transactions (#3815), thanks to @shravankumar147

    Minor Changes

    • nn.models.MLP: MLPs can now either be initialized via a list of channels or by specifying hidden_channels and num_layers (#3957)
    • nn.models.BasicGNN: Final Linear transformations are now always applied (except for jk=None) (#4042)
    • nn.conv.MessagePassing: Message passing modules that make use of edge_updater are now jittable (#3765), thanks to @Padarn
    • nn.conv.MessagePassing: (Official) support for min and mul aggregations (#4219)
    • nn.LightGCN: Initialize embeddings via xavier_uniform for better model performance (#4083), thanks to @nishithshowri006
    • nn.conv.ChebConv: Automatic eigenvalue approximation (#4106), thanks to @daniel-unyi-42
    • nn.conv.APPNP: Added support for optional edge_weight, (690a01d), thanks to @YueeXiang
    • nn.conv.GravNetConv: Support for torch.jit.script (#3885), thanks to @RobMcH
    • nn.pool.global_*_pool: The batch vector is now optional (#4161)
    • nn.to_hetero: Added a warning in case to_hetero is used on HeteroData metadata with unused destination node types (#3775)
    • nn.to_hetero: Support for nested modules (ea135bf)
    • nn.Sequential: Support for indexing (#3790)
    • nn.Sequential: Support for OrderedDict as input (#4075)
    • datasets.ZINC: Added an in-depth description of the task (#3832), thanks to @gasteigerjo
    • datasets.FakeDataset: Support for different feature distributions across different labels (#4065), thanks to @arunppsg
    • datasets.FakeDataset: Support for custom global attributes (#4074), thanks to @arunppsg
    • transforms.NormalizeFeatures: Features will no longer be transformed in-place (ada5b9a)
    • transforms.NormalizeFeatures: Support for negative feature values (6008e30)
    • utils.is_undirected: Improved efficiency (#3789)
    • utils.dropout_adj: Improved efficiency (#4059)
    • utils.contains_isolated_nodes: Improved efficiency (970de13)
    • utils.to_networkx: Support for to_undirected options (upper triangle vs. lower triangle) (#3901, #3948), thanks to @RemyLau
    • graphgym: Support for custom metrics and loggers (#3494), thanks to @RemyLau
    • graphgym.register: Register operations can now be used as class decorators (#3779, #3782)
    • Documentation: Added a few exercises at the end of documentation tutorials (#3780), thanks to @PabloAMC
    • Documentation: Added better installation instructions to CONTRIBUTUNG.md (#3803, #3991, #3995), thanks to @Cho-Geonwoo and @RBendias and @RodrigoVillatoro
    • Refactor: Clean-up dependencies (#3908, #4133, #4172), thanks to @adelizer
    • CI: Improved test runtimes (#4241)
    • CI: Additional linting check via yamllint (#3886)
    • CI: Additional linting check via isort (66b1780), thanks to @mananshah99
    • torch.package: Model packaging via torch.package (#3997)

    Bugfixes

    • data.HeteroData: Fixed a bug in data.{attr_name}_dict in case data.{attr_name} does not exist (#3897)
    • data.Data: Fixed data.is_edge_attr in case data.num_edges == 1 (#3880)
    • data.Batch: Fixed a device mismatch bug in case a batch object was indexed that was created from GPU tensors (e6aa4c9, c549b3b)
    • data.InMemoryDataset: Fixed a bug in which copy did not respect the underlying slice (d478dcb, #4223)
    • nn.conv.MessagePassing: Fixed message passing with zero nodes/edges (#4222)
    • nn.conv.MessagePassing: Fixed bipartite message passing with flow="target_to_source" (#3907)
    • nn.conv.GeneralConv: Fixed an issue in case skip_linear=False and in_channels=out_channels (#3751), thanks to @danielegrattarola
    • nn.to_hetero: Fixed model transformation in case node type names or edge type names contain whitespaces or dashes (#3882, b63a660)
    • nn.dense.Linear: Fixed a bug in lazy initialization for PyTorch < 1.8.0 (973d17d, #4086)
    • nn.norm.LayerNorm: Fixed a bug in the shape of weights and biases (#4030), thanks to @marshka
    • nn.pool: Fixed torch.jit.script support for torch-cluster functions (#4047)
    • datasets.TOSCA: Fixed a bug in which indices of faces started at 1 rather than 0 (8c282a0), thanks to @JRowbottomGit
    • datasets.WikiCS: Fixed WikiCS to be undirected by default (#3796), thanks to @pmernyei
    • Resolved inconsistency between utils.contains_isolated_nodes and data.has_isolated_nodes (#4138)
    • graphgym: Fixed the loss function regarding multi-label classification (#4206), thanks to @RemyLau
    • Documentation: Fixed typos, grammar and bugs (#3840, #3874, #3875, #4149), thanks to @itamblyn and @chrisyeh96 and @finquick
    Source code(tar.gz)
    Source code(zip)
  • 2.0.3(Dec 22, 2021)

    PyG 2.0.3 🎉

    A new minor PyG version release, including a variety of new features and bugfixes:

    Features

    Datasets

    Minor Changes

    • torch_geometric.nn.norm: Improved the runtimes of normalization layers - thanks to @johnpeterflynn
    • DataLoader and NeighborLoader: Output tensors are now written to shared memory to avoid an extra copy in case num_workers > 0 (#3401 and #3734) - thanks to @johnpeterflynn
    • GATv2Conv: Support for edge features (#3421) - thanks to @Kenneth-Schroeder
    • Batch.from_data_list: Runtime improvements
    • TransformerConv: Runtime and memory consumption improvements (#3392) - thanks to @wsad1
    • mean_iou: Added IoU computation via omitting NaNs (#3464) - thanks to @GericoVi
    • DataLoader: follow_batch and exclude_keys are now optional arguments
    • Improvements to the package metadata (#3445) - thanks to @cthoyt
    • Updated the quick start widget to support PyTorch 1.10 (#3474) - thanks to @kathyfan
    • NeighborLoader and HGTLoader: Removed the persistent_workers=True default
    • voxel_grid: The batch argument is now optional (#3533) - thanks to @QuanticDisaster
    • TransformerConv: JIT support (#3538) - thanks to @RobMcH
    • Lazy modules can now correctly be saved and loaded via state_dict() and load_state_dict() (#3651) - thanks to @shubham-gupta-iitr
    • from_networkx: Support for nx.MultiDiGraph (#3646) - thanks to @max-zipfl-fzi
    • GATv2Conv: Support for lazy initialization (#3678) - thanks to @richcmwang
    • torch_geometric.graphgym: register_* functions can now be used as decorators (#3684)
    • AddSelfLoops: Now supports the full argument set of torch_geometric.utils.add_self_loops (#3702) - thanks to @dongkwan-kim
    • Documentation: Added shape information to a variety of GNN operators, e.g., GATConv or ChebConv (#3697) - thanks to @saiden89
    • GATv2Conv and HEATConv: Removed unnecessary size argument in forward (#3744) - thanks to @saiden89

    Bugfixes

    • GNNExplainer: Fixed a bug in the GCN example normalization coefficients were wrongly calculated (#3508) - thanks to @RBendias
    • HGTConv: Fixed a bug in the residual connection formulation - thanks to @zzhnobug
    • torch_geometric.grapghym: Fixed a bug in the creation of MLP (#3431) - thanks to @JiaxuanYou
    • torch_geometric.graphgym: Fixed a bug in the dimensionality of GeneralMultiLayer (#3456) - thanks to @JiaxuanYou
    • RandomLinkSplit: Fixed a bug in negative edge sampling for undirected graphs (#3440) - thanks to @panisson
    • add_self_loops: Fixed a bug in adding self-loops with scalar-valued weights
    • SchNet: Fixed a bug in which a bias vector was not correctly initialized as zero - thanks to @nec4
    • Batch.from_data_list: Replaced the torch.repeat_interleave call due to errors in forked processes (#3566) - thanks to @Enolerobotti
    • NeighborLoader: Fixed a bug in conjunction with PyTorch Lightning (#3602) - thanks to @pbielak
    • NeighborLoader and ToSparseTensor: Fixed a bug in case num_nodes == num_edges (#3683) - thanks to @WuliangHuang
    • ToUndirected: Fixed a bug in case num_nodes == 2 (#3627) - thanks to @aur3l14no
    • FiLMConv: Fixed a bug in the backward pass due to the usage of in-place operations - thanks to @Jokeren
    • GDC: Fixed a bug in case K > num_nodes - thanks to @Misterion777
    • LabelPropagation: Fixed a bug in the order of transformations (#3639) - thanks to @Riyer01
    • negative_sampling: Fixed execution for GPU input tensors - thanks to @Sticksword and @lmy86263
    • HeteroData: Fixed a bug in which node types were interpreted as edge types in case they were described by two characters (#3692)
    • FastRGCNConv: Fixed a bug in which weights were indexed on destination node index rather than source node index (#3690) - thanks to @Jokeren
    • WikipediaNetwork: Fixed a bug in downloading due to a change in URLs - thanks to @csbobby and @Kousaka-Honoka
    Source code(tar.gz)
    Source code(zip)
  • 2.0.2(Oct 26, 2021)

    A new minor version release, including further bugfixes, official PyTorch 1.10 support, as well as additional features and operators:

    Features

    Minor Changes

    • Data.to_homogeneous will now add node_type information to the homogeneous Data object
    • GINEConv now allows to transform edge features automatically in case their dimensionalities do not match (thanks to @CaypoH)
    • OGB_MAG will now add node_year information to paper nodes
    • Entities datasets do now allow the processing of HeteroData objects via the hetero=True option
    • Batch objects can now be batched together to form super batches
    • Added heterogeneous graph support for Center, Constant and LinearTransformation transformations
    • HeteroConv now allows to return "stacked" embeddings
    • The batch vector of a Batch object will now be initialized on the GPU in case other attributes are held in GPU memory

    Bugfixes

    • Fixed the num_neighbors argument of NeighborLoader in order to specify an edge-type specific number of neighbors
    • Fixed the collate policy of lists of integers/strings to return nested lists
    • Fixed the Delaunay transformation in case the face attribute is not present in the data
    • Fixed the TGNMemory module to only read from the latest update (thanks to @cwh104504)
    • Fixed the pickle.PicklingError when Batch objects are used in a torch.multiprocessing.manager.Queue() (thanks to @RasmusOrsoe)
    • Fixed an issue with _parent state changing after pickling of Data objects (thanks to @zepx)
    • Fixed the ToUndirected transformation in case the number of edges and nodes are equal (thanks to @lmkmkrcc)
    • Fixed the from_networkx routine in case node-level and edge-level features share the same names
    • Removed the num_nodes warning when creating PairData objects
    • Fixed the initialization of the GeneralMultiLayer module in GraphGym (thanks to @fjulian)
    • Fixed custom model registration in GraphGym
    • Fixed a clash in the run_dir naming of GraphGym (thanks to @fjulian)
    • Includes a fix to prevent a GraphGym crash in case ROC-score is undefined (thanks to @fjulian)
    • Fixed the Batch.from_data_list routine on dataset slices (thanks to @dtortorella)
    • Fixed the MetaPath2Vec model in case there exists isolated nodes
    • Fixed torch_geometric.utils.coalesce with CUDA tensors
    Source code(tar.gz)
    Source code(zip)
  • 2.0.1(Sep 16, 2021)

    PyG 2.0.1

    This is a minor release, bringing some emergency fixes to PyG 2.0.

    Bugfixes

    • Fixed a bug in loader.DataLoader that raised a PicklingError for num_workers > 0 (thanks to @r-echeveste, @arglog and @RishabhPandit-00)
    • Fixed a bug in the creation of data.Batch objects in case customized data.Data objects expect non-default arguments (thanks to @Emiyalzn)
    • Fixed a bug in which SparseTensor attributes could not be batched along single dimensions (thanks to @rubenwiersma)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Sep 13, 2021)

    PyG 2.0 :tada: :tada: :tada:

    PyG (PyTorch Geometric) has been moved from my own personal account rusty1s to its own organization account pyg-team to emphasize the ongoing collaboration between TU Dortmund University, Stanford University and many great external contributors. With this, we are releasing PyG 2.0, a new major release that brings sophisticated heterogeneous graph support, GraphGym integration and many other exciting features to PyG.

    If you encounter any bugs in this new release, please do not hesitate to create an issue.

    Heterogeneous Graph Support

    We finally provide full heterogeneous graph support in PyG 2.0. See here for the accompanying tutorial.

    Highlights

    • Heterogeneous Graph Storage: Heterogeneous graphs can now be stored in their own dedicated data.HeteroData class (thanks to @yaoyaowd):

      from torch_geometric.data import HeteroData
      
      data = HeteroData()
      
      # Create two node types "paper" and "author" holding a single feature matrix:
      data['paper'].x = torch.randn(num_papers, num_paper_features)
      data['author'].x = torch.randn(num_authors, num_authors_features)
      
      # Create an edge type ("paper", "written_by", "author") holding its graph connectivity:
      data['paper', 'written_by', 'author'].edge_index = ...  # [2, num_edges]
      

      data.HeteroData behaves similar to a regular homgeneous data.Data object:

      print(data['paper'].num_nodes)
      print(data['paper', 'written_by', 'author'].num_edges)
      data = data.to('cuda')
      
    • Heterogeneous Mini-Batch Loading: Heterogeneous graphs can be converted to mini-batches for many small and single giant graphs via the loader.DataLoader and loader.NeighborLoader loaders, respectively. These loaders can now handle both homogeneous and heterogeneous graphs:

      from torch_geometric.loader import DataLoader
      
      loader = DataLoader(heterogeneous_graph_dataset, batch_size=32, shuffle=True)
      
      from torch_geometric.loader import NeighborLoader
      
      loader = NeighborLoader(heterogeneous_graph, num_neighbors=[30, 30], batch_size=128,
                              input_nodes=('paper', data['paper'].train_mask), shuffle=True)
      
    • Heterogeneous Graph Neural Networks: Heterogeneous GNNs can now easily be created from homogeneous ones via nn.to_hetero and nn.to_hetero_with_bases. These processes take an existing GNN model and duplicate their message functions to account for different node and edge types:

      from torch_geometric.nn import SAGEConv, to_hetero
      
      class GNN(torch.nn.Module):
          def __init__(hidden_channels, out_channels):
              super().__init__()
              self.conv1 = SAGEConv((-1, -1), hidden_channels)
              self.conv2 = SAGEConv((-1, -1), out_channels)
      
          def forward(self, x, edge_index):
              x = self.conv1(x, edge_index).relu()
              x = self.conv2(x, edge_index)
              return x
      
      model = GNN(hidden_channels=64, out_channels=dataset.num_classes)
      model = to_hetero(model, data.metadata(), aggr='sum')
      

    Additional Features

    Managing Experiments with GraphGym

    GraphGym is now officially supported in PyG 2.0 via torch_geometric.graphgym. See here for the accompanying tutorial. Overall, GraphGym is a platform for designing and evaluating Graph Neural Networks from configuration files via a highly modularized pipeline (thanks to @JiaxuanYou):

    1. GraphGym is the perfect place to start learning about standardized GNN implementation and evaluation
    2. GraphGym provides a simple interface to try out thousands of GNN architectures in parallel to find the best design for your specific task
    3. GraphGym lets you easily do hyper-parameter search and visualize what design choices are better

    Breaking Changes

    • The datasets.AMiner dataset now returns a data.HeteroData object. See here for our updated MetaPath2Vec example on AMiner.
    • transforms.AddTrainValTestMask has been replaced in favour of transforms.RandomNodeSplit
    • Since the storage layout of data.Data significantly changed in order to support heterogenous graphs, already processed datasets need to be re-processed by deleting the root/processed folder.
    • data.Data.__cat_dim__ and data.Data.__inc__ now expect additional input arguments:
      def __cat_dim__(self, key, value, *args, **kwargs):
          pass
      
      def __inc__(self, key, value, *args, **kwargs):
          pass
      

      In case you modified __cat_dim__ or __inc__ functionality in a customized data.Data object, please ensure to apply the above changes.

    Deprecations

    Additional Features

    Minor Changes

    • Heavily improved loading times of import torch_geometric
    • nn.Sequential is now fully jittable
    • nn.conv.LEConv is now fully jittable (thanks to @lucagrementieri)
    • nn.conv.GENConv can now make use of "add", "mean" or "max" aggregations (thanks to @riskiem)
    • Attributes of type torch.nn.utils.rnn.PackedSequence are now correctly handled by data.Data and data.HeteroData (thanks to @WuliangHuang)
    • Added support for data.record_stream() in order to allow for data prefetching (thanks to @FarzanT)
    • Added a max_num_neighbors attribute to nn.models.SchNet and nn.models.DimeNet (thanks to @nec4)
    • nn.conv.MessagePassing is now jittable in case message, aggregate and update return multiple arguments (thanks to @PhilippThoelke)
    • utils.from_networkx now supports grouping of node-level and edge-level features (thanks to @PabloAMC)
    • Transforms now inherit from transforms.BaseTransform to ease type checking (thanks to @CCInc)
    • Added support for the deletion of data attributes via del data[key] (thanks to @Linux-cpp-lisp)

    Bugfixes

    • The transforms.LinearTransformation transform now correctly transposes the input matrix before applying the transformation (thanks to @beneisner)
    • Fixed a bug in benchmark/kernel that prevented the application of DiffPool on the IMDB-BINARY dataset (thanks to @dongZheX)
    • Feature dimensionalities of datasets.WikipediaNetwork do now match which the official reported ones in case geom_gcn_preprocess=True (thanks to @ZhuYun97 and @GitEventhandler)
    • Fixed a bug in the datasets.DynamicFAUST dataset in which data.num_nodes was undefined (thanks to @koustav123)
    • Fixed a bug in which nn.models.GNNExplainer could not handle GNN operators that add self-loops to the graph in case self-loops were already present (thanks to @tw200464tw and @NithyaBhasker)
    • nn.norm.LayerNorm may no longer produce NaN gradients (thanks to @fbragman)
    • Fixed a bug in which it was not possible to customize networkx drawing arguments in nn.models.GNNExplainer.visualize_subgraph() (thanks to @jvansan)
    • transforms.RemoveIsolatedNodes now correctly removes isolated nodes in case data.num_nodes is explicitely set (thanks to @blakechi)
    Source code(tar.gz)
    Source code(zip)
  • 1.7.2(Jun 26, 2021)

    Datasets

    Bugfixes

    • Fixed an error in DeepGCNLayer in case no normalization layer is provided (thanks to @lukasfolle)
    • Fixed a bug in GNNExplainer which mixed the loss computation for graph-level and node-level predictions (thanks to @panisson and @wsad1)
    Source code(tar.gz)
    Source code(zip)
  • 1.7.1(Jun 17, 2021)

    A minor release that brings PyTorch 1.9.0 and Python 3.9 support to PyTorch Geometric. In case you are in the process of updating to PyTorch 1.9.0, please re-install the external dependencies for PyTorch 1.9.0 as well (torch-scatter and torch-sparse).

    Features

    • EGConv (thanks to @shyam196)
    • GATv2Conv (thanks to @shakedbr)
    • GraphNorm normalization layer
    • GNNExplainer now supports explaining graph-level predictions (thanks to @wsad1)
    • bro and gini regularization (thanks to @rhsimplex)
    • train_test_split_edges() and to_undirected() can now edge features (thanks to @saiden89 and @SherylHYX)
    • Datasets can now be accessed with np.ndarray as well (thanks to @josephenguehard)
    • dense_to_sparse can now handle batched adjacency matrices
    • numba is now an optional dependency

    Datasets

    • The tree-structured fake news propagation UPFD dataset (thanks to @YingtongDou)
    • The large-scale AmazonProducts graph from the GraphSAINT paper
    • Added support for two more datasets in the SNAPDataset benchmark suite (thanks to @SherylHYX)

    Issues

    • Fixed an issue in which SuperGATConv used all positive edges for computing the auxiliary loss (thanks to @anniekmyatt)
    • Fixed a bug in which MemPooling produced NaN gradients (thanks to @wsad1)
    • Fixed an issue in which the schnetpack package was required for training SchNet (thanks to @mshuaibii)
    • Modfied XConv to sample without replacement in case dilation > 1 (thanks to @mayur-ag)
    • GraphSAINTSampler can now be used in combination with PyTorch Lightning
    • Fixed a bug in HypergraphConv in case num_nodes > num_edges (thanks to @THinnerichs)
    Source code(tar.gz)
    Source code(zip)
  • 1.7.0(Apr 9, 2021)

    Major Features

    Additional Features

    Minor Changes

    • More memory-efficient implementation of GCN2Conv
    • Improved TransformerConv with the beta argument being input and message dependent (thanks to @ldv1)
    • NeighborSampler now works with SparseTensor and supports an additional transform argument
    • Batch.from_data_list now supports batching along a new dimension via returning None in Data.__cat_dim__, see here for the accompanying tutorial (thanks to @Linux-cpp-lisp)
    • MetaLayer is now "jittable"
    • Lazy loading of torch_geometric.nn and torch_geometric.datasets, leading to faster imports (thanks to @Linux-cpp-lisp)
    • GNNExplainer now supports various output formats of the underlying GNN model (thanks to @wsad1)

    Datasets

    Bugfixes

    Source code(tar.gz)
    Source code(zip)
  • 1.6.3(Dec 2, 2020)

  • 1.6.2(Nov 27, 2020)

    Features

    Minor improvements

    • The SIGN example now operates on mini-batches of nodes
    • Improved data loading runtime of InMemoryDatasets
    • NeighborSampler does now work with SparseTensor as input
    • ToUndirected transform in order to convert directed graphs to undirected ones
    • GNNExplainer does now allow for customizable edge and node feature loss reduction
    • aggr can now passed to any GNN based on the MessagePassing interface (thanks to @m30m)
    • Runtime improvements in SEAL (thanks to @muhanzhang)
    • Runtime improvements in torch_geometric.utils.softmax (thanks to @Book1996)
    • GAE.recon_loss now supports custom negative edge indices (thanks to @reshinthadithyan)
    • Faster spmm computation and random_walk sampling on CPU (torch-sparse and torch-cluster updates required)
    • DataParallel does now support the follow_batch argument
    • Parallel approximate PPR computation in the GDC transform (thanks to @klicperajo)
    • Improved documentation by providing an autosummary of all subpackages (thanks to @m30m)
    • Improved documentation on how edge weights are handled in various GNNs (thanks to @m30m)

    Bugfixes

    • Fixed a bug in GATConv when computing attention coefficients in bipartite graphs
    • Fixed a bug in GraphSAINTSampler that led to wrong edge feature sampling
    • Fixed the DimeNet pretraining link
    • Fixed a bug in processing ego-twitter and ego-gplus of the SNAPDataset collection
    • Fixed a number of broken dataset URLs (ICEWS18, QM9, QM7b, MoleculeNet, Entities, PPI, Reddit, MNISTSuperpixels, ShapeNet)
    • Fixed a bug in which MessagePassing.jittable() tried to write to a file without permission (thanks to @twoertwein)
    • GCNConv does not require edge_weight in case normalize=False
    • Batch.num_graphs will now report the correct amount of graphs in case of zero-sized graphs
    Source code(tar.gz)
    Source code(zip)
  • 1.6.1(Aug 5, 2020)

    This is a minor release, mostly focusing on PyTorch 1.6.0 support. All external wheels are now also available for PyTorch 1.6.0.

    New Features

    Bugfixes

    • Fixed a bug which prevented GNNExplainer to work with GATConv
    • Fixed the MessagePassing.jittable call when installing PyG via pip
    • Fixed a bug in torch-sparse where reduce functions with dim=0 did not yield the correct result
    • Fixed a bug in torch-sparse which suppressed all warnings
    Source code(tar.gz)
    Source code(zip)
  • 1.6.0(Jul 7, 2020)

    A new major release, introducing TorchScript support, memory-efficient aggregations, bipartite GNN modules, static graphs and much more!

    Major Features

    • TorchScript support, see here for the accompanying tutorial (thanks to @lgray and @liaopeiyuan)
    • Memory-efficient aggregations via torch_sparse.SparseTensor, see here for the accompanying tutorial
    • Most GNN modules can now operate on bipartite graphs (and some of them can also operate on different feature dimensionalities for source and target nodes), useful for neighbor sampling or heterogeneous graphs:
    conv = SAGEConv(in_channels=(32, 64), out_channels=64)
    out = conv((x_src, x_dst), edge_index)
    
    • Static graph support:
    conv = GCNConv(in_channels=32, out_channels=64)
    
    x = torch.randn(batch_size, num_nodes, in_channels)
    out = conv(x, edge_index)
    print(out.size())
    >>> torch.Size([batch_size, num_nodes, out_channels])
    

    Additional Features

    Breaking Changes

    Complementary Frameworks

    • DeepSNAP: A PyTorch library that bridges between graph libraries such as NetworkX and PyTorch Geometric
    • PyTorch Geometric Temporal: A temporal GNN library built upon PyTorch Geometric

    Datasets

    Bugfixes

    • Fixed a bug in the VGAE KL-loss computation (thanks to @GuillaumeSalha)
    Source code(tar.gz)
    Source code(zip)
  • 1.5.0(May 25, 2020)

    This release is a big one thanks to many wonderful contributors. You guys are awesome!

    Breaking Changes and Highlights

    • NeighborSampler got completely revamped: it's now much faster, allows for parallel sampling, and allows to easily apply skip-connections or self-loops. See examples/reddit.py or the newly introduced OGB examples (examples/ogbn_products_sage.py and examples/ogbn_products_gat.py). The latter also sets a new SOTA on the OGB leaderboards (reaching 0.7945 ± 0.0059 test accuracy)
    • SAGEConv now uses concat=True by default, and there is no option to disable it anymore
    • Node2Vec got enhanced by a parallel sampling mechanism, and as a result, its API slightly changed
    • MetaPath2Vec: The first model in PyG that is able to operate on heteregenous graphs
    • GNNExplainer: Generating explanations for graph neural networks
    • GraphSAINT: A graph sampling based inductive learning method
    • SchNet model for learning on molecular graphs, comes with pre-trained weights for each target of the QM9 dataset (thanks to @Nyuten)

    Additional Features

    • ASAPooling: Adaptive structure aware pooling for learning hierarchical graph representations (thanks to @ekagra-ranjan)
    • ARGVA node clustering example, see examples/argva_node_clustering.py (thanks to @gsoosk)
    • MFConv: Molecular fingerprint graph convolution operator (thanks to @rhsimplex)
    • GIN-E-Conv that extends the GINConv to also account for edge features
    • DimeNet: Directional message passing for molecular graphs
    • SIGN: Scalable inception graph neural networks
    • GravNetConv (thanks to @jkiesele)

    Datasets

    Minor changes

    • GATConv can now return attention weights via the return_attention_weights argument (thanks to @douglasrizzo)
    • InMemoryDataset now has a copy method that converts sliced datasets back into a contiguous memory layout
    • Planetoid got enhanced by the ability to let users choose between different splitting methods (thanks to @dongkwan-kim)
    • k_hop_subgraph: Computes the k-hop subgraph around a subset of nodes
    • geodesic_distance: Geodesic distances can now be computed in parallel (thanks to @jannessm)
    • tree_decomposition: The tree decompostion algorithm for generating junction trees from molecules
    • SortPool benchmark script now uses 1-D convolutions after pooling, leading to better performance (thanks to @muhanzhang)

    Bugfixes

    • Fixed a bug in write_off
    • Fixed a bug in the processing of the GEDDataset dataset
    • to_networkx conversion can now also properly handle non-tensor attributes
    • Fixed a bug in read_obj (thanks to @mwussow)
    Source code(tar.gz)
    Source code(zip)
  • 1.4.3(Mar 17, 2020)

    Features

    Datasets

    Minor Changes

    Bugfixes

    • Fixed SplineConv compatibility with latest torch-spline-conv package
    • trimesh conversion utilities do not longer result in a permutation of the input data
    Source code(tar.gz)
    Source code(zip)
  • 1.4.2(Feb 18, 2020)

    Minor Changes

    • There are now Python wheels available for torch-scatter and torch-sparse which should make the installation procedure much more user-friendly. Simply run
    pip install torch-scatter==latest+${CUDA} torch-sparse==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.4.0.html
    pip install torch-geometric
    

    where ${CUDA} should be replaced by either cpu, cu92, cu100 or cu101 depending on your PyTorch installation.

    • torch-cluster is now an optional dependency. All methods that rely on torch-cluster will result in an error requesting you to install torch-cluster.
    • torch_geometric.data.Dataset can now also be indexed and shuffled:
    dataset.shuffle()[:50]
    

    Bugfixes

    • Fixed a bug that prevented the user from saving MessagePassing modules.
    • Fixed a bug in RGCNConv when using root_weight=False.
    Source code(tar.gz)
    Source code(zip)
  • 1.4.1(Feb 4, 2020)

    This release mainly focuses on torch-scatter=2.0 support. As a result, PyTorch Geometric now requires PyTorch 1.4. If you are in the process of updating to PyTorch 1.4, please ensure that you also re-install all related external packages.

    Features

    • Graph Diffusion Convolution
    • MinCUT Pooling
    • CGCNNConv
    • TUDataset cleaned versions, containing only non-isomorphic graphs
    • GridSampling transform
    • ShapeNet dataset now comes with normals and better split options
    • TriMesh conversion utilities
    • ToSLIC transform for superpixel generation from images
    • Re-writing of MessagePassing interface with custom aggregate methods (no API changes)

    Bugfixes

    • Fixed some failure modes of from_networkx.
    Source code(tar.gz)
    Source code(zip)
  • 1.3.2(Oct 4, 2019)

    This release focuses on Pytorch 1.2 support and removes all torch.bool deprecation warnings. As a result, this release now requires PyTorch 1.2. If you are in the process of updating to PyTorch 1.2, please ensure that you also re-install all related external packages.

    Overall, this release brings the following new features/bugfixes:

    Features

    • Prints out a warning in case the pre_transform and pre_filter arguments differ from an already processed version

    Bugfixes

    • Removed all torch.bool deprecation warnings
    • Fixed ARGA initialization bug
    • Fixed a pre-processing bug in QM9
    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Aug 29, 2019)

    This is a minor release which is mostly distributed for official PyTorch 1.2 support. In addition, it provides minor bugfixes and the following new features:

    Modules

    • Non-normalized ChebConv in combination with a largest eigenvalue transform
    • TAGCN
    • Graph U-Net
    • Node2Vec
    • EdgePooling
    • Alternative GMMConv formulation with separate kernels
    • Alternative Top-K pooling formulation based on thresholds with examples on synthetic COLORS and TRIANGLES datasets

    Datasets

    • Pascal VOC 2011 with Berkeley keypoint annotations (PascalVOCKeypoints)
    • DBP15K dataset
    • WILLOWObjectClass dataset

    Please also update related external packages via, e.g.:

    $ pip install --upgrade torch-cluster
    
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Jun 29, 2019)

    • Support for giant graph handling using NeighborSampler and bipartite message passing operators
    • Debugging support using the new debug API
    • Fixed TUDataset download errors
    • Added FeasStConv module
    • Improved networkx conversion functionality
    • Improved Data and DataLoader handling with customizable number_of_nodes (e.g. for holding two graphs in a single Data object)
    • Added GeniePath example
    • Added SAGPool module
    • Added geodesic distance computation using gdist (optional)
    • Improved PointNet and DGCNN classification and segmentation examples
    • Added subgraph functionality
    • Fixed GMMConv
    • Added a bunch of new datasets
    • Added fast implementations for random graph generation
    • Improved loop API
    • Minor bugfixes

    Thanks to all contributors!

    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(May 22, 2019)

    • More convenient self-loop API (including addition of edge weights)
    • Small bugfixes, .e.g., DiffPool NaNs and empty edge indices treatment
    • New datasets have been added:
      • GEDDataset
      • DynamicFAUST
      • TOSCA
      • SHREC2016
    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Apr 29, 2019)

  • 1.1.2(Apr 5, 2019)

  • 1.1.1(Apr 2, 2019)

  • 1.1.0(Apr 1, 2019)

    This release includes:

    • All Variants of Graph Autoencoders
    • Gated Graph Conv
    • DataParallel bugfixes
    • New transforms (Line Graph Transformation, Local Degree Profile, Sample Points with Normals)
    • PointNet++ example
    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Mar 7, 2019)

  • 1.0.2(Jan 25, 2019)

  • 1.0.1(Jan 15, 2019)

    • Finally completed documentation
    • Finally achieved 100% code coverage (every single line is tested)
    • Fixed a few minor bugs
    • Added the GlobalAttention layer from Li et al.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Dec 18, 2018)

    We made a bunch of improvements to PyTorch Geometric and added various new convolution and pooling operators, e.g., top_k pooling, PointCNN, Iterative Farthest Point Sampling, PointNet++, ...

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Oct 20, 2018)

    • minor bug fixes (e.g. calls to torch-sparse had wrong argument order)
    • new operators and examples (GINConv and Infomax example)
    • added helpful evaluation functions
    Source code(tar.gz)
    Source code(zip)
Owner
Matthias Fey
PhD student @ TU Dortmund University - Interested in Representation Learning on Graphs and Manifolds; PyTorch, CUDA, Vim and macOS Enthusiast
Matthias Fey
A geometric deep learning pipeline for predicting protein interface contacts.

A geometric deep learning pipeline for predicting protein interface contacts.

null 43 Sep 1, 2022
Implementation of Geometric Vector Perceptron, a simple circuit for 3d rotation equivariance for learning over large biomolecules, in Pytorch. Idea proposed and accepted at ICLR 2021

Geometric Vector Perceptron Implementation of Geometric Vector Perceptron, a simple circuit with 3d rotation equivariance for learning over large biom

Phil Wang 56 Sep 2, 2022
Code for "SRHEN: Stepwise-Refining Homography Estimation Network via Parsing Geometric Correspondences in Deep Latent Space"

SRHEN This is a better and simpler implementation for "SRHEN: Stepwise-Refining Homography Estimation Network via Parsing Geometric Correspondences in

null 0 Jan 18, 2022
Contains code for Deep Kernelized Dense Geometric Matching

DKM - Deep Kernelized Dense Geometric Matching Contains code for Deep Kernelized Dense Geometric Matching We provide pretrained models and code for ev

Johan Edstedt 67 Sep 21, 2022
A PyTorch implementation of "DGC-Net: Dense Geometric Correspondence Network"

DGC-Net: Dense Geometric Correspondence Network This is a PyTorch implementation of our work "DGC-Net: Dense Geometric Correspondence Network" TL;DR A

null 188 Sep 28, 2022
Pytorch Geometric Tutorials

Pytorch Geometric Tutorials

Antonio Longa 553 Sep 22, 2022
TorchX: A PyTorch Extension Library for More Efficient Deep Learning

TorchX TorchX: A PyTorch Extension Library for More Efficient Deep Learning. @misc{torchx, author = {Ansheng You and Changxu Wang}, title = {T

Donny You 8 May 28, 2022
Geometric Vector Perceptron --- a rotation-equivariant GNN for learning from biomolecular structure

Geometric Vector Perceptron Code to accompany Learning from Protein Structure with Geometric Vector Perceptrons by B Jing, S Eismann, P Suriana, RJL T

Dror Lab 72 Sep 27, 2022
Geometric Vector Perceptrons --- a rotation-equivariant GNN for learning from biomolecular structure

Geometric Vector Perceptron Implementation of equivariant GVP-GNNs as described in Learning from Protein Structure with Geometric Vector Perceptrons b

Dror Lab 123 Sep 23, 2022
Multi-Scale Geometric Consistency Guided Multi-View Stereo

ACMM [News] The code for ACMH is released!!! [News] The code for ACMP is released!!! About ACMM is a multi-scale geometric consistency guided multi-vi

Qingshan Xu 112 Sep 16, 2022
Code for "FGR: Frustum-Aware Geometric Reasoning for Weakly Supervised 3D Vehicle Detection", ICRA 2021

FGR This repository contains the python implementation for paper "FGR: Frustum-Aware Geometric Reasoning for Weakly Supervised 3D Vehicle Detection"(I

Yi Wei 30 Jun 1, 2022
Certifiable Outlier-Robust Geometric Perception

Certifiable Outlier-Robust Geometric Perception About This repository holds the implementation for certifiably solving outlier-robust geometric percep

null 77 Sep 26, 2022
3DMV jointly combines RGB color and geometric information to perform 3D semantic segmentation of RGB-D scans.

3DMV 3DMV jointly combines RGB color and geometric information to perform 3D semantic segmentation of RGB-D scans. This work is based on our ECCV'18 p

Владислав Молодцов 0 Feb 6, 2022
Geometric Algebra package for JAX

JAXGA - JAX Geometric Algebra GitHub | Docs JAXGA is a Geometric Algebra package on top of JAX. It can handle high dimensional algebras by storing onl

Robin Kahlow 8 Jul 22, 2022
Computational modelling of ray propagation through optical elements using the principles of geometric optics (Ray Tracer)

Computational modelling of ray propagation through optical elements using the principles of geometric optics (Ray Tracer) Introduction By applying the

Son Gyo Jung 1 Jul 9, 2022
GeoTransformer - Geometric Transformer for Fast and Robust Point Cloud Registration

Geometric Transformer for Fast and Robust Point Cloud Registration PyTorch imple

Zheng Qin 173 Sep 27, 2022
Buffon’s needle: one of the oldest problems in geometric probability

Buffon-s-Needle Buffon’s needle is one of the oldest problems in geometric proba

null 3 Feb 18, 2022
Implementation of GeoDiff: a Geometric Diffusion Model for Molecular Conformation Generation (ICLR 2022).

GeoDiff: a Geometric Diffusion Model for Molecular Conformation Generation [OpenReview] [arXiv] [Code] The official implementation of GeoDiff: A Geome

Minkai Xu 107 Sep 19, 2022
DeepProbLog is an extension of ProbLog that integrates Probabilistic Logic Programming with deep learning by introducing the neural predicate.

DeepProbLog DeepProbLog is an extension of ProbLog that integrates Probabilistic Logic Programming with deep learning by introducing the neural predic

KU Leuven Machine Learning Research Group 79 Sep 8, 2022