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

Replace module backward hook with tensor hook #1

Open
yaroslavvb opened this issue Sep 13, 2019 · 0 comments
Open

Replace module backward hook with tensor hook #1

yaroslavvb opened this issue Sep 13, 2019 · 0 comments

Comments

@yaroslavvb
Copy link
Collaborator

yaroslavvb commented Sep 13, 2019

Module backward hooks may get deprecated eventually, can replace them with tensor hook as follows.

def tensor_hook_adder(module, input, output):
    def tensor_backwards(grad):
        setattr(module, 'backprops', grad)
    output.register_hook(tensor_backwards)

layer.register_forward_hook(tensor_hook_adder)
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

No branches or pull requests

1 participant