how about this:
loss2.backward(retain_graph=True)
for p in model.parameters():
    p.grad *= C
optimizer.step()
optimizer.zero_grad()
loss1.backward()
optimizer.step()

so you can avoid accumulate gradients on parameters.