-
Notifications
You must be signed in to change notification settings - Fork 547
Optim-wip: Move inception test helpers to separate file #863
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from typing import Type | ||
|
|
||
| import torch | ||
|
|
||
|
|
||
| def _check_layer_in_model( | ||
| self, | ||
|
||
| model: torch.nn.Module, | ||
| layer: Type[torch.nn.Module], | ||
| ) -> None: | ||
| def check_for_layer_in_model(model, layer) -> bool: | ||
|
||
| for name, child in model._modules.items(): | ||
| if child is not None: | ||
| if isinstance(child, layer): | ||
| return True | ||
| if check_for_layer_in_model(child, layer): | ||
| return True | ||
| return False | ||
|
|
||
| self.assertTrue(check_for_layer_in_model(model, layer)) | ||
|
|
||
|
|
||
| def _check_layer_not_in_model( | ||
|
||
| self, model: torch.nn.Module, layer: Type[torch.nn.Module] | ||
| ) -> None: | ||
| for name, child in model._modules.items(): | ||
| if child is not None: | ||
| self.assertNotIsInstance(child, layer) | ||
| _check_layer_not_in_model(self, child, layer) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leading
_is a convention for private. As we are exporting these 2 functions to be used by others, we can remove this leading_There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yeah I'm not sure how I missed removing the underscore!