something like:
aa.requires_grad = bool(epoch % 2)
if aa.requires_grad:
  with torch.no_grad():
    y = net(x)
else:
  y = net(x)

you may also want to assign aa to a distinct optimizer or parameter group, as this procedure only makes sense if you want to adjust training dynamics of “aa”