RedisAI/redisai-py

Response error for pytorch

Distortedlogic opened this issue · 2 comments

import redisai as rai
import torch
import torchvision
import ml2rt

conn = rai.Client(host='redis', port='6379')
vgg16 = torchvision.models.vgg16(pretrained=True)
vgg16_no_top = torch.nn.Sequential(*(list(vgg16.children())[:-3]))
torch.save(vgg16_no_top, 'vgg16_no_top.pt')
vgg16_no_top= ml2rt.load_model('vgg16_no_top.pt')
conn.modelset(
            'vgg16',
            'torch',
            device,
            vgg16_no_top
        )

throws

vgg16_no_top
  File "/usr/local/lib/python3.7/site-packages/redisai/client.py", line 228, in modelset
    return self.execute_command(*args).decode()
  File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 878, in execute_command
    return self.parse_response(conn, command_name, **options)
  File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 892, in parse_response
    response = connection.read_response()
  File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 752, in read_response
    raise response
redis.exceptions.ResponseError: [enforce fail at inline_container.cc:208] . file not found: archive/constants.pkl frame #0: c10::ThrowEn
forceNotMet(char const*, int, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void
const*) + 0x67 (0x7fa9d4010787 in /usr/lib/redis/modules/backends/redisai_torch/lib/libc10.so) frame #1: caffe2::serialize::PyTorchStrea
mReader::getRecordID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0xd6 (0x7fa9c6f84376 in /
usr/lib/redis/modules/backends/redisai_torch/lib/libtorch_cpu.so) frame #2: caffe2::serialize::PyTorchStreamReader::getRecord(std::__cxx
11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x38 (0x7fa9c6f85018 in /usr/lib/redis/modules/backends/
redisai_torch/lib/libtorch_cpu.so) frame #3: 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::functio
n<c10::intrusive_ptr<c10::ivalue::Object, c10::detail::intrusive_target_default_null_type<c10::ivalue::Object> > (c10::StrongTypePtr, c1
0::IValue)> >, c10::optional<c10::Device>, caffe2::serialize::PyTorchStreamReader&) + 0xda (0x7fa9c80083aa in /usr/lib/redis/modules/bac
kends/redisai_torch/lib/libtorch_cpu.so) frame #4: <unknown function> + 0x2f3bc9d (0x7fa9c8008c9d in /usr/lib/redis/modules/backends/red
isai_torch/lib/libtorch_cpu.so) frame #5: <unknown function> + 0x2f3e26f (0x7fa9c800b26f in /usr/lib/redis/modules/backends/redisai_torc
h/lib/libtorch_cpu.so) frame #6: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::s
erialize::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::basi
c_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> > > > >&) + 0x179 (0x7fa9c800bbf9 in /usr/lib/redis/modu
les/backends/redisai_torch/lib/libtorch_cpu.so) frame #7: 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<st
d::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<cha
r, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
 > > >&) + 0x75 (0x7fa9c800c3f5 in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch_cpu.so) frame #8: torchLoadModel + 0x215 (
0x7fa9d444b1e5 in /usr/lib/redis/modules/backends/redisai_torch/redisai_torch.so) frame #9: RAI_ModelCreateTorch + 0x8a (0x7fa9d444408a
in /usr/lib/redis/modules/backends/redisai_torch/redisai_torch.so) frame #10: RAI_ModelCreate + 0x16d (0x7fa9dcbebd2d in /usr/lib/redis/
modules/redisai.so) frame #11: RedisAI_ModelSet_RedisCommand + 0x6ea (0x7fa9dcbe452a in /usr/lib/redis/modules/redisai.so) frame #12: Re
disModuleCommandDispatcher + 0x54 (0x561d6f034ca4 in redis-server *:6379) frame #13: call + 0x9d (0x561d6efc0f0d in redis-server *:6379)
 frame #14: processCommand + 0x327 (0x561d6efc1687 in redis-server *:6379) frame #15: processCommandAndResetClient + 0x10 (0x561d6efcf28
0 in redis-server *:6379) frame #16: processInputBuffer + 0x18f (0x561d6efd37cf in redis-server *:6379) frame #17: <unknown function> +
0xd4b4c (0x561d6f050b4c in redis-server *:6379) frame #18: aeProcessEvents + 0x111 (0x561d6efbaa21 in redis-server *:6379) frame #19: ae
Main + 0x2b (0x561d6efbaeab in redis-server *:6379) frame #20: main + 0x4db (0x561d6efb77eb in redis-server *:6379) frame #21: __libc_st
art_main + 0xeb (0x7fa9dd44609b in /lib/x86_64-linux-gnu/libc.so.6) frame #22: _start + 0x2a (0x561d6efb7a7a in redis-server *:6379)

Hi @Distortedlogic,
I see two problems with the provided snippet.

  1. vgg16 will have only 3 "children" and you are removing all of them with your slice operation. I am assuming what you actually need is removing that last classifier. If that's the case, the line should work
vgg16_no_top = torch.nn.Sequential(*(list(vgg16.children())[:-1]))
  1. RedisAI expects a torchscript model but when you invoke torch.save on a native torch model object, you are essentially saving a python object which is not load-able into RedisAI. If you change that line to below, it should work
torch.jit.save(torch.jit.script(vgg16_no_top), 'vgg16_no_top.pt')

Another problem that I anticipate you might get after fixing these two issues is, the latest version of RedisAI expects your model to be built with 1.5 version of PyTorch instead of 1.6 (We are updating RedisAI to use 1.6 in a week or so)

yep, I was just tryina remove the 3 FC layers. Your comments fixed this for me, much thanks!