I would claim it depends on your use case and especially if you have any knowledge about the task for each sample.
I.e. regardless of the training approach, once the model is trained how would you pass the samples to the model and which predictions do you expect? If each sample also contains information about the task, an if condition inside the forward methods could work, since you would be able to use it during training as well as inference. However, if you don’t have the task information during inference, the condition inside forward cannot be applied so you wouldn’t be able to deploy the model and might need to stick to calculating the predictions for both tasks (and use more logic to decide which task to pick).