Skip to content

Cleanup examples #10097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5e73c3c
cleanup 9 gnn models on cora dataset
xnuohz Mar 1, 2025
81ee836
dna, super_gat
xnuohz Mar 1, 2025
7540ad8
gat, gcn
xnuohz Mar 1, 2025
4ac9df4
node2vec
xnuohz Mar 1, 2025
29b6766
align with ogbn train
xnuohz Mar 1, 2025
9742f25
update readme
xnuohz Mar 2, 2025
1a8909e
update
xnuohz Mar 2, 2025
cb944ba
Merge branch 'master' into examples/cleanup
xnuohz Mar 5, 2025
b47cf2d
update
xnuohz Mar 5, 2025
a122eb5
update
xnuohz Mar 5, 2025
765d296
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 5, 2025
ad43f2c
Merge branch 'master' into examples/cleanup
xnuohz Mar 6, 2025
f3962c4
add readme
xnuohz Mar 7, 2025
6c10b3b
add type hints
xnuohz Mar 8, 2025
1497633
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 8, 2025
768b257
update
xnuohz Mar 8, 2025
47cd6f4
Merge branch 'examples/cleanup' of github.com:xnuohz/pytorch_geometri…
xnuohz Mar 8, 2025
01ebfc0
update
xnuohz Mar 8, 2025
a96ec03
update
xnuohz Mar 8, 2025
abe9260
update
xnuohz Mar 9, 2025
f8113a3
update
xnuohz Mar 9, 2025
b7fd052
update
xnuohz Mar 9, 2025
d4dcfdc
update
xnuohz Mar 9, 2025
2151f4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 9, 2025
65e67bf
update
xnuohz Mar 10, 2025
c51ba59
Merge branch 'master' into examples/cleanup
puririshi98 Mar 13, 2025
eb66552
Update CHANGELOG.md
xnuohz Mar 14, 2025
9bdfc6e
delete useless files and update changelog
xnuohz Mar 15, 2025
a941d82
fix broken tj-action/changed-files
xnuohz Mar 16, 2025
c29ffbd
update readme
xnuohz Mar 16, 2025
6b287d7
restore
xnuohz Mar 18, 2025
3074d70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 18, 2025
a5945f7
Restore individual examples (#2)
xnuohz Mar 18, 2025
73a6380
update
xnuohz Mar 18, 2025
7d9ba54
update
xnuohz Mar 18, 2025
c445ffb
Merge branch 'master' into examples/cleanup
puririshi98 Mar 19, 2025
44293f9
Merge branch 'master' into examples/cleanup
xnuohz Mar 20, 2025
d829ec6
update
xnuohz Mar 22, 2025
242fa69
Merge branch 'master' into examples/cleanup
puririshi98 Mar 26, 2025
6f4d0ab
Update README.md
puririshi98 Mar 26, 2025
84b1d26
update
xnuohz Mar 27, 2025
e2d2ff6
Merge branch 'master' into examples/cleanup
xnuohz Apr 7, 2025
09d4f62
Merge branch 'master' into examples/cleanup
xnuohz Apr 7, 2025
48d29cb
Merge branch 'master' into examples/cleanup
xnuohz Apr 8, 2025
219eece
Merge branch 'master' into examples/cleanup
xnuohz Apr 11, 2025
cc2d718
Merge branch 'master' into examples/cleanup
puririshi98 Apr 22, 2025
a60007e
Merge branch 'master' into examples/cleanup
puririshi98 May 1, 2025
976cd71
update
xnuohz May 1, 2025
0e7430a
update
xnuohz May 1, 2025
aba6642
Merge branch 'master' into examples/cleanup
puririshi98 May 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ jobs:

- name: Run GCN on Cora
run: |
python examples/gcn.py --wandb
python examples/planetoid_train.py --gnn_choice gcn --dataset Cora --wandb
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}

- name: Run GAT on Cora
run: |
python examples/gat.py --wandb
python examples/planetoid_train.py --gnn_choice gat --dataset Cora --wandb

env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}

Expand Down
30 changes: 15 additions & 15 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ To build the container, run
then wait. Once finished, you can run the GAT example in the folder you built the image in by calling

```
wget https://raw.githubusercontent.com/pyg-team/pytorch_geometric/master/examples/gat.py
wget https://raw.githubusercontent.com/pyg-team/pytorch_geometric/master/examples/planetoid_train.py
```

(to download the sample),

then

```
singularity exec geometric.sif python3 gat.py
singularity exec geometric.sif python3 planetoid_train.py --gnn_choice gat
```

to run on the CPU, or

```
singularity exec --nv geometric.sif python3 gat.py
singularity exec --nv geometric.sif python3 planetoid_train.py --gnn_choice gat
```

to run on the GPU.
2 changes: 1 addition & 1 deletion docs/source/advanced/compile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Exampe Scripts

We have incorporated multiple examples in :obj:`examples/compile` that further show the practical usage of :meth:`torch.compile`:

#. `Node Classification <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/compile/gcn.py>`__ via :class:`~torch_geometric.nn.models.GCN` (:obj:`dynamic=False`)
#. `Node Classification <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/compile/planetoid_train.py>`__ via :class:`~torch_geometric.nn.models.GCN` (:obj:`dynamic=False`)
#. `Graph Classification <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/compile/gin.py>`__ via :class:`~torch_geometric.nn.models.GIN` (:obj:`dynamic=True`)

If you notice that :meth:`torch.compile` fails for a certain :pyg:`PyG` model, do not hesitate to reach out either on :github:`null` `GitHub <https://github.com/pyg-team/pytorch_geometric/issues>`_ or :slack:`null` `Slack <https://data.pyg.org/slack.html>`_.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/dataset_splitting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Node Prediction
.. note::

