In short, yes. Conditions for terminating the contract ahead of schedule should be specified in the document. It is usually required to notify a landlord in advance of your intentions. Besides, you will probably have to pay the penalty.