Skip to content

Commit 667fc42

Browse files
authored
ONNXRuntime backend (#138)
* WIP adding ONNXRuntime * WIP2 adding ONNXRuntime * Add comment * Remove commented code * Implement DLTensor conversion from/to ORT Value * ONNX runtime working * Complete first pass of ONNXRuntime integration * Updated docs * Updated README * Don't release info too soon. Thanks to @hhsecond for catching the crash * Bump the base image on CI * Address review comments
1 parent 29a6f57 commit 667fc42

28 files changed

+830
-27
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/python:3.6.1
5+
- image: circleci/python:3.6.8
66

77
steps:
88
- checkout

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
1818
SET(CMAKE_C_STANDARD 99)
1919

2020
FIND_LIBRARY(TF_LIBRARIES NAMES tensorflow libtensorflow.so)
21-
2221
IF (NOT TF_LIBRARIES)
2322
MESSAGE(FATAL_ERROR "Could not find tensorflow")
2423
ENDIF()
2524

25+
FIND_LIBRARY(ORT_LIBRARIES NAMES onnxruntime)
26+
IF (NOT ORT_LIBRARIES)
27+
MESSAGE(FATAL_ERROR "Could not find ONNXRuntime")
28+
ENDIF()
29+
2630
INCLUDE_DIRECTORIES(${depsAbs}/libtensorflow/include)
2731

2832
IF (APPLE)
@@ -41,7 +45,7 @@ ADD_DEFINITIONS(-DREDISMODULE_EXPERIMENTAL_API)
4145
ADD_SUBDIRECTORY(util/libtorch_c)
4246
ADD_SUBDIRECTORY(src)
4347
ADD_LIBRARY(redisai SHARED $<TARGET_OBJECTS:redisai_obj>)
44-
TARGET_LINK_LIBRARIES(redisai torch_c ${TF_LIBRARIES} ${platDeps})
48+
TARGET_LINK_LIBRARIES(redisai ${ORT_LIBRARIES} torch_c ${TF_LIBRARIES} ${platDeps})
4549

4650
SET_TARGET_PROPERTIES(redisai PROPERTIES PREFIX "")
4751
SET_TARGET_PROPERTIES(redisai PROPERTIES SUFFIX ".so")

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ redis-cli
4646

4747
## Building
4848
This will checkout and build and download the libraries for the backends
49-
(TensorFlow and PyTorch) for your platform.
49+
(TensorFlow, PyTorch, ONNXRuntime) for your platform.
5050

5151
```sh
5252
bash get_deps.sh
@@ -89,15 +89,14 @@ Some languages have client libraries that provide support for RedisAI's commands
8989
| JRedisAI | Java | BSD-3 | [RedisLabs](https://redislabs.com/) | [Github](https://github.com/RedisAI/JRedisAI) |
9090
| redisai-py | Python | BSD-3 | [RedisLabs](https://redislabs.com/) | [Github](https://github.com/RedisAI/redisai-py) |
9191

92-
9392
## Backend Dependancy
9493

95-
RedisAI currently supports PyTorch (libtorch) and Tensorflow (libtensorflow) as backends. We are also building support for ONNXRuntime backend soon. This section shows the version map between RedisAI and supported backends. This extremely important since the serialization mechanism of one version might not match with another. For making sure your model will work with a given RedisAI version, check with the backend documentation about incompatible features between the version of your backend and the version RedisAI is built with.
94+
RedisAI currently supports PyTorch (libtorch), Tensorflow (libtensorflow) and ONNXRuntime as backends. This section shows the version map between RedisAI and supported backends. This extremely important since the serialization mechanism of one version might not match with another. For making sure your model will work with a given RedisAI version, check with the backend documentation about incompatible features between the version of your backend and the version RedisAI is built with.
9695

9796

9897
| RedisAI | PyTorch | TensorFlow | ONNXRuntime |
9998
|:--------|:-------:|:----------:|:-------------:|
100-
| 0.1.0 | 1.0.1 | 1.12.0 | Not Yet |
99+
| 0.1.0 | 1.0.1 | 1.12.0 | 0.4.0 |
101100

102101

103102
## Documentation

docs/commands.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ AI.MODELSET model_key backend device [INPUTS name1 name2 ... OUTPUTS name1 name2
6161
```
6262

6363
* model_key - Key for storing the model
64-
* backend - The backend corresponding to the model being set. Allowed values: `TF`, `TORCH`.
64+
* backend - The backend corresponding to the model being set. Allowed values: `TF`, `TORCH`, `ONNX`.
6565
* device - Device where the model is loaded and where the computation will run. Allowed values: `CPU`, `GPU`.
6666
* INPUTS name1 name2 ... - Name of the nodes in the provided graph corresponding to inputs [`TF` backend only]
6767
* OUTPUTS name1 name2 ... - Name of the nodes in the provided graph corresponding to outputs [`TF` backend only]
@@ -77,6 +77,10 @@ AI.MODELSET resnet18 TORCH GPU < foo.pt
7777
AI.MODELSET resnet18 TF CPU INPUTS in1 OUTPUTS linear4 < foo.pt
7878
```
7979

80+
```sql
81+
AI.MODELSET mnist_net ONNX CPU < mnist.onnx
82+
```
83+
8084
## AI.MODELGET
8185

8286
Get a model.

examples/models/linear_iris.onnx

277 Bytes
Binary file not shown.

examples/models/load_onnx_model.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
REDIS_CLI=redis-cli
2+
3+
echo "SET MODEL"
4+
$REDIS_CLI -x AI.MODELSET foo ONNX CPU < mnist.onnx
5+
# $REDIS_CLI AI.MODELGET foo
6+
7+
echo "SET TENSORS"
8+
$REDIS_CLI -x AI.TENSORSET a FLOAT 1 1 28 28 BLOB < one.raw
9+
10+
echo "GET TENSORS"
11+
$REDIS_CLI AI.TENSORGET a META
12+
13+
echo "RUN MODEL"
14+
$REDIS_CLI AI.MODELRUN foo INPUTS a OUTPUTS b
15+
16+
echo "GET TENSOR META"
17+
$REDIS_CLI AI.TENSORGET b META
18+
19+
echo "GET TENSOR VALUES"
20+
$REDIS_CLI AI.TENSORGET b VALUES
21+
22+
echo "GET TENSOR BLOB"
23+
# $REDIS_CLI --raw AI.TENSORGET b BLOB
24+
$REDIS_CLI AI.TENSORGET b BLOB
25+
26+
$REDIS_CLI DEL foo a b

examples/models/load_onnxml_model.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
REDIS_CLI=redis-cli
2+
3+
echo "SET MODEL"
4+
$REDIS_CLI -x AI.MODELSET foo ONNX CPU < logreg_iris.onnx
5+
# $REDIS_CLI AI.MODELGET foo
6+
7+
echo "SET TENSORS"
8+
$REDIS_CLI AI.TENSORSET a FLOAT 1 4
9+
10+
echo "GET TENSORS"
11+
$REDIS_CLI AI.TENSORGET a META
12+
13+
echo "RUN MODEL"
14+
$REDIS_CLI AI.MODELRUN foo INPUTS a OUTPUTS b c
15+
16+
echo "GET TENSOR META"
17+
$REDIS_CLI AI.TENSORGET b META
18+
19+
echo "GET TENSOR VALUES"
20+
$REDIS_CLI AI.TENSORGET b VALUES
21+
22+
echo "GET TENSOR VALUES"
23+
$REDIS_CLI AI.TENSORGET c VALUES
24+
25+
echo "GET TENSOR BLOB"
26+
# $REDIS_CLI --raw AI.TENSORGET b BLOB
27+
$REDIS_CLI AI.TENSORGET b BLOB
28+
29+
$REDIS_CLI DEL foo a b
30+
31+
32+
echo "SET MODEL"
33+
$REDIS_CLI -x AI.MODELSET foo ONNX CPU < linear_iris.onnx
34+
# $REDIS_CLI AI.MODELGET foo
35+
36+
echo "SET TENSORS"
37+
$REDIS_CLI AI.TENSORSET a FLOAT 1 4
38+
39+
echo "GET TENSORS"
40+
$REDIS_CLI AI.TENSORGET a META
41+
42+
echo "RUN MODEL"
43+
$REDIS_CLI AI.MODELRUN foo INPUTS a OUTPUTS b
44+
45+
echo "GET TENSOR META"
46+
$REDIS_CLI AI.TENSORGET b META
47+
48+
echo "GET TENSOR VALUES"
49+
$REDIS_CLI AI.TENSORGET b VALUES
50+
51+
echo "GET TENSOR BLOB"
52+
# $REDIS_CLI --raw AI.TENSORGET b BLOB
53+
$REDIS_CLI AI.TENSORGET b BLOB
54+
55+
$REDIS_CLI DEL foo a b

examples/models/load_model.sh renamed to examples/models/load_tf_model.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
REDIS_CLI=../../deps/redis/src/redis-cli
1+
REDIS_CLI=redis-cli
22

33
echo "SET MODEL"
44
$REDIS_CLI -x AI.MODELSET foo TF GPU INPUTS a b OUTPUTS mul < graph.pb
5-
$REDIS_CLI AI.MODELGET foo
5+
#$REDIS_CLI AI.MODELGET foo
66

77
echo "SET TENSORS"
88
$REDIS_CLI AI.TENSORSET a FLOAT 2 VALUES 2 3

examples/models/load_torch_model.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
REDIS_CLI=../../deps/redis/src/redis-cli
1+
REDIS_CLI=redis-cli
22

33
echo "SET MODEL"
44
$REDIS_CLI -x AI.MODELSET foo TORCH CPU < pt-minimal.pt

examples/models/load_yolo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
REDIS_CLI=../../deps/redis/src/redis-cli
1+
REDIS_CLI=redis-cli
22

33
MODEL_FILE=tiny-yolo-voc.pb
44
INPUT_VAR=input

0 commit comments

Comments
 (0)