Skip to content

TORCH loading documentation and/or error #126

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
stockholmux opened this issue May 22, 2019 · 4 comments
Open

TORCH loading documentation and/or error #126

stockholmux opened this issue May 22, 2019 · 4 comments
Assignees

Comments

@stockholmux
Copy link
Contributor

I'm attempting to load in a Torch model and I'm a little unsure of what RedisAI is expecting It doesn't seem to be documented, so I'm assuming it's the result of torch.save, but that doesn't seem to work.

As a test, I'm using the AllenNLP tutorial then trying to load one of the models it generates like this:

$ redis-cli -p 9379 -x AI.MODELSET  test TORCH CPU < /tmp/model.th

Yet it results in the following error:

ERR: [enforce fail at inline_container.cc:127] . PytorchStreamReader failed reading zip archive: failed finding central directory
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7fe485ce6021 in /usr/lib/redis/modules/libc10.so)
frame #1: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x49 (0x7fe485ce5dc9 in /usr/lib/redis/modules/libc10.so)
frame #2: torch::jit::PyTorchStreamReader::valid(char const*) + 0x80 (0x7fe4876cec30 in /usr/lib/redis/modules/libcaffe2.so)
frame #3: torch::jit::PyTorchStreamReader::PyTorchStreamReader(std::string, std::istream*) + 0x1e6 (0x7fe4876d0c36 in /usr/lib/redis/modules/libcaffe2.so)
frame #4: <unknown function> + 0x656543 (0x7fe490329543 in /usr/lib/redis/modules/libtorch.so.1)
frame #5: torch::jit::load(std::istream&, c10::optional<c10::Device>) + 0x7f (0x7fe49032c8cf in /usr/lib/redis/modules/libtorch.so.1)
frame #6: torchLoadModel + 0xeb (0x7fe4975d8ddf in /usr/lib/redis/modules/redisai.so)
frame #7: RAI_ModelCreateTorch + 0x7b (0x7fe4975c812c in /usr/lib/redis/modules/redisai.so)
frame #8: RAI_ModelCreate + 0x83 (0x7fe4975cfb40 in /usr/lib/redis/modules/redisai.so)
frame #9: RedisAI_ModelSet_RedisCommand + 0x52b (0x7fe4975cb8df in /usr/lib/redis/modules/redisai.so)
frame #10: RedisModuleCommandDispatcher + 0x49 (0x561b46ad2ec9 in redis-server *:6379)
frame #11: call + 0xa7 (0x561b46a636a7 in redis-server *:6379)
frame #12: processCommand + 0x35f (0x561b46a63d5f in redis-server *:6379)
frame #13: processInputBuffer + 0x185 (0x561b46a73e35 in redis-server *:6379)
frame #14: aeProcessEvents + 0x2a0 (0x561b46a5d870 in redis-server *:6379)
frame #15: aeMain + 0x2b (0x561b46a5db0b in redis-server *:6379)
frame #16: main + 0x4d3 (0x561b46a5a803 in redis-server *:6379)
frame #17: __libc_start_main + 0xf1 (0x7fe4999e62e1 in /lib/x86_64-linux-gnu/libc.so.6)
frame #18: _start + 0x2a (0x561b46a5aa6a in redis-server *:6379)
@hhsecond
Copy link

For your current issue: You should use the binary from torch.jit.save instead of torch.save. Also, torch.jit.save expects you to pass a torchscript model.

@lantiga
Copy link
Contributor

lantiga commented May 23, 2019

A complete description on how to save a JIT'ed model in PyTorch is here: https://pytorch.org/tutorials/advanced/cpp_export.html

For simple models, you can follow this:
https://github.com/RedisAI/redisai-examples/blob/master/models/imagenet/pytorch/model_saver.py

We certainly need good documentation on how to export models from the various frameworks for GA.

Also, @hhsecond has added some support for exporting to the redisai-py client https://github.com/RedisAI/redisai-py/blob/master/test/test_model.py
which should cover the standard cases.

@hhsecond
Copy link

hhsecond commented Jun 12, 2019

Continuing this and #139, I have a plan to make a set of tutorial documentation at https://oss.redislabs.com/redisai/.
These are the heads I am planning to cover. What do you think? @lantiga

  • Setting up RedisAI (docker, install from source, installing Redis etc)
  • Exporting graphs from different frameworks and importing that to RedisAI
  • PyTorch example
  • Tensorflow example
  • MxNet/PyTorch/Tensorflow -> ONNX example
  • ScikitLearn example
  • Sentinel example
  • Cluster example (I understand it's not straight forward now, may be we could skip it for now)

@lantiga
Copy link
Contributor

lantiga commented Jun 12, 2019

I was also thinking something on these lines. Absolutely, by all means feel free to move ahead with this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants