[dist_optim] serialize compilation when creating dist_optim (#45871)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45871
Attempt to fix https://github.com/pytorch/pytorch/issues/45845
Test Plan: Imported from OSS
Reviewed By: pritamdamania87
Differential Revision: D24125209
Pulled By: wanchaol
fbshipit-source-id: e3697dd6ef107d8153d2a82d78a17c66d109b4fa