Some countries are routinely criticized for their military having considerable influence over politics and foreign policy. E.g. Pakistan.

How does the situation in the USA compare to those countries?

What is the scale of the Pentagon's ability to influence/override/pressurize POTUS?

For instance, as far as I know, Pentagon opposed the decision of Barack Obama and Trump of withdrawing troops from Afghanistan. I also heard that they are still opposing Biden's decision regarding the withdrawal of troops. So, why could they stop Barack Obama from calling troops back, while they could not stop Biden?

I also think that Pentagon has great influence regarding the defense budget/procurement and the military exports.

Can anyone clarify this matter to me?