Skip to content
Snippets Groups Projects
Commit 794ac09d authored by Neta Zmora's avatar Neta Zmora
Browse files

Activation statistics collection: add user assert

When detecting a module that is used multiple times, stop execution
and print an explanation to the user.v
parent f3482e06
No related branches found
No related tags found
No related merge requests found
......@@ -145,7 +145,16 @@ class SummaryActivationStatsCollector(ActivationStatsCollector):
This is a callback from the forward() of 'module'.
"""
getattr(module, self.stat_name).add(self.summary_fn(output.data))
try:
getattr(module, self.stat_name).add(self.summary_fn(output.data))
except RuntimeError:
raise ValueError("ActivationStatsCollector: a module was encountered twice during model.apply().\n"
"This is an indication that your model is using the same module instance, "
"in multiple nodes in the graph. This usually occurs with ReLU modules: \n"
"For example in TorchVision's ResNet model, self.relu = nn.ReLU(inplace=True) is "
"instantiated once, but used multiple times. This is not permissible when using "
"instances of ActivationStatsCollector.")
def _start_counter(self, module):
if not hasattr(module, self.stat_name):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment