Premium problem77. Stop the Gradient Through One Branch

Medium Locked

Let x be a scalar tensor holding value with requires_grad=True, and let

y = x**2 + detached(x**3)

where the cubic term is detached from the graph so no gradient flows through it.

Differentiate y with respect to x and return x.grad. Since only the square contributes, the answer is 2*value rather than 2*value + 3*value**2.

Input

2.0

Output

tensor(4.)

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)