Implement sigmoid as a torch.autograd.Function. Forward: y = 1 / (1 + exp(-x)). Backward uses the identity dy/dx = y * (1 - y).
The rule: you may NOT call F.sigmoid, torch.sigmoid, or nn.Sigmoid. Build the forward from .exp() and basic arithmetic, and wire the backward by hand.
Implement SigmoidFunction with forward/backward. Save y (the output), not x, so backward is grad_output * y * (1 - y). The driver sigmoid_run(mode, x) dispatches 'forward' | 'grad_x' | 'gradcheck'.
Math
Related problems
Asked at
import numpy as np
def sigmoid_run(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?