I’m seeing the same issue using libtorch 1.8.0, compiling with clang 11.1 on Ubuntu focal. If std::regex_replace is used at all before loading a torchscript model then there will be a segfault when torch::jit::load is called to load the model.
Here’s the relevant part of the stacktrace for the segfault from gdb:
#0  std::__detail::_State<char>::_M_opcode (this=0x94ce81b480053a10)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/regex_automaton.h:166
#1  0x00007ffff7c7882f in std::__detail::_NFA<std::__cxx11::regex_traits<char> >::_M_eliminate_dummy (this=0x2111fa0)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/regex_automaton.tcc:182
#2  0x00007fffdf1cc828 in std::__detail::_Compiler<std::__cxx11::regex_traits<char> >::_Compiler(char const*, char const*, std::locale const&, std::regex_constants::syntax_option_type) () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#3  0x00007fffdf3ed405 in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#4  0x00007fffdf3f0d1c in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#5  0x00007fffdf3f164b in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#6  0x00007fffdf3f1a55 in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#7  0x00007fffdf3f1b3a in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#8  0x00007fffdf1504a1 in torch::jit::ScriptTypeParser::parseTypeFromExpr(torch::jit::Expr const&) const ()
   from /usr/local/lib/libtorch-1/libtorch_cpu.so
#9  0x00007fffdf150769 in torch::jit::ScriptTypeParser::parseType(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#10 0x00007fffdf3e2b4b in torch::jit::SourceImporter::loadType(c10::QualifiedName const&) const ()
   from /usr/local/lib/libtorch-1/libtorch_cpu.so
#11 0x00007fffdf3ce7cb in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#12 0x00007fffdf41e8c2 in torch::jit::Unpickler::readGlobal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
   from /usr/local/lib/libtorch-1/libtorch_cpu.so
#13 0x00007fffdf422cca in torch::jit::Unpickler::readInstruction() () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#14 0x00007fffdf4249e8 in torch::jit::Unpickler::run() () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#15 0x00007fffdf424c0e in torch::jit::Unpickler::parse_ivalue() () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#16 0x00007fffdf3ce441 in torch::jit::readArchiveAndTensors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, c10::optional<std::function<c10::StrongTypePtr (c10::QualifiedName const&)> >, c10::optional<std::function<c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_type<c10::ivalue::Object> > (c10::StrongTypePtr, c10::IValue)> >, c10::optional<c10::Device>, caffe2::serialize::PyTorchStreamReader&) () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#17 0x00007fffdf3ce6e0 in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#18 0x00007fffdf3d1587 in ?? () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#19 0x00007fffdf3d1c24 in torch::jit::load(std::shared_ptr<caffe2::serialize::ReadAdapterInterface>, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) () from /usr/local/lib/libtorch-1/libtorch_cpu.so
#20 0x00007fffdf3d4be5 in torch::jit::load(std::istream&, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) ()
   from /usr/local/lib/libtorch-1/libtorch_cpu.so
#21 0x00007fffdf3d4cef in torch::jit::load(std::istream&, c10::optional<c10::Device>) () from /usr/local/lib/libtorch-1/libtorch_cpu.so