We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← Activations step 9 of 9
Hard
Framework
Custom Activation with Gradient
Implement a custom activation function f(x) = x * sigmoid(x) (SiLU/Swish)
and compute its gradient at given input values.
Return a tuple of (output, gradient) where:
-
output =
x * sigmoid(x) -
gradient =
d/dx [x * sigmoid(x)]
The derivative is: sigmoid(x) + x * sigmoid(x) * (1 - sigmoid(x))
Input: A 1D tensor x.
Output: A dict with keys “output” and “gradient”, each a 1D tensor of the same shape as input.
API Reference:
-
PyTorch: custom autograd or
torch.autograd.grad -
JAX:
jax.value_and_gradorjax.grad
Nothing accepted yet. When a submission passes, the code that passed shows up
here, one entry per mode.
Stuck?
PyTorch reference solution
Sign in to attempt this problem and reveal the reference solution.