I would guess that you have something in your constraints  function which is causing it to print out.  That’s the most likely to me at least, everything else is pretty standard.
For example this will print out on apply:
import torch

@torch.no_grad()
def init_weights(m):
  print(m)
  if type(m) == nn.Linear:
    m.weight.fill_(1.0)
    # print(m.weight)
net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
n = net.apply(init_weights);

will output
Linear(in_features=2, out_features=2, bias=True)
Linear(in_features=2, out_features=2, bias=True)
Sequential(
  (0): Linear(in_features=2, out_features=2, bias=True)
  (1): Linear(in_features=2, out_features=2, bias=True)
)

which is similar to what you are seeing.  You would just need to get rid of the print statement and you should be good. Of course if anything in those other methods has been modified it could they could be the culprit as well.