move test helper functions out of test funciton (#33960)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33960
test helper functions should be out of test function. it is possible process 2 launches test functions slower than process 1, and process 1 sends request to run a helper function on process 2. process 2 may have not compile the helper function yet when process 2 starts to serve processs 1's request, and thus may return error like "attempted to get undefined function"
ghstack-source-id: 99205620
Test Plan: test_remote_script_module was flaky for thrift backend in my local stress test runs, due to error "attempted to get undefined function". With fix in this diff, stress runs passed
Differential Revision: D20167969
fbshipit-source-id: 8a2b9cd7bd62462e24bdbcb69ad32dca745d6956