In this section, we'll learn how to use :class:`~torch_geometric.transforms.RandomNodeSplit` of :pyg:`PyG` to randomly divide nodes into training, validation, and test sets.
A fully working example on dataset :class:`~torch_geometric.datasets.Planetoid` is available in `examples/cora.py <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/cora.py>`_.
A fully working example on dataset :class:`~torch_geometric.datasets.Planetoid` is available in `examples/planetoid_train.py <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/planetoid_train.py>`_.

The :class:`~torch_geometric.transforms.RandomNodeSplit` is initialized to split nodes for both a :pyg:`PyG` :class:`~torch_geometric.data.Data` and :class:`~torch_geometric.data.HeteroData` object.

Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorial/neighbor_loader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Scaling GNNs via Neighbor Sampling

One of the challenges of Graph Neural Networks is to scale them to large graphs, *e.g.*, in industrial and social applications.
Traditional deep neural networks are known to scale well to large amounts of data by decomposing the training loss into individual samples (called a *mini-batch*) and approximating exact gradients stochastically.
In contrast, applying stochastic mini-batch training in GNNs is challenging since the embedding of a given node depends recursively on all its neighbors embeddings, leading to high inter-dependency between nodes that grows exponentially with respect to the number of layers.
In contrast, applying stochastic mini-batch training in GNNs is challenging since the embedding of a given node depends recursively on all its neighbor's embeddings, leading to high inter-dependency between nodes that grows exponentially with respect to the number of layers.
This phenomenon is often referred to as *neighbor explosion*.
As a simple workaround, GNNs are typically executed in a full-batch fashion (see `here <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/gcn.py>`_ for an example), where the GNN has access to all hidden node representations in all its layers.
As a simple workaround, GNNs are typically executed in a full-batch fashion (see `here <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/planetoid_train.py>`_ for an example), where the GNN has access to all hidden node representations in all its layers.
However, this is not feasible in large-scale graphs due to memory limitations and slow convergence.

Scalability techniques are indispensable for applying GNNs to large-scale graphs in order to alleviate the neighbor explosion problem induced by mini-batch training, *i.e.* **node-wise**, **layer-wise** or **subgraph-wise** sampling techniques, or to **decouple propagations from predictions**.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/shallow_node_embeddings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Node2Vec
.. note::

In this section of the tutorial, we will learn node embeddings for **homogenous graphs** using the :class:`~torch_geometric.nn.models.Node2Vec` module of :pyg:`PyG`.
The code is available in `examples/node2vec.py <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/node2vec.py>`_ and as a `Google Colab tutorial notebook <https://colab.research.google.com/github/AntonioLonga/PytorchGeometricTutorial/blob/main/Tutorial11/Tutorial11.ipynb>`_.
The code is available in `examples/planetoid_train.py <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/planetoid_train.py>`_ and as a `Google Colab tutorial notebook <https://colab.research.google.com/github/AntonioLonga/PytorchGeometricTutorial/blob/main/Tutorial11/Tutorial11.ipynb>`_.

:class:`~torch_geometric.nn.models.Node2Vec` is a method for learning shallow node embeddings, which allows for flexible
control of random walk procedures based on breadth-first or depth-first samplers.
Expand Down
25 changes: 24 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This folder contains a plethora of examples covering different GNN use-cases.
This readme highlights some key examples.

A great and simple example to start with is [`gcn.py`](./gcn.py), showing a user how to train a [`GCN`](https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.models.GCN.html) model for node-level prediction on small-scale homogeneous data.
A great and simple example to start with is [`planetoid_train.py`](./planetoid_train.py), showing a user how to train a [`GCN`](https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.models.GCN.html) model for node-level prediction on small-scale homogeneous data.

For a simple link prediction example, see [`link_pred.py`](./link_pred.py).

Expand All @@ -22,3 +22,26 @@ For examples on scaling PyG up via multi-GPUs, see the examples under [`examples
For examples on working with heterogeneous data, see the examples under [`examples/hetero`](./hetero).

For examples on co-training LLMs with GNNs, see the examples under [`examples/llm`](./llm).

# Results

```
python examples/planetoid_train.py --gnn_choice {model} --dataset {dataset}
```

| Model | Cora | CiteSeer | PubMed |
| --------- | ---------- | ---------- | ---------- |
| GCN | 83.80% | 72.40% | 87.20% |
| GAT | 91.40% | 76.00% | 84.20% |
| AGNN | 92.00% | 77.20% | 87.80% |
| ARMA | 88.60% | 74.40% | 86.60% |
| MixHop | 91.40% | 75.80% | 84.60% |
| SGC | 64.00% | 73.60% | 77.00% |
| TAGCN | 91.20% | 73.80% | **89.00%** |
| GraphUNet | 90.20% | 77.20% | 85.20% |
| PMLP | 90.40% | **77.40%** | 84.60% |
| SplineGNN | 91.60% | **77.40%** | 87.60% |
| GCN2 | **92.80%** | 75.60% | 84.60% |
| SuperGAT | 88.20% | 74.40% | 80.60% |
| DNA | 90.00% | 75.20% | 85.80% |
| Node2Vec | 84.00% | 55.60% | 76.80% |
65 changes: 0 additions & 65 deletions examples/agnn.py

This file was deleted.

74 changes: 0 additions & 74 deletions examples/arma.py

This file was deleted.

65 changes: 0 additions & 65 deletions examples/cora.py

This file was deleted.

Loading
Loading