Skip to content

Segfault on unloading a model #5453

Closed
Closed
@seanxhughes

Description

@seanxhughes

Hi,
I'm using pytorch compiled from source and with this very simple program which successfully loads a pre-trained model, then terminates I get a segfault in the sequence of destructors - anyone seen this before?

Code

#include <iostream>
#include <torch/script.h> 
#include <memory>

int main(int argc, char **argv)
{

    try {
        std::cout << "Attempting to load " << argv[1] << "\n";
        // Deserialize the ScriptModule from a file using torch::jit::load().
        auto module = torch::jit::load(argv[1]);

        std::cout << "Model loaded\n";
    }
    catch (const c10::Error& e) {
        std::cerr << "Error loading Pytorch model " << e.msg() << "\n";
        return -1;
    }

    return 0;
}

Stack trace

#0 0x000055555555a27a in c10::IValue::isTensor (this=0x80) at /usr/local/libtorch/include/ATen/core/ivalue.h:394
#1 0x000055555555ac77 in c10::IValue::destroy (this=0x80) at /usr/local/libtorch/include/ATen/core/ivalue.h:991
#2 0x000055555555a24c in c10::IValue::~IValue (this=0x80, __in_chrg=) at /usr/local/libtorch/include/ATen/core/ivalue.h:197
#3 0x0000555555561419 in std::_Destroyc10::IValue (__pointer=0x80) at /usr/include/c++/9/bits/stl_construct.h:98
#4 0x00005555555604a2 in std::_Destroy_aux::__destroyc10::IValue* (__first=0x80, __last=0x21) at /usr/include/c++/9/bits/stl_construct.h:108
#5 0x000055555555f324 in std::_Destroyc10::IValue* (__first=0x80, __last=0x21) at /usr/include/c++/9/bits/stl_construct.h:137
#6 0x000055555555d79d in std::_Destroy<c10::IValue*, c10::IValue> (__first=0x80, __last=0x21) at /usr/include/c++/9/bits/stl_construct.h:206
#7 0x000055555555c151 in std::__cxx1998::vector<c10::IValue, std::allocatorc10::IValue >::~vector (this=0x555556b2e6d0, __in_chrg=) at /usr/include/c++/9/bits/stl_vector.h:677
#8 0x000055555555a220 in std::__debug::vector<c10::IValue, std::allocatorc10::IValue >::~vector (this=0x555556b2e6b8, __in_chrg=) at /usr/include/c++/9/debug/vector:220
#9 0x000055555555dbf6 in c10::ivalue::Object::~Object (this=0x555556b2e660, __in_chrg=) at /usr/local/libtorch/include/ATen/core/ivalue_inl.h:1328
#10 0x000055555555dc32 in c10::ivalue::Object::~Object (this=0x555556b2e660, _in_chrg=) at /usr/local/libtorch/include/ATen/core/ivalue_inl.h:1328
#11 0x000055555555dd6d in c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_typec10::ivalue::Object >::reset
(this=0x7fffffffdcb0) at /usr/local/libtorch/include/c10/util/intrusive_ptr.h:289
#12 0x000055555555c37c in c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_typec10::ivalue::Object >::~intrusive_ptr (this=0x7fffffffdcb0, __in_chrg=) at /usr/local/libtorch/include/c10/util/intrusive_ptr.h:366
#13 0x000055555555b460 in torch::jit::Object::~Object (this=0x7fffffffdcb0, __in_chrg=) at /usr/local/libtorch/include/torch/csrc/jit/api/object.h:24
#14 0x000055555555b480 in torch::jit::Module::~Module (this=0x7fffffffdcb0, __in_chrg=) at /usr/local/libtorch/include/torch/csrc/jit/api/module.h:98
#15 0x00005555555589be in main (argc=2, argv=0x7fffffffddf8) at ./exe/hello_world.cpp:87

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions