Speed up RecordFunction with sampled callbacks (#20307)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20307
ghimport-source-id: 94adc3c3102bb6b9cb60cf6c6112e350aa954aaf
Differential Revision: D15276308
Pulled By: ilia-cher
fbshipit-source-id: c536063669d8414b4ce0b09fd5dc0d76f1e94bb5