As previously described, often wrong if conditions are used which are never met. In your case this also seems to be the case here:
        if i==0:
            nms_keep = class_keep
        else:
            nms_keep = unique1d(torch.cat((nms_keep, class_keep)))

Add a print statement to the if i==0 case and you would see that it most likely won’t be executed before the else branch.