LeanderK:

I want to disable the gradient from logdets if it’s greater than zero.


If you would like to disable the gradient flowing back from logdets if it’s > 0, this code should probably work:
def forward(self, input):
    ...
    if logdets > 0:
        logdets = logdets.detach()
    return l_1, logdets