From 5ae3f2e0802ed3c2f11be992933cfc77fe9a93d5 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Thu, 19 Jan 2023 12:28:22 +0530 Subject: [PATCH 01/21] Update CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6943821a64d7..266251f7d168 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,9 @@ If you are interested in contributing to PyG, your contributions will likely fal 1. You want to implement a new feature: - In general, we accept any features as long as they fit the scope of this package. If you are unsure about this or need help on the design/implementation of your feature, post about it in an issue. 2. You want to fix a bug: - - Feel free to send a Pull Request any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. + - Feel free to send a Pull Request(PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. -Once you finish implementing a feature or bug-fix, please send a Pull Request to https://github.com/pyg-team/pytorch_geometric. +Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). Sometimes PR merges get delayed due to its large size, complexity or unavailabiltiy of reviewers, in such cases you can move your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. ## Developing PyG From 13b118869a8d012d47c8e49f0aad3345991e8419 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Jan 2023 06:59:25 +0000 Subject: [PATCH 02/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 266251f7d168..64f6edad1c38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ If you are interested in contributing to PyG, your contributions will likely fal 2. You want to fix a bug: - Feel free to send a Pull Request(PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. -Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). Sometimes PR merges get delayed due to its large size, complexity or unavailabiltiy of reviewers, in such cases you can move your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. +Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). Sometimes PR merges get delayed due to its large size, complexity or unavailabiltiy of reviewers, in such cases you can move your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. ## Developing PyG From b145737cdc5bb23879e5c337606eaf4693997c59 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Thu, 19 Jan 2023 12:37:54 +0530 Subject: [PATCH 03/21] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64f6edad1c38..da6bdbcaf74e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ If you are interested in contributing to PyG, your contributions will likely fal 2. You want to fix a bug: - Feel free to send a Pull Request(PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. -Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). Sometimes PR merges get delayed due to its large size, complexity or unavailabiltiy of reviewers, in such cases you can move your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. +Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). If your PR isn't merged in around 4 weeks, due to its large size, complexity or unavailabiltiy of reviewers. Try moving your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. ## Developing PyG From d18da58572703a8776faeb048a960d78fe94709e Mon Sep 17 00:00:00 2001 From: rusty1s Date: Thu, 19 Jan 2023 08:46:27 +0000 Subject: [PATCH 04/21] update --- CONTRIBUTING.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index da6bdbcaf74e..1eb249cb57a9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,12 @@ If you are interested in contributing to PyG, your contributions will likely fal 1. You want to implement a new feature: - In general, we accept any features as long as they fit the scope of this package. If you are unsure about this or need help on the design/implementation of your feature, post about it in an issue. 2. You want to fix a bug: - - Feel free to send a Pull Request(PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. + - Feel free to send a Pull Request (PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. -Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. Your PR will be merged after 1 or more rounds of reveiws by the [pyg_team](https://github.com/pyg-team). If your PR isn't merged in around 4 weeks, due to its large size, complexity or unavailabiltiy of reviewers. Try moving your contribution to [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html). [torch_geometric.contrib](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. +Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch\_geometric. +Your PR will be merged after 1 or more rounds of reveiws by the [pyg-team](https://github.com/pyg-team). +If your PR isn't merged in anytime soon (*e.g.,* due to its large size, complexity or unavailability of reviewers), try moving your contribution to the [`torch_geometric.contrib`](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) package. +[`torch_geometric.contrib`](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. ## Developing PyG From bf0f30c45ff6d2ad554194e41ced334af3f13a28 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Thu, 19 Jan 2023 08:47:42 +0000 Subject: [PATCH 05/21] update --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1eb249cb57a9..08e562311fb2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,9 +7,9 @@ If you are interested in contributing to PyG, your contributions will likely fal 2. You want to fix a bug: - Feel free to send a Pull Request (PR) any time you encounter a bug. Please provide a clear and concise description of what the bug was. If you are unsure about if this is a bug at all or how to fix, post about it in an issue. -Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch\_geometric. -Your PR will be merged after 1 or more rounds of reveiws by the [pyg-team](https://github.com/pyg-team). -If your PR isn't merged in anytime soon (*e.g.,* due to its large size, complexity or unavailability of reviewers), try moving your contribution to the [`torch_geometric.contrib`](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) package. +Once you finish implementing a feature or bug-fix, please send a PR to https://github.com/pyg-team/pytorch_geometric. +Your PR will be merged after one or more rounds of reviews by the [pyg-team](https://github.com/pyg-team). +If your PR isn't merged anytime soon (*e.g.,* due to its large size, complexity or unavailability of reviewers), try moving your contribution to the [`torch_geometric.contrib`](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) package. [`torch_geometric.contrib`](https://pytorch-geometric.readthedocs.io/en/latest/modules/contrib.html) has less rigourous review requirements and might lead to your PR getting merged faster. ## Developing PyG From b9244daaffc08253c245ca1d19d8f4a744b5e4c0 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Fri, 3 Feb 2023 18:52:09 +0530 Subject: [PATCH 06/21] link medium blog. --- docs/source/tutorial/explain.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index af83c0645dd6..5e87c5a0d333 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -32,6 +32,9 @@ The :class:`torch_geometric.explain.Explainer` class is designed to handle all e This class allows the user to easily compare different explainability methods and to easily switch between different types of masks, while making sure the high-level framework stays the same. The :class:`~torch_geometric.explain.Explainer` generates an :class:`~torch_geometric.explain.Explanation` or :class:`~torch_geometric.explain.HeteroExplanation` object which contains the final information about which nodes, edges and features are crucial to explain a GNN model. +Check out this [blog](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2) to understand the desing of the +`torch_geometric.explain` module. Below we discuss a few use cases with code. + Examples -------- From a14b9c58081e3517327556ba882f44d3bb11e03b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Feb 2023 13:23:11 +0000 Subject: [PATCH 07/21] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/tutorial/explain.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index 5e87c5a0d333..2944de870c53 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -32,8 +32,8 @@ The :class:`torch_geometric.explain.Explainer` class is designed to handle all e This class allows the user to easily compare different explainability methods and to easily switch between different types of masks, while making sure the high-level framework stays the same. The :class:`~torch_geometric.explain.Explainer` generates an :class:`~torch_geometric.explain.Explanation` or :class:`~torch_geometric.explain.HeteroExplanation` object which contains the final information about which nodes, edges and features are crucial to explain a GNN model. -Check out this [blog](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2) to understand the desing of the -`torch_geometric.explain` module. Below we discuss a few use cases with code. +Check out this [blog](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2) to understand the desing of the +`torch_geometric.explain` module. Below we discuss a few use cases with code. Examples -------- From 51b2e1914868f3a1c8d88dc3e7c29649d31398ef Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Fri, 3 Feb 2023 18:57:32 +0530 Subject: [PATCH 08/21] Update nn.rst --- docs/source/modules/nn.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index 59b5331e43c4..2a3a5e08fd14 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -144,6 +144,8 @@ For combining via attention, we need to additionally specify the :obj:`in_channe If aggregations are given as a list, they will be automatically resolved to a :class:`~torch_geometric.nn.aggr.MultiAggregation`, *e.g.*, :obj:`aggr=['mean', 'std', 'median']`. +Read more about the `Aggregation` package in this [blog](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). + Finally, we added full support for customization of aggregations into the :class:`~torch_geometric.nn.conv.SAGEConv` layer --- simply override its :obj:`aggr` argument and **utilize the power of aggregation within your GNN**. .. autosummary:: From 30b599e48d3d30fbc66c234f26f89ecac5b18ce8 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Fri, 3 Feb 2023 16:27:54 +0000 Subject: [PATCH 09/21] update --- docs/source/modules/nn.rst | 4 ++-- docs/source/tutorial/explain.rst | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index 2a3a5e08fd14..c0012b9f32af 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -144,10 +144,10 @@ For combining via attention, we need to additionally specify the :obj:`in_channe If aggregations are given as a list, they will be automatically resolved to a :class:`~torch_geometric.nn.aggr.MultiAggregation`, *e.g.*, :obj:`aggr=['mean', 'std', 'median']`. -Read more about the `Aggregation` package in this [blog](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). - Finally, we added full support for customization of aggregations into the :class:`~torch_geometric.nn.conv.SAGEConv` layer --- simply override its :obj:`aggr` argument and **utilize the power of aggregation within your GNN**. +You can read more about the :class:`~torch_geometric.nn.aggr` package in this [blog post](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). + .. autosummary:: :nosignatures: :toctree: ../generated diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index 2944de870c53..19205671dadc 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -32,12 +32,13 @@ The :class:`torch_geometric.explain.Explainer` class is designed to handle all e This class allows the user to easily compare different explainability methods and to easily switch between different types of masks, while making sure the high-level framework stays the same. The :class:`~torch_geometric.explain.Explainer` generates an :class:`~torch_geometric.explain.Explanation` or :class:`~torch_geometric.explain.HeteroExplanation` object which contains the final information about which nodes, edges and features are crucial to explain a GNN model. -Check out this [blog](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2) to understand the desing of the -`torch_geometric.explain` module. Below we discuss a few use cases with code. +You can read more about the :class:`~torch_geometric.explain` package in this [blog post](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2). Examples -------- +In what follows, we discuss a few use-codes with code. + Explaining node classification on a homogeneous graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From e3f3fc687fdc88b47a0d677d7f3e642f3ec0d838 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Fri, 3 Feb 2023 16:28:20 +0000 Subject: [PATCH 10/21] update --- docs/source/modules/nn.rst | 2 +- docs/source/tutorial/explain.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index c0012b9f32af..32b38a0c1eb4 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -146,7 +146,7 @@ If aggregations are given as a list, they will be automatically resolved to a :c Finally, we added full support for customization of aggregations into the :class:`~torch_geometric.nn.conv.SAGEConv` layer --- simply override its :obj:`aggr` argument and **utilize the power of aggregation within your GNN**. -You can read more about the :class:`~torch_geometric.nn.aggr` package in this [blog post](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). +You can read more about the :class:`torch_geometric.nn.aggr` package in this [blog post](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). .. autosummary:: :nosignatures: diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index 19205671dadc..bf752028794e 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -32,7 +32,7 @@ The :class:`torch_geometric.explain.Explainer` class is designed to handle all e This class allows the user to easily compare different explainability methods and to easily switch between different types of masks, while making sure the high-level framework stays the same. The :class:`~torch_geometric.explain.Explainer` generates an :class:`~torch_geometric.explain.Explanation` or :class:`~torch_geometric.explain.HeteroExplanation` object which contains the final information about which nodes, edges and features are crucial to explain a GNN model. -You can read more about the :class:`~torch_geometric.explain` package in this [blog post](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2). +You can read more about the :class:`torch_geometric.explain` package in this [blog post](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2). Examples -------- From b8640ef6a350d9df874a4ef2da41d3d5ac7cd017 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Fri, 3 Feb 2023 16:28:36 +0000 Subject: [PATCH 11/21] update --- docs/source/tutorial/explain.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index bf752028794e..013cac43b2b0 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -37,7 +37,7 @@ You can read more about the :class:`torch_geometric.explain` package in this [bl Examples -------- -In what follows, we discuss a few use-codes with code. +In what follows, we discuss a few use-cases with corresponding code examples. Explaining node classification on a homogeneous graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From bb74e0cfed5f5552c724d1c7bca7380840bb7fda Mon Sep 17 00:00:00 2001 From: rusty1s Date: Fri, 3 Feb 2023 16:29:34 +0000 Subject: [PATCH 12/21] update --- docs/source/modules/nn.rst | 4 +++- docs/source/tutorial/explain.rst | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index 32b38a0c1eb4..dae310386832 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -146,7 +146,9 @@ If aggregations are given as a list, they will be automatically resolved to a :c Finally, we added full support for customization of aggregations into the :class:`~torch_geometric.nn.conv.SAGEConv` layer --- simply override its :obj:`aggr` argument and **utilize the power of aggregation within your GNN**. -You can read more about the :class:`torch_geometric.nn.aggr` package in this [blog post](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). +.. note:: + + You can read more about the :class:`torch_geometric.nn.aggr` package in this [blog post](https://medium.com/@pytorch_geometric/a-principled-approach-to-aggregations-983c086b10b3). .. autosummary:: :nosignatures: diff --git a/docs/source/tutorial/explain.rst b/docs/source/tutorial/explain.rst index 013cac43b2b0..96a6cf15e62e 100644 --- a/docs/source/tutorial/explain.rst +++ b/docs/source/tutorial/explain.rst @@ -14,7 +14,7 @@ Interpreting GNN models is crucial for many use cases. .. warning:: - The explanation APIs discussed here may change in the future as we continuously work to improve their ease-of-use and generalizability. + The explanation APIs discussed here may change in the future as we continuously work to improve their ease-of-use and generalizability. Explainer Interface ------------------- @@ -32,7 +32,9 @@ The :class:`torch_geometric.explain.Explainer` class is designed to handle all e This class allows the user to easily compare different explainability methods and to easily switch between different types of masks, while making sure the high-level framework stays the same. The :class:`~torch_geometric.explain.Explainer` generates an :class:`~torch_geometric.explain.Explanation` or :class:`~torch_geometric.explain.HeteroExplanation` object which contains the final information about which nodes, edges and features are crucial to explain a GNN model. -You can read more about the :class:`torch_geometric.explain` package in this [blog post](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2). +.. note:: + + You can read more about the :class:`torch_geometric.explain` package in this [blog post](https://medium.com/@pytorch_geometric/graph-machine-learning-explainability-with-pyg-ff13cffc23c2). Examples -------- From 30428de0cccf177b0d309b1a4ea7c44d5a7a5285 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Sat, 4 Feb 2023 17:08:43 +0530 Subject: [PATCH 13/21] add model hub to docs. --- docs/source/modules/nn.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index dae310386832..3912e41cdc99 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -6,6 +6,8 @@ torch_geometric.nn .. autoclass:: torch_geometric.nn.sequential.Sequential +.. autoclass:: torch_geometric.nn.model_hub.PyGModelHubMixin + .. currentmodule:: torch_geometric.nn.dense {% for name in torch_geometric.nn.dense.lin_classes %} From 0c3643e56d940653f5a1c90aca043407d62c134c Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Mon, 6 Feb 2023 13:25:40 +0530 Subject: [PATCH 14/21] Update setup.py --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 0032c589e4b7..a01e6d7aad23 100644 --- a/setup.py +++ b/setup.py @@ -22,8 +22,6 @@ 'pytorch-lightning', ] -huggingface_requires = ['huggingface_hub'] - full_requires = graphgym_requires + huggingface_requires + [ 'ase', 'h5py', @@ -42,6 +40,7 @@ 'pgmpy', 'opt_einsum', # required for pgmpy 'statsmodels', + 'huggingface_hub', ] benchmark_requires = [ @@ -82,7 +81,6 @@ install_requires=install_requires, extras_require={ 'graphgym': graphgym_requires, - 'huggingface': huggingface_requires, 'full': full_requires, 'benchmark': benchmark_requires, 'test': test_requires, From cc5e05c9e719d2e065672846c56d54587a65812e Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Mon, 6 Feb 2023 13:27:09 +0530 Subject: [PATCH 15/21] Update __init__.py --- torch_geometric/nn/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch_geometric/nn/__init__.py b/torch_geometric/nn/__init__.py index 572425618811..79d541b9b0ce 100644 --- a/torch_geometric/nn/__init__.py +++ b/torch_geometric/nn/__init__.py @@ -6,6 +6,7 @@ from .to_fixed_size_transformer import to_fixed_size from .encoding import PositionalEncoding from .summary import summary +from .model_hub import PyGModelHubMixin from .aggr import * # noqa from .conv import * # noqa @@ -27,4 +28,5 @@ 'to_fixed_size', 'PositionalEncoding', 'summary', + 'PyGModelHubMixin', ] From 3f5c2e614eda268ca3276a1d182fffe476f848d1 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Mon, 6 Feb 2023 13:30:09 +0530 Subject: [PATCH 16/21] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a01e6d7aad23..10a103ce78b6 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ 'pytorch-lightning', ] -full_requires = graphgym_requires + huggingface_requires + [ +full_requires = graphgym_requires + [ 'ase', 'h5py', 'numba', From 8ac70fed0aeb6d0715af513b9a952f9d00273770 Mon Sep 17 00:00:00 2001 From: Jinu Sunil Date: Mon, 6 Feb 2023 13:39:28 +0530 Subject: [PATCH 17/21] Update model_hub.py --- torch_geometric/nn/model_hub.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/torch_geometric/nn/model_hub.py b/torch_geometric/nn/model_hub.py index 773cc32cdb70..09f01f5adc28 100644 --- a/torch_geometric/nn/model_hub.py +++ b/torch_geometric/nn/model_hub.py @@ -3,16 +3,12 @@ from typing import Dict, Optional, Union import torch - -try: - from huggingface_hub import ( - ModelCard, - ModelCardData, - ModelHubMixin, - hf_hub_download, - ) -except ImportError: - raise ImportError("'PyGModelHubMixin' requires 'huggingface_hub'") +from huggingface_hub import ( + ModelCard, + ModelCardData, + ModelHubMixin, + hf_hub_download, +) CONFIG_NAME = 'config.json' MODEL_HUB_ORGANIZATION = "pytorch_geometric" From 0c208ba1811f8a0e5aca4baebacc75351c82842f Mon Sep 17 00:00:00 2001 From: rusty1s Date: Wed, 8 Feb 2023 14:28:15 +0000 Subject: [PATCH 18/21] update --- setup.py | 1 - torch_geometric/nn/__init__.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a3be155298e4..b1caff238a43 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,6 @@ 'pgmpy', 'opt_einsum', # required for pgmpy 'statsmodels', - 'huggingface_hub', ] benchmark_requires = [ diff --git a/torch_geometric/nn/__init__.py b/torch_geometric/nn/__init__.py index 79d541b9b0ce..c3cb5d2cf7cf 100644 --- a/torch_geometric/nn/__init__.py +++ b/torch_geometric/nn/__init__.py @@ -5,8 +5,8 @@ from .to_hetero_with_bases_transformer import to_hetero_with_bases from .to_fixed_size_transformer import to_fixed_size from .encoding import PositionalEncoding -from .summary import summary from .model_hub import PyGModelHubMixin +from .summary import summary from .aggr import * # noqa from .conv import * # noqa @@ -27,6 +27,6 @@ 'to_hetero_with_bases', 'to_fixed_size', 'PositionalEncoding', - 'summary', 'PyGModelHubMixin', + 'summary', ] From 03127757e22ea7bd4fc7f9b6d8ac83187dc443ca Mon Sep 17 00:00:00 2001 From: rusty1s Date: Wed, 8 Feb 2023 14:28:54 +0000 Subject: [PATCH 19/21] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 204f27ae0fd7..0453efd13278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `cat` aggregation type to the `HeteroConv` class so that features can be concatenated during grouping ([#6634](https://github.com/pyg-team/pytorch_geometric/pull/6634)) - Added `torch.compile` support and benchmark study ([#6610](https://github.com/pyg-team/pytorch_geometric/pull/6610)) - Added the `AntiSymmetricConv` layer ([#6577](https://github.com/pyg-team/pytorch_geometric/pull/6577)) -- Added a mixin for Huggingface model hub integration ([#5930](https://github.com/pyg-team/pytorch_geometric/pull/5930)) +- Added a mixin for Huggingface model hub integration ([#5930](https://github.com/pyg-team/pytorch_geometric/pull/5930), [#6591](https://github.com/pyg-team/pytorch_geometric/pull/6591)) - Added support for accelerated GNN layers in `nn.conv.cugraph` via `cugraph-ops` ([#6278](https://github.com/pyg-team/pytorch_geometric/pull/6278), [#6388](https://github.com/pyg-team/pytorch_geometric/pull/6388), [#6412](https://github.com/pyg-team/pytorch_geometric/pull/6412)) - Added accelerated `index_sort` function from `pyg-lib` for faster sorting ([#6554](https://github.com/pyg-team/pytorch_geometric/pull/6554)) - Fix incorrect device in `EquilibriumAggregration` ([#6560](https://github.com/pyg-team/pytorch_geometric/pull/6560)) From d6577d4dc652c2a8129109de861b18b37de07637 Mon Sep 17 00:00:00 2001 From: rusty1s Date: Wed, 8 Feb 2023 15:46:18 +0100 Subject: [PATCH 20/21] update --- docs/source/modules/nn.rst | 10 +- torch_geometric/nn/model_hub.py | 186 ++++++++++++++------------------ 2 files changed, 88 insertions(+), 108 deletions(-) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index 3912e41cdc99..d342977308e7 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -291,11 +291,15 @@ DataParallel Layers .. automodule:: torch_geometric.nn.data_parallel :members: - :undoc-members: - :exclude-members: training +Model Hub +--------- + +.. automodule:: torch_geometric.nn.model_hub + :members: Model Summary ------------- -.. autofunction:: torch_geometric.nn.summary.summary +.. automodule:: torch_geometric.nn.summary + :members: diff --git a/torch_geometric/nn/model_hub.py b/torch_geometric/nn/model_hub.py index fc21c46e0834..b495d4838787 100644 --- a/torch_geometric/nn/model_hub.py +++ b/torch_geometric/nn/model_hub.py @@ -17,61 +17,55 @@ class PyGModelHubMixin(ModelHubMixin): - r""" - Mixin for saving and loading models to - `Huggingface Model Hub `. - - Sample code for saving a :obj:`Node2Vec` model to the model hub: + r"""A mixin for saving and loading models to the + `Huggingface Model Hub `_. .. code-block:: python - from torch_geometric.datasets import Planetoid - from torch_geometric.nn import Node2Vec - from torch_geometric.nn.model_hub import PyGModelHubMixin - - # Define your class with the mixin: - class N2V(Node2Vec, PyGModelHubMixin): - def __init__(self,model_name, dataset_name, model_kwargs): - Node2Vec.__init__(self,**model_kwargs) - PyGModelHubMixin.__init__(self, model_name, - dataset_name, model_kwargs) - - # instantiate your model: - n2v = N2V(model_name='node2vec', - dataset_name='Cora', model_kwargs=dict( - edge_index=data.edge_index, embedding_dim=128, - walk_length=20, context_size=10, walks_per_node=10, - num_negative_samples=1, p=1, q=1, sparse=True)) - - # train model - ... - - # push to Huggingface: - repo_id = ... # your repo id - n2v.save_pretrained(local_file_path, push_to_hub=True, - repo_id=repo_id) - - # Load the model for inference: - # The required arguments are the repo id/local folder, and any model - # initialisation arguments that are not native python types (e.g - # Node2Vec requires the edge_index argument which is a tensor-- - # this is not saved in model hub) - - model = N2V.from_pretrained(repo_id, - model_name='node2vec', dataset_name='Cora', - edge_index=data.edge_index) - + from torch_geometric.datasets import Planetoid + from torch_geometric.nn import Node2Vec, PyGModelHubMixin + + # Define your class with the mixin: + class N2V(Node2Vec, PyGModelHubMixin): + def __init__(self,model_name, dataset_name, model_kwargs): + Node2Vec.__init__(self,**model_kwargs) + PyGModelHubMixin.__init__(self, model_name, + dataset_name, model_kwargs) + + # Instantiate your model: + n2v = N2V(model_name='node2vec', + dataset_name='Cora', model_kwargs=dict( + edge_index=data.edge_index, embedding_dim=128, + walk_length=20, context_size=10, walks_per_node=10, + num_negative_samples=1, p=1, q=1, sparse=True)) + + # Train the model: + ... + + # Push to the HuggingFace hub: + repo_id = ... # your repo id + n2v.save_pretrained( + local_file_path, + push_to_hub=True, + repo_id=repo_id, + ) - ..note:: - At the moment the model card is fairly basic. Override the - :obj:`construct_model_card` method if you want a more detailed - model card + # Load the model for inference: + # The required arguments are the repo id/local folder, and any model + # initialisation arguments that are not native python types (e.g + # Node2Vec requires the edge_index argument which is not stored in the + # model hub). + model = N2V.from_pretrained( + repo_id, + model_name='node2vec', + dataset_name='Cora', + edge_index=data.edge_index, + ) Args: - model_name (str): Name of the model shown on the model card - on hugging face hub. + model_name (str): Name of the model. dataset_name (str): Name of the dataset the model was trained against. - model_kwargs (Dict): Arguments to initialise the Pyg model. + model_kwargs (Dict[str, Any]): The arguments to initialise the model. """ def __init__(self, model_name: str, dataset_name: str, model_kwargs: Dict): ModelHubMixin.__init__(self) @@ -100,11 +94,6 @@ def construct_model_card(self, model_name: str, dataset_name: str) -> Any: return card def _save_pretrained(self, save_directory: Union[Path, str]): - r""" - Args: - save_directory (Path or str): local filepath to - save model state dict. - """ path = os.path.join(save_directory, MODEL_WEIGHTS_NAME) model_to_save = self.module if hasattr(self, "module") else self torch.save(model_to_save.state_dict(), path) @@ -112,19 +101,17 @@ def _save_pretrained(self, save_directory: Union[Path, str]): def save_pretrained(self, save_directory: Union[str, Path], push_to_hub: bool = False, repo_id: Optional[str] = None, **kwargs): - r""" - Save a trained model to a local directory or to huggingface model hub. + r"""Save a trained model to a local directory or to the HuggingFace + model hub. Args: - save_directory (str, Path): The directory where weights are saved, - to a file called :obj:`"model.pth"`. - push_to_hub(bool): If :obj:`True`, push the model to the - model hub. (default: :obj:`False`) + save_directory (str): The directory where weights are saved. + push_to_hub (bool, optional): If :obj:`True`, push the model to the + HuggingFace model hub. (default: :obj:`False`) repo_id (str, optional): The repository name in the hub. If not provided will default to the name of - :obj:`save_directory` in your namespace. - (default: :obj:`None`) - **kwargs: Additional keyword arguments passed along to + :obj:`save_directory` in your namespace. (default: :obj:`None`) + **kwargs: Additional keyword arguments passed to :obj:`huggingface_hub.ModelHubMixin.save_pretrained`. """ config = self.model_config @@ -158,7 +145,6 @@ def _from_pretrained( strict=False, **model_kwargs, ): - r"""Load trained model.""" map_location = torch.device(map_location) if os.path.isdir(model_id): @@ -201,56 +187,46 @@ def from_pretrained( local_files_only: bool = False, **model_kwargs, ): - r""" - Download and instantiate a model from the Hugging Face Hub. + r"""Downloads and instantiates a model from the HuggingFace hub. Args: - pretrained_model_name_or_path (str, Path): - Can be either: - - A string, the `model id` of a pretrained model - hosted inside a model repo on huggingface.co. - Valid model ids can be located at the root-level, - like `bert-base-uncased`, or namespaced under a - user or organization name, like - `dbmdz/bert-base-german-cased`. - - You can add `revision` by appending `@` at the end - of model_id simply like this: - `dbmdz/bert-base-german-cased@main` Revision is - the specific model version to use. It can be a - branch name, a tag name, or a commit id, since we - use a git-based system for storing models and - other artifacts on huggingface.co, so `revision` - can be any identifier allowed by git. - - A path to a `directory` containing model weights - saved using - [`~transformers.PreTrainedModel.save_pretrained`], - e.g., `./my_model_directory/`. - - `None` if you are both providing the configuration - and state dictionary (resp. with keyword arguments - :obj:`config` and :obj:`state_dict`). - force_download (bool): Whether to force the (re-)download of the - model weights and configuration files, overriding the cached - versions if they exist. (default: :obj:`False`) - resume_download (bool): Whether to delete incompletely received - files. Will attempt to resume the download if such a - file exists.(default: :obj:`False`) + pretrained_model_name_or_path (str): Can be either: + + - The :obj:`model_id` of a pretrained model hosted inside the + HuggingFace hub. + + - You can add a :obj:`revision` by appending :obj:`@` at the + end of :obj:`model_id` to load a specific model version. + + - A path to a directory containing the saved model weights. + + - :obj:`None` if you are both providing the configuration + :obj:`config` and state dictionary :obj:`state_dict`. + + force_download (bool, optional): Whether to force the + (re-)download of the model weights and configuration files, + overriding the cached versions if they exist. + (default: :obj:`False`) + resume_download (bool, optional): Whether to delete incompletely + received files. Will attempt to resume the download if such a + file exists. (default: :obj:`False`) proxies (Dict[str, str], optional): A dictionary of proxy servers - to use by protocol or endpoint, - e.g.,`{'http': 'foo.bar:3128', 'http://host': 'foo.bar:4012'}`. + to use by protocol or endpoint, *e.g.*, + :obj:`{'http': 'foo.bar:3128', 'http://host': 'foo.bar:4012'}`. The proxies are used on each request. (default: :obj:`None`) - token (str, bool, optional): The token to use as HTTP bearer - authorization for remote files. If `True`, will use the token - generated when running `transformers-cli login` (stored in - `~/.huggingface`). It is **required** if you + token (str or bool, optional): The token to use as HTTP bearer + authorization for remote files. If set to :obj:`True`, will use + the token generated when running :obj:`transformers-cli login` + (stored in :obj:`~/.huggingface`). It is **required** if you want to use a private model. (default: :obj:`None`) - cache_dir (str, Path, optional): Path to a directory in which a + cache_dir (str, optional): The path to a directory in which a downloaded model configuration should be cached if the standard cache should not be used. (default: :obj:`None`) - local_files_only(bool): Whether to only look at local files - (i.e., do not try to download the model). + local_files_only (bool, optional): Whether to only look at local + files, *i.e.* do not try to download the model. (default: :obj:`False`) - **model_kwargs: Keyword arguments passed along to - model during initialization. (default: :obj:`None`) + **model_kwargs: Additional keyword arguments passed to the + model during initialization. """ return super().from_pretrained( pretrained_model_name_or_path, From 081fd14c0e88f188f433f599ed6ec509f2b7b70b Mon Sep 17 00:00:00 2001 From: rusty1s Date: Wed, 8 Feb 2023 15:48:19 +0100 Subject: [PATCH 21/21] update --- docs/source/modules/nn.rst | 2 -- torch_geometric/nn/model_hub.py | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/source/modules/nn.rst b/docs/source/modules/nn.rst index d342977308e7..b411266a88d5 100644 --- a/docs/source/modules/nn.rst +++ b/docs/source/modules/nn.rst @@ -6,8 +6,6 @@ torch_geometric.nn .. autoclass:: torch_geometric.nn.sequential.Sequential -.. autoclass:: torch_geometric.nn.model_hub.PyGModelHubMixin - .. currentmodule:: torch_geometric.nn.dense {% for name in torch_geometric.nn.dense.lin_classes %} diff --git a/torch_geometric/nn/model_hub.py b/torch_geometric/nn/model_hub.py index b495d4838787..221e657c3344 100644 --- a/torch_geometric/nn/model_hub.py +++ b/torch_geometric/nn/model_hub.py @@ -112,7 +112,7 @@ def save_pretrained(self, save_directory: Union[str, Path], If not provided will default to the name of :obj:`save_directory` in your namespace. (default: :obj:`None`) **kwargs: Additional keyword arguments passed to - :obj:`huggingface_hub.ModelHubMixin.save_pretrained`. + :meth:`huggingface_hub.ModelHubMixin.save_pretrained`. """ config = self.model_config # due to way huggingface hub handles the loading/saving of models, @@ -186,7 +186,7 @@ def from_pretrained( cache_dir: Optional[str] = None, local_files_only: bool = False, **model_kwargs, - ): + ) -> Any: r"""Downloads and instantiates a model from the HuggingFace hub. Args: