[PyTorch] [Model Tracer] Protect writes to set/map for capturing used operators, dtypes, custom classes, and build features (#73327)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73327
The lack of a mutex to protect 4 static variables used by model tracer leads to a problem when multi-threaded/parallel operators are invoked when running a model. These cause the static variables to be read from and written to concurrently, corrupting their internal state.
Since tracing isn't a performance critical code path, it's okay to use a mutext to protect all writes and reads to these shared variables.
Verified that the problem to model tracer goes away after this change.
Test Plan:
1. Built Model Tracer Locally:
```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```
2. Ran it multiple times to ensure that there's no contention on unprotected variables:
```
buck-out/gen/aab7ed39/xplat/caffe2/fb/model_tracer/model_tracer --model_input_path /tmp/tmpmqjqubro.ptl --build_yaml_path /data/users/dhruvbird/fbsource/xplat/pytorch_models/build/assistant_oculus_smart_keyboard_litelm_lstm/v1/fl_model_with_context_v1.yaml --model_name assistant_oculus_smart_keyboard_litelm_lstm --model_version 1 --model_asset_name fl_model_with_context_v1 --model_asset_md5_hash 206dded28c18447c287d10ac91993b2d
```
Reviewed By: JacobSzwejbka
Differential Revision: D34433840
fbshipit-source-id: 5fb97277335cf09278648981a13e169be1271641
(cherry picked from commit 3d3c63388d49a7df7f6b0155364795e9eaf811b3)