It’s not the apply function itself, it’s probably the constraints function which you are passing into model.apply(), but without seeing it I can’t know for sure.  For example, in my code above the init_weights function is being passed into apply, you should have a similar function called constraints which is getting passed into apply.  You can see more information on how this works at https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.apply 1