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

Align SequentialModule.add_module behavior with torch.nn.Module.add_module #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmklee
Copy link

@dmklee dmklee commented Sep 11, 2023

The assertion checks in SequentialModule.add_module assume that the module is
being added to the end of the sequence. However, it calls torch.nn.Module.add_module
which allows for overwriting existing modules by name. So, if one tries to overwrite an
existing module by name, an assertion error is raised. I modified the assertion checks
so that modules can be overwritten so long as they have the correct in_type and out_type
according to the modules before and after them in the sequence.

I encountered this issue when trying to call torch.nn.SyncBatchNorm.convert_sync_batchnorm
on a SequentialModule. With this change, you can sync InnerBatchNorm's across machines during
training since they use torch.nn.BatchNormXd under the hood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant