You can just create a simple function for the your purpose and call that function directly. PyTorch would automatically handle the backprop step for you.
For the if-else part, you can add if-else statements in your model and pytorch would train them for you.