Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Core dump when trying to create empty IValue list for pytorch engine #1437

Closed
jiyuanq opened this issue Dec 30, 2021 · 4 comments
Closed

Core dump when trying to create empty IValue list for pytorch engine #1437

jiyuanq opened this issue Dec 30, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@jiyuanq
Copy link
Contributor

jiyuanq commented Dec 30, 2021

Description

Core dump when trying to create an empty IValue list with IValue.listFrom(new IValue[0]) with djl 0.14.0

However IValue.listFrom(new double[0]) works for creating an empty double list

Expected Behavior

It should successfully create an IValue instance which represents an empty list of IValues.

Error Message

Core dump

From JVM thread dump

Register to memory mapping:

RAX=0x0000000000000000 is an unknown value
RBX={method} {0x00007fa45f747a20} 'iValueFromList' '([J)J' in 'ai/djl/pytorch/jni/PyTorchLibrary'
RCX=0x00007fa48b3c4207: mprotect+0x7 in /lib/x86_64-linux-gnu/libc.so.6 at 0x00007fa48b2d0000
RDX=0x0000000000000000 is an unknown value
RSP=0x00007fa48a1301b0 is pointing into the stack for thread: 0x00007fa48400a800
RBP=0x00007fa48a1302f0 is pointing into the stack for thread: 0x00007fa48400a800
RSI=0x0000000000000000 is an unknown value
RDI=0x00007fa48a130290 is pointing into the stack for thread: 0x00007fa48400a800
R8 =0x00000000ffffffff is an unknown value
R9 =0x0000000000000000 is an unknown value
R10=0x0000000000004022 is an unknown value
R11=0x0000000000000206 is an unknown value
R12=0x0000000000000000 is an unknown value
R13={method} {0x00007fa45f747a20} 'iValueFromList' '([J)J' in 'ai/djl/pytorch/jni/PyTorchLibrary'
R14=0x00007fa48a130378 is pointing into the stack for thread: 0x00007fa48400a800
R15=0x00007fa48400a800 is a thread


Stack: [0x00007fa48a033000,0x00007fa48a133000],  sp=0x00007fa48a1301b0,  free space=1012k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libtorch_cpu.so+0xef892a]  c10::IValue::type() const+0x1a
j  ai.djl.pytorch.jni.PyTorchLibrary.iValueFromList([J)J+0
j  ai.djl.pytorch.jni.IValue.listFrom([Lai/djl/pytorch/jni/IValue;)Lai/djl/pytorch/jni/IValue;+28

How to Reproduce?

IValue emptyList = IValue.listFrom(new IValue[0]);

Steps to reproduce

Simply run the above code from java

What have you tried to solve it?

looks like it's an issue with the JNI layer, so not much i can do without changing it.

Environment Info

--------------- Hardware --------------
Available processors (cores): 4
Byte Order: LITTLE_ENDIAN
Free memory (bytes): 210618976
Maximum memory (bytes): 3663200256
Total memory available to JVM (bytes): 247463936
Heap committed: 247463936
Heap nonCommitted: 30212096
GCC: 
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@jiyuanq jiyuanq added the bug Something isn't working label Dec 30, 2021
@jiyuanq jiyuanq changed the title Unable to create empty IValue list for pytorch engine Core dump when trying to create empty IValue list for pytorch engine Dec 30, 2021
frankfliu added a commit to frankfliu/djl that referenced this issue Dec 31, 2021
Change-Id: If6bebfef02efb1d42b65b1dd58b591df8274ff24
@frankfliu
Copy link
Contributor

frankfliu commented Dec 31, 2021

@jiyuanq

In libtorch, IValue list is a typed list, which means all the IValue in the list must be the same type. When creating an empty IValue list, we won't be able to detect the type. The possible solutions might be add a few new APIs:

IValue.emptyIValueList(long.class)

I'm not sure how useful this emptyList API in real world.

For now I will add a check to prevent the crash.

@jiyuanq
Copy link
Contributor Author

jiyuanq commented Jan 3, 2022

@frankfliu I think empty lists are not uncommon.
For example, if I need to pass in a list of strings to a torchscripted preprocessing module, the list itself can be empty to represent missing data or simply no observation.
We can also use None but looks like that’s not supported by DJL either.
Both None and empty IValue list seems to be supported in pytorch Android java api, so it would be really nice to make feature parity

@frankfliu
Copy link
Contributor

@jiyuanq
Can you use empty tuple? empty tuple works fine.

We will take a look and see if we can add the feature with a nice API

@jiyuanq
Copy link
Contributor Author

jiyuanq commented Jan 3, 2022

@frankfliu
not sure if torchscript Tuples can have variable length… I’m under the impression the each element needs to be type annotated

Anyway thanks for considering adding this feature! Let me know how it goes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants