Repository: pytorch
Issue: TSAN issues in torch::jit::ProfilingRecord
Labels: oncall: jit

## 🐛 Bug

```
    #0 std::enable_if<__and_<std::__not_<std::__is_tuple_like<torch::jit::AttributeValue*> >, std::is_move_constructible<torch::jit::AttributeValue*>, std::is_move_assignable<torch::jit::AttributeValue*> >::value, vo
id>::type std::swap<torch::jit::AttributeValue*>(torch::jit::AttributeValue*&, torch::jit::AttributeValue*&) 
    #1 std::unique_ptr<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >::reset(torch::jit::AttributeValue*) 
    #2 std::unique_ptr<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >::operator=(std::unique_ptr<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >&&) 
    #3 torch::jit::Node* torch::jit::Node::setAttr<torch::jit::ScalarAttributeValue<std::shared_ptr<c10::Type>, (torch::jit::AttributeKind)12> >(c10::Symbol, torch::jit::ScalarAttributeValue<std::shared_ptr<c10::Type
>, (torch::jit::AttributeKind)12>::ConstructorType) caffe2/torch/csrc/jit/ir/ir.h:860 (libcaffe2_libtorch.so+0x327ada2)
    #4 torch::jit::Node::ty_(c10::Symbol, std::shared_ptr<c10::Type>) caffe2/torch/csrc/jit/ir/ir.h:815 (libcaffe2_libtorch.so+0x3276df0)
    #5 torch::jit::ProfilingRecord::instrumentGraph(std::shared_ptr<torch::jit::Graph> const&)::$_1::operator()(std::vector<c10::IValue, std::allocator<c10::IValue> >&) const caffe2/torch/csrc/jit/runtime/profiling_r
ecord.cpp:378 (libcaffe2_libtorch.so+0x35c186e)

  Previous read of size 8 at 0x7b04000b3c60 by thread T30 (mutexes: write M702978548836049480):
    #0 std::__uniq_ptr_impl<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >::_M_ptr() const 
    #1 std::unique_ptr<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >::get() const 
    #2 std::unique_ptr<torch::jit::AttributeValue, std::default_delete<torch::jit::AttributeValue> >::operator->() const 
    #3 torch::jit::Node::copyAttributes(torch::jit::Node const&) caffe2/torch/csrc/jit/ir/ir.h:748 (libcaffe2_libtorch.so+0x2e192ee)
    #4 torch::jit::Node::cloneFrom(torch::jit::Node*) caffe2/torch/csrc/jit/ir/ir.cpp:1269 (libcaffe2_libtorch.so+0x31133ea)
    #5 torch::jit::ProfileOp::cloneFrom(torch::jit::Node*) caffe2/torch/csrc/jit/ir/ir.cpp:2131 (libcaffe2_libtorch.so+0x312084f)
    #6 torch::jit::Graph::createClone(torch::jit::Node*, std::function<torch::jit::Value* (torch::jit::Value*)> const&, bool) caffe2/torch/csrc/jit/ir/ir.cpp:1868 (libcaffe2_libtorch.so+0x310b7f7)
    #7 torch::jit::Block::cloneFrom(torch::jit::Block*, std::function<torch::jit::Value* (torch::jit::Value*)>) caffe2/torch/csrc/jit/ir/ir.cpp:670 (libcaffe2_libtorch.so+0x310b0f8)
    #8 torch::jit::Graph::createClone(torch::jit::Node*, std::function<torch::jit::Value* (torch::jit::Value*)> const&, bool) caffe2/torch/csrc/jit/ir/ir.cpp:1874 (libcaffe2_libtorch.so+0x310b9e2)
    #9 torch::jit::Block::cloneFrom(torch::jit::Block*, std::function<torch::jit::Value* (torch::jit::Value*)>) caffe2/torch/csrc/jit/ir/ir.cpp:670 (libcaffe2_libtorch.so+0x310b0f8)
    #10 torch::jit::Graph::copy() caffe2/torch/csrc/jit/ir/ir.cpp:705 (libcaffe2_libtorch.so+0x310c529)
    #11 torch::jit::ProfilingGraphExecutorImpl::getOptimizedPlanFor(std::vector<c10::IValue, std::allocator<c10::IValue> >&, unsigned long) caffe2/torch/csrc/jit/runtime/profiling_graph_executor_impl.cpp:617 (libcaffe2_libtorch.so+0x35a44c7)
    #12 torch::jit::ProfilingGraphExecutorImpl::getPlanFor(std::vector<c10::IValue, std::allocator<c10::IValue> >&, unsigned long) caffe2/torch/csrc/jit/runtime/profiling_graph_executor_impl.cpp:640 (libcaffe2_libtorch.so+0x35a50b9)
    #13 torch::jit::GraphExecutorImplBase::runAsync(std::vector<c10::IValue, std::allocator<c10::IValue> >&, std::function<void (std::function<void ()>)>) caffe2/torch/csrc/jit/runtime/graph_executor.cpp:569 (libcaffe2_libtorch.so+0x2ef4efe)
    #14 torch::jit::GraphExecutor::runAsync(std::vector<c10::IValue, std::allocator<c10::IValue> >&, std::function<void (std::function<void ()>)>) caffe2/torch/csrc/jit/runtime/graph_executor.cpp:772 (libcaffe2_libtorch.so+0x2ef5b61)
    #15 torch::jit::GraphFunction::runAsync(std::vector<c10::IValue, std::allocator<c10::IValue> >&, std::function<void (std::function<void ()>)>) caffe2/torch/csrc/jit/api/function_impl.cpp:45 (libcaffe2_libtorch.so+0x2ed7b03)
```

## To Reproduce

Run `test_stress_heavy_rpc_torchscript` with @mode/dev-tsan

cc @gmagogsfm