Thanks for the clarification.
In that case, this might work:
b = torch.randn(2,2)*1.5
a = b.detach()
idx = (a>=0) & (a <1)
if idx.any():
    a[idx] = -2 * torch.pow(a[idx],3) + 3 * torch.pow(a[idx],2)