Am I doing the right thing you teach me? Because when I try model.state_dict(), there is still no l in it. I think I am doing things wrong. How can I fix it?
#  Learnable softshrink func
def softshrink(x, lambd):
    mask1 = x > lambd
    mask2 = x < -lambd
    out = torch.zeros_like(x)
    out += mask1.float() * -lambd + mask1.float() * x
    out += mask2.float() * lambd + mask2.float() * x
    return out

# A Neural Network
class LISTA(torch.nn.Module):
    def __init__(self, D_in, D_out):
        super(LISTA, self).__init__()
        self.We = torch.nn.Linear(D_in, D_out)
        self.S = torch.nn.Linear(D_out, D_out)
        self.l = Variable(torch.Tensor([0.5]), requires_grad=True)

    def forward(self, x):
        out = softshrink(self.We(x),self.l)
        for i in range(20):
            out = softshrink(self.We(x)+self.S(out),self.l)
        out = nn.functional.sigmoid(out)
        return out