How to know if gpu memory is enough before starting training?

Are there any available code to be used directly?

There is this: https://huggingface.co/transformers/benchmarks.html, which you can use to test memory usage amongst other things.