your example should be changed to:
    def forward(ctx, x):
        y = torch.sin(2*x)
        if ctx.needs_input_grad[0]: ctx.save_for_backward(y)
        return y

as your version keeps both 2x and sin(2x) tensors. I’m not sure about relu’s role.