TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

266. Backprop: Sigmoid (PyTorch)

Easy

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

σ(x)=1+e−x1​,σ′(x)=σ(x)(1−σ(x))

Related problems

  • Backprop: SigmoideasyNumPy

Asked at

NumPy

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.

Upgrade to PremiumBack to problems

Already premium?