Talking with your landlord, or with an agent is probably the best place to start.
If you can find a new person to take over the lease, they may be willing to let you go and even give you back the deposit. They may take the deposit but not hold you liable for anything else. They may just ask you to pay the agent fee (50% of rent) to find a new tennant. Sometime the new person will pay more than you so that is a nice 'carrot' to dangle in front of them.
FWIW, if you are in a negotiation on a lease and think this might occur, it is best to talk with the landlord at the beginning and see what can be done. Maybe you can work out some 'buy out' option or 'replacement option' should this happen.
We had an emergency departure but were able (after some debate) to get a new tennant at a higher rate. We paid the agent fee, but in the end everyone was happy.