- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.1k
 
          Add ActivationStatsHook  to allow extracting activation stats for Signal Propogation Plots
          #525
        
          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
Conversation
| 
           @amaarora thanks for the addition, I don't have any issues re style/guidlines. On the impl, this will match the originals for the resnet/nf_resnet modles but not quite the same as nfnet. For nfnet they also tap the end of the residual path (before the addition/skipinit). That requires hooking specific sub-layers by name, not just the block module. I wonder if it makes sense to use layer_names (for the actual full layer name in the hierarchy, and possibly layer_types if that is desired as well)... below I show an example using layer names w/ fnmatch to grab the stem, the block output, and the residual path  | 
    
| 
           Thanks @rwightman, I've implemented a version of your approach but the matching pattern for residual block will vary across models? For example for  Notice the difference in the   | 
    
| 
           I suggest we update the      def register_hook(self, hook_fn_loc, hook_fn):
        for name, module in self.model.named_modules():
            if not fnmatch.fnmatch(name, hook_fn_loc):
                continue
            module.register_forward_hook(self._create_hook(hook_fn))Where users provide the matching pattern   | 
    
| 
           @rwightman I've updated PR. Feel that letting the user provide pattern is the best and most flexible way to keep the  Here is an example that plots SPPs including the last layer on residual branch: https://gist.github.com/amaarora/6e56942fcb46e67ba203f3009b30d950 
  | 
    
          
 @amaarora Agreed, this way allows it to be used with any model. Since it does require a bit of knowledge about the model & how hooks work, it might be good to expand the docstring for your ActivationStatsHook to include a link to your gist as a concrete and immediately accessible example.  | 
    
          
 Done :)  | 
    
Add `ActivationStatsHook` to allow extracting activation stats for Signal Propogation Plots
Refer here for example usage https://gist.github.com/amaarora/c562da34b95d97f8254960bdca6a12d1.
As this is my first PR, please let me if I haven't used the correct formatting etc and can contribute towards creating a
contributing.mdto set the standard rules for PRs.Thanks Ross!