I am working on a multi-objective problem where I have multiple losses that I need to compute, and the total loss is just the sum of the losses. I want to have PyTorch learnable floating-point parameters alpha, and beta that act as coefficients to the individual losses. Note that the summation of losses occurs outside my NN model in the training loop:
optimizer = AdamW(model.parameters(), lr=2e-5, eps=1e-8)
for batch in dl:
optimizer.zero_grad()
result = model(batch)
loss1 = loss_fn_1(result)
loss2 = loss_fn_2(result)
loss3 = loss_fn_3(result)
loss = alpha*loss1 + beta*loss2 + (1-beta)*loss3 # How to optimize alpha, beta?
loss.backward()
optimizer.step()
How would I declare and use the learnable parameters alpha and beta?