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

Custom Surrogate Gradient Function #237

Merged

Conversation

mehranfaraji
Copy link
Contributor

CustomSurrogate class and custom_surrogate function added to the surrogate.py file.

This enables the users to define their own custom surrogate function and call it using either custom_surrogate(name_of_custom_surrogate_function) or
CustomSurrogate.apply(data, name_of_custom_surrogate_function)

The arguments of the custom surrogate gradient function always are The input of the forward pass (input_), the gradient of the input (grad_input) and the output of the the forward pass (out) respectively.

** Important Note: The hyperparameters of the custom Surrogate gradient function have to be defined inside of the function itself. **

mehranfaraji and others added 4 commits September 6, 2023 13:02
CustomSurrogate class and custom_surrogate function added to the surrogate.py file.

This enables the users to define their own custom surrogate function and call it using either
custom_surrogate(name_of_custom_surrogate_function)
or
CustomSurrogate.apply(data, name_of_custom_surrogate_function)

The arguments of the custom surrogate gradient function always are The input of the forward pass (input_), the gradient of the input (grad_input) and the output of the the forward pass (out) respectively.

** Important Note: The hyperparameters of the custom Surrogate gradient function have to be defined inside of the function itself. **
@jeshraghian
Copy link
Owner

This is really elegant, thanks for this contribution!

I've just done a commit to fix up some minor docstrings, and also added a section in the documentation about custom surrogate gradients.

@jeshraghian jeshraghian merged commit b4a1d10 into jeshraghian:master Sep 23, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants