You can define a custom gradient rule for RSWAF basis by noting the derivative of the key operation
rswaf_core(x) = 1 - tanh(x)^2
has a lot of computation in common with the forward pass. Specifically,
rswaf_core_deriv(x) = -2 * tanh(x) * tanh_deriv(x)
tanh_deriv(x) = 1 - tanh(x)^2 # = rswaf_core(x)
A custom gradient can share work between the forward and backward pass thus improving efficiency and memory utilization. You can check my Julia implementation for reference.
You can define a custom gradient rule for RSWAF basis by noting the derivative of the key operation
has a lot of computation in common with the forward pass. Specifically,
A custom gradient can share work between the forward and backward pass thus improving efficiency and memory utilization. You can check my Julia implementation for reference.