def grad_hook(module, name, writer, bins):
    """ Factory for grad_hook closures """
    def hook(grad):
        writer.add_histogram('{}/grad'.format(name.replace('.','/')),
                             grad.detach().cpu().numpy(),
                             module.global_step-1,
                             bins=bins)
    return hook
def grad_hook ( module , name , writer , bins ) : def hook ( grad ) : writer . add_histogram ( '{}/grad' . format ( name . replace ( '.' , '/' ) ) , grad . detach ( ) . cpu ( ) . numpy ( ) , module . global_step - 1 , bins = bins ) return hook
Factory for grad_hook closures