Generate: faster `can_generate` check on TF and Flax
# What does this PR do?

Same as https://github.com/huggingface/transformers/pull/22643, but on TF and Flax.

[This comment](https://github.com/huggingface/transformers/pull/22643#issuecomment-1501033074) shows that it reduces the exec time of this line from 1-500 ms to <0.01 ms
_The documentation is not available anymore as the PR was closed or merged._