You can withdraw your offer at any time until the seller accepts it and communicates that acceptance to you. Many states have something peculiar called the mailbox acceptance rule. It says that if you typically communicate via the mail, and someone accepts your offer by sending you something in the mail, you cannot withdraw your offer after he or she has mailed you his or her acceptance. In other words, giving the acceptance to the post office is the same as giving it to you. Many states have modernized the rule to include emails, so that as soon as a person hits “send” on his or her email accepting an offer, it is the same as if you received it, even if your server is down for several days.
If you indeed have a contract, the question is whether you can cancel it or not if the economics of the deal change.
Most contracts prepared by local real estate associations provide a deadline for a home inspection, and perhaps another one for cancellation based on seller disclosures. Commercial real estate contracts often have many pages of deadlines for inspections, permitting, architectural review, and the like, with the seller having the ability to cancel at any stage. Instead of all that, I typically use an all-purpose due diligence clause. It says I have a certain amount of time to check on anything I want. At the end of that time, I have to go forward to closing or cancel the contract. I can cancel for any reason. This would be a good clause for you to use in your contracts, also.