TF SAM shape flexibility fixes
This PR makes some small changes to use dynamic instead of static shapes for SAM, which fixes issues when compiling and fine-tuning.

cc @sayakpaul, fixes #23826
_The documentation is not available anymore as the PR was closed or merged._