Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Deprecate nn.glob package #5039

Merged
merged 16 commits into from Jul 26, 2022
Merged

Conversation

Padarn
Copy link
Contributor

@Padarn Padarn commented Jul 23, 2022

Removes use of nn.glob package. #4712

@codecov
Copy link

codecov bot commented Jul 23, 2022

Codecov Report

Merging #5039 (0357f32) into master (575611f) will decrease coverage by 1.84%.
The diff coverage is 92.85%.

@@            Coverage Diff             @@
##           master    #5039      +/-   ##
==========================================
- Coverage   84.74%   82.89%   -1.85%     
==========================================
  Files         331      331              
  Lines       18162    18137      -25     
==========================================
- Hits        15391    15035     -356     
- Misses       2771     3102     +331     
Impacted Files Coverage Δ
torch_geometric/nn/glob.py 81.25% <90.00%> (ø)
torch_geometric/nn/__init__.py 100.00% <100.00%> (ø)
torch_geometric/nn/pool/__init__.py 89.65% <100.00%> (+0.36%) ⬆️
torch_geometric/nn/pool/glob.py 100.00% <100.00%> (ø)
torch_geometric/nn/models/dimenet_utils.py 0.00% <0.00%> (-75.52%) ⬇️
torch_geometric/nn/models/dimenet.py 14.51% <0.00%> (-53.00%) ⬇️
torch_geometric/nn/conv/utils/typing.py 81.25% <0.00%> (-17.50%) ⬇️
torch_geometric/profile/profile.py 32.94% <0.00%> (-15.30%) ⬇️
torch_geometric/nn/inits.py 67.85% <0.00%> (-7.15%) ⬇️
torch_geometric/nn/resolver.py 88.00% <0.00%> (-6.00%) ⬇️
... and 12 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@Padarn Padarn requested review from rusty1s and lightaime July 23, 2022 07:10
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@lightaime lightaime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM! Left a few minor comments.

sum_aggr = SumAggregation()


def global_add_pool(x: Tensor, index: Optional[Tensor],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the original doc strings for global pools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea


@deprecated(
details="use 'nn.aggr.GlobalSortAggr' instead",
func_name='nn.glob.global_sort_pool',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a bit confusing for me since the modules are now moved to nn.pool.glob.*.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks good point!

torch_geometric/nn/pool/glob.py Outdated Show resolved Hide resolved
torch_geometric/nn/pool/glob.py Outdated Show resolved Hide resolved
return scatter(x, batch, dim=-2, dim_size=size, reduce='max')


class GlobalPooling(torch.nn.Module):
Copy link
Contributor

@lightaime lightaime Jul 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why this is removed completely? If we need it can we implement it with MultiAggregation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes removed completed (discussed with @rusty1s in earlier version of this PR - the code for this was added recently and we decided it was no longer needed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense

@@ -1,78 +0,0 @@
import torch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why the tests are removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake, added back.

Padarn and others added 3 commits July 24, 2022 08:25
Co-authored-by: Guohao Li <lightaime@gmail.com>
Co-authored-by: Guohao Li <lightaime@gmail.com>
Co-authored-by: Guohao Li <lightaime@gmail.com>
@Padarn
Copy link
Contributor Author

Padarn commented Jul 24, 2022

Thanks for the review @lightaime

Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Padarn. I think my comments earlier let to some misunderstanding, sorry about that. Clarified more in the comments. Let me know what you think!

test/nn/aggr/test_sort.py Show resolved Hide resolved
@@ -1,72 +0,0 @@
import torch
Copy link
Member

@rusty1s rusty1s Jul 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this file to pool/test_glob.py?

@@ -11,6 +11,8 @@
from .asap import ASAPooling
from .pan_pool import PANPooling
from .mem_pool import MemPooling
from .glob import (global_max_pool, global_mean_pool, global_add_pool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, this is not what I meant. I meant:

  • Move global_add_pool, global_mean_pool, and global_max_pool to glob/glob.py to pool/glob.py`.
  • Move glob/__init__.py to nn/glob.py and keep the deprecations in there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that we keep the implementations of global_*_pool as they were (since they are so heavily used).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm sorry I don't fully understand the distinction between these. In both cases you can

from torch_geometric.nn import global_max_pool

is it that you want to keep this?

from torch_geometric.nn.glob import global_max_pool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you just want to clearly separate the deprecations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we only need to
deprecate the import of torch_geometric.nn.glob.

@Padarn
Copy link
Contributor Author

Padarn commented Jul 24, 2022

Ah yeah I misunderstood. Thanks for clarifying, I'll make the changes

Copy link
Contributor

@lightaime lightaime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left some small comments.

'MemPooling', 'max_pool', 'avg_pool', 'max_pool_x', 'max_pool_neighbor_x',
'avg_pool_x', 'avg_pool_neighbor_x', 'graclus', 'voxel_grid', 'fps', 'knn',
'knn_graph', 'radius', 'radius_graph', 'nearest', 'global_max_pool',
'global_add_pool', 'global_mean_pool'
Copy link
Contributor

@lightaime lightaime Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add back a comma for auto-formatting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Let‘s also move the global pooling methods to the top.


Set2Set = deprecated(
details="use 'nn.aggr.Set2Set' instead",
func_name='nn.pool.Set2Set',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecations are moved back to nn.glob.*. Should we change back from nn.pool.* to nn.glob.*? Sorry about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct. We provide backward compatibility in nn/glob.py but deprecate its use.

Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This is exactly what I had in mind. Left some last comments.


Set2Set = deprecated(
details="use 'nn.aggr.Set2Set' instead",
func_name='nn.pool.Set2Set',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct. We provide backward compatibility in nn/glob.py but deprecate its use.

@@ -0,0 +1,35 @@
from torch_geometric.deprecation import deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global_*_pool methods need to be added here as well.

'MemPooling', 'max_pool', 'avg_pool', 'max_pool_x', 'max_pool_neighbor_x',
'avg_pool_x', 'avg_pool_neighbor_x', 'graclus', 'voxel_grid', 'fps', 'knn',
'knn_graph', 'radius', 'radius_graph', 'nearest', 'global_max_pool',
'global_add_pool', 'global_mean_pool'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Let‘s also move the global pooling methods to the top.

@@ -25,19 +29,19 @@ def global_add_pool(x: Tensor, batch: Optional[Tensor],
"""
if batch is None:
return x.sum(dim=-2, keepdim=x.dim() == 2)
size = int(batch.max().item() + 1) if size is None else size
return scatter(x, batch, dim=-2, dim_size=size, reduce='add')
return sum_aggr(x, batch, dim_size=size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the implementation as it is? I am not super happy with having global modules here.

@Padarn
Copy link
Contributor Author

Padarn commented Jul 26, 2022

Thanks for the reviews again! I've addressed the comments. Will merge later unless any objections

@Padarn
Copy link
Contributor Author

Padarn commented Jul 26, 2022

I have some problem with the docs build. Will figure it out tonight

@Padarn
Copy link
Contributor Author

Padarn commented Jul 26, 2022

could be sphinx-doc/sphinx#10705 .. may have to wait until they release the new version

@rusty1s
Copy link
Member

rusty1s commented Jul 26, 2022

Yes, don‘t worry about it.

@rusty1s rusty1s merged commit 9ecd507 into pyg-team:master Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants