How to define loss weights for parts of model?

I need to calculate a loss which is composed by some different parts of a net,but different parts need to have a different weights to constitute a loss value.How should I do for this purpose?
I wonder if the form
loss+=math.exp(-1*float(epoch+1)/args.epochs)*loss_fn(model_output[i],label)
is correct???
Can the gradients flow correctly though net in this way?

Thanks for your advice!

yes, from what I see gradients will flow correctly in this case.