It might not be as efficient, but you could just hard-code the BCE instead of using the built-in BCEloss and then multiply each loss term in the batch by your desired coefficient before you sum it up. This doesn’t require a loop, just an elementwise multiply.