You can use the output variable to generate two outputs. There are multiple ways, e.g., something like the forward in your code above.
To backprop, just do loss on different outputs, add them together, and call backward on the sum.