[dynamo] add stronger test for dynamo memory leaks (#120459)
This issue was raised by a regression of https://github.com/pytorch/pytorch/issues/112090 caused by https://github.com/pytorch/pytorch/pull/120147.
Make the memory leak test stronger by using weakref to check for model deletion instead of measuring CUDA memory allocation.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/120459
Approved by: https://github.com/jansel