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

Replace torch.nn.ModuleDict with custom ModuleDict #5227

Merged
merged 13 commits into from
Aug 18, 2022
Merged

Conversation

kiriti-kumo
Copy link
Contributor

torch.nn.ModuleDict doesn't allow . to be used in the keys. This prevents using node types with . in the name.
CustomModuleDict will support it by converting the . to # in the internal representation and converts it back to . in the external representation.

@kiriti-kumo kiriti-kumo self-assigned this Aug 18, 2022
Copy link
Contributor

@yaoyaowd yaoyaowd left a comment

Choose a reason for hiding this comment

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

LGTM. Do we know any legacy reasons that . is not supported?

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! Looks good. Importantly, I don't think we have to replace every occurence of ModuleDict for now - let's keep it simple and start with HeteroConv.

torch_geometric/utils/module_dict.py Outdated Show resolved Hide resolved
torch_geometric/utils/module_dict.py Outdated Show resolved Hide resolved
torch_geometric/utils/module_dict.py Outdated Show resolved Hide resolved
torch_geometric/utils/module_dict.py Outdated Show resolved Hide resolved
torch_geometric/utils/__init__.py Outdated Show resolved Hide resolved
torch_geometric/utils/module_dict.py Outdated Show resolved Hide resolved
torch_geometric/nn/fx.py Outdated Show resolved Hide resolved
test/nn/conv/test_hetero_conv.py Outdated Show resolved Hide resolved
@rusty1s
Copy link
Member

rusty1s commented Aug 18, 2022

@yaoyaowd I believe PyTorch provides nested module access via dot-syntax in ModuleDict.

@rusty1s
Copy link
Member

rusty1s commented Aug 18, 2022

Tests failure does not seem related to this PR. I will look into this separately.

@kiriti-kumo
Copy link
Contributor Author

@yaoyaowd As per pytorch/pytorch#6639 - seems like torch uses . as a reserved delimiter.

Copy link
Contributor

@mananshah99 mananshah99 left a comment

Choose a reason for hiding this comment

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

LGTM after comments are addressed, thanks :)

@codecov
Copy link

codecov bot commented Aug 18, 2022

Codecov Report

Merging #5227 (1316ad6) into master (bb0a32f) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5227      +/-   ##
==========================================
+ Coverage   83.09%   83.13%   +0.03%     
==========================================
  Files         335      336       +1     
  Lines       18496    18521      +25     
==========================================
+ Hits        15369    15397      +28     
+ Misses       3127     3124       -3     
Impacted Files Coverage Δ
torch_geometric/nn/conv/hetero_conv.py 89.09% <100.00%> (+0.20%) ⬆️
torch_geometric/nn/module_dict.py 100.00% <100.00%> (ø)
torch_geometric/data/dataset.py 97.60% <0.00%> (+0.79%) ⬆️
torch_geometric/loader/hgt_loader.py 94.33% <0.00%> (+3.77%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.

This is amazing. Thank you!

@rusty1s rusty1s merged commit 77af334 into master Aug 18, 2022
@rusty1s rusty1s deleted the custom_module_dict branch August 18, 2022 07:43
@rusty1s rusty1s changed the title Replace torch.nn.ModuleDict with CustomModuleDict Replace torch.nn.ModuleDict with custom ModuleDict Aug 18, 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

4 participants