Below loss_func returns variable for whom require grad has to be explicitly made requires grad=True  or else i get an error message during .backward saying there is grad fn for this.
But   few epochs this variable results cuda meomory error,i keep very low batch size.
CustomLossfunc(nn.Module):

def forward 
loss=torch.tensor(loss_func(torch.round(inputs), targets,  )-1).requires_grad_(True).cuda()
        return  -loss