Skip to content

questions and help about libtorch under multi thread #23920

@wanggujin

Description

@wanggujin

i use libtorch v1.1.0 in c++,
but in multi thread program, the program will core dump in this funcion:

void ModelInference(const std::vector<torch::jit::IValue>& torch_inputs,
    std::shared_ptr<torch::jit::script::Module> torch_model_ptr,
    LaneSequence* lane_sequence_ptr) {
  auto torch_output_tuple = torch_model_ptr->forward(torch_inputs).toTuple();
   auto probability_tensor = torch_output_tuple->elements()[0].toTensor();
   auto finish_time_tensor = torch_output_tuple->elements()[1].toTensor();
}

some error message as follows:

terminate called after throwing an instance of 'c10::Error'
  what():  method 'forward' already defined. (insert at libtorch/include/torch/csrc/jit/script/module.h:515)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6a (0x7ffff49335ca in libtorch/lib/libc10.so)
frame #1: std::unique_ptr<torch::jit::script::Method, std::default_delete<torch::jit::script::Method> >& torch::jit::script::Module::insert<std::unique_ptr<torch::jit::script::Method, std::default_delete<torch::jit::script::Method> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::unique_ptr<torch::jit::script::Method, std::default_delete<torch::jit::script::Method> >, std::allocator<std::unique_ptr<torch::jit::script::Method, std::default_delete<torch::jit::script::Method> > > >&, torch::jit::script::Module::EntityType, std::unique_ptr<torch::jit::script::Method, std::default_delete<torch::jit::script::Method> >) + 0x20a 
frame #2: torch::jit::script::Module::find_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const + 0x167 
frame #3: torch::jit::script::Module::get_method(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const + 0x35 
frame #4: torch::jit::script::Module::forward(std::vector<c10::IValue, std::allocator<c10::IValue> >) + 0xb3 
frame #5: CruiseMLPEvaluator::ModelInference(std::vector<c10::IValue, std::allocator<c10::IValue> > const&, std::shared_ptr<torch::jit::script::Module>, LaneSequence*) + 0x5d

someone knows that's why? how can i solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions