Skip to content

Commit 9adc16f

Browse files
Updated documentation with some performance considerations (#262)
* [add] added mention to THREADS_PER_QUEUE feature. [add] splitted configuration options * [add] documented Intermediate tensors memory overhead when issuing AI.MODELRUN and AI.SCRIPTRUN * [add] Document the overhead of AI.TENSORGET and AI.TENSORSET with the optional arg VALUES * [add] extended configuration documentation per PR review * Update configuring.md Co-authored-by: Luca Antiga <[email protected]>
1 parent 7e6ec5f commit 9adc16f

File tree

3 files changed

+157
-30
lines changed

3 files changed

+157
-30
lines changed

docs/commands.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
# RedisAI Commands
22

3-
## AI.CONFIG LOADBACKEND
4-
5-
Load a DL/ML backend.
6-
7-
By default, RedisAI starts with the ability to set and get tensor data, but setting and running models and scritps requires a computing backend to be loaded. This command allows to dynamically load a backend by specifying the backend identifier and the path to the backend library. Currently, once loaded, a backend cannot be unloaded, and there can be at most one backend per identifier loaded.
8-
9-
```sql
10-
AI.CONFIG LOADBACKEND <backend_identifier> <location_of_backend_library>
11-
```
12-
13-
* allowed backend identifiers are: TF (TensorFlow), TORCH (PyTorch), ONNX (ONNXRuntime).
14-
15-
It is possible to specify backends at the command-line when starting `redis-server`, see example below.
16-
17-
### AI.CONFIG LOADBACKEND Example
18-
19-
> Load the TORCH backend
20-
21-
```sql
22-
AI.CONFIG LOADBACKEND TORCH install/backend/redisai_torch/redisai_torch.so
23-
```
24-
25-
> Load the TORCH backend at the command-line
26-
27-
```bash
28-
redis-server --loadmodule install/redisai.so TORCH install/backend/redisai_torch/redisai_torch.so
29-
```
30-
31-
This replaces the need for loading a backend using AI.CONFIG LOADBACKEND
32-
333
## AI.TENSORSET
344

355
Set a tensor.
@@ -61,6 +31,11 @@ Optional args:
6131
AI.TENSORSET foo FLOAT 2 2 VALUES 1 2 3 4
6232
```
6333

34+
!!! warning "Overhead of `AI.TENSORSET` with the optional arg VALUES"
35+
36+
It is possible to set a tensor by specifying each individual value (VALUES ... ) or the entire tensor content as a binary buffer (BLOB ...). You should always try to use the `BLOB` option since it removes the overhead of parsing each individual value and does not require serialization/deserialization of the tensor, thus reducing the overall command latency an improving the maximum attainable performance of the model server.
37+
---
38+
6439
## AI.TENSORGET
6540

6641
Get a tensor.
@@ -82,6 +57,11 @@ Get binary data for tensor at `foo`. Meta data is also returned.
8257
AI.TENSORGET foo BLOB
8358
```
8459

60+
!!! warning "Overhead of `AI.TENSORGET` with the optional arg VALUES"
61+
62+
It is possible to receive a tensor as a list of each individual value (VALUES ... ) or the entire tensor content as a binary buffer (BLOB ...). You should always try to use the `BLOB` option since it removes the overhead of replying each individual value and does not require serialization/deserialization of the tensor, thus reducing the overall command latency an improving the maximum attainable performance of the model server.
63+
---
64+
8565
## AI.MODELSET
8666

8767
Set a model.
@@ -159,6 +139,13 @@ If needed, input tensors are copied to the device specified in `AI.MODELSET` bef
159139
AI.MODELRUN resnet18 INPUTS image12 OUTPUTS label12
160140
```
161141

142+
!!! warning "Intermediate tensors memory overhead when issuing `AI.MODELRUN` and `AI.SCRIPTRUN`"
143+
144+
The execution of models will generate intermediate tensors that are not allocated by the Redis allocator, but by whatever allocator is used in the backends (which may act on main memory or GPU memory, depending on the device), thus not being limited by maxmemory settings on Redis.
145+
---
146+
147+
148+
162149
## AI.SCRIPTSET
163150

164151
Set a script.
@@ -235,6 +222,11 @@ If needed, input tensors are copied to the device specified in `AI.SCRIPTSET` be
235222
AI.SCRIPTRUN addscript addtwo INPUTS a b OUTPUTS c
236223
```
237224

225+
!!! warning "Intermediate tensors memory overhead when issuing `AI.MODELRUN` and `AI.SCRIPTRUN`"
226+
227+
The execution of models will generate intermediate tensors that are not allocated by the Redis allocator, but by whatever allocator is used in the backends (which may act on main memory or GPU memory, depending on the device), thus not being limited by maxmemory settings on Redis.
228+
---
229+
238230
## AI.INFO
239231

240232
Return information about runs of a `MODEL` or a `SCRIPT`.

docs/configuring.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Configuration
2+
3+
RedisAI supports both run-time configuration options and others that should be specified when loading the module.
4+
5+
## Configuration Options During Loading
6+
7+
In general, passing configuration options is done by appending arguments after the `--loadmodule` argument in the command line, `loadmodule` configuration directive in a Redis config file, or the `MODULE LOAD` command.
8+
9+
The module dynamic library `redisai.so` can be located in any path, provided that we specify the full path or a path relative to where the `redis-server` command is issued. The additional arguments are options passed to the module. Currently the supported options are:
10+
11+
- `BACKENDSPATH`: specify the default backends path used when loading a dynamic backend library.
12+
- `TORCH`: specify the location of the PyTorch backend library, and dynamically load it. The location can be given in two ways, absolute or relative to the `<BACKENDSPATH>`. Using this option replaces the need for loading the PyTorch backend on runtime.
13+
- `TF`: specify the location of the TensorFlow backend library, and dynamically load it. The location can be given in two ways, absolute or relative to the `<BACKENDSPATH>`. Using this option replaces the need for loading the TensorFlow backend on runtime.
14+
- `TFLITE`: specify the location of the TensorFlow Lite backend library, and dynamically load it. The location can be given in two ways, absolute or relative to the `<BACKENDSPATH>`. Using this option replaces the need for loading the TensorFlow Lite backend on runtime.
15+
- `ONNX`: specify the location of the ONNXRuntime backend library, and dynamically load it. The location can be given in two ways, absolute or relative to the `<BACKENDSPATH>`. Using this option replaces the need for loading the ONNXRuntime backend on runtime.
16+
- `THREADS_PER_QUEUE`: specify the fixed number of worker threads up front per device. This option is described in detail at [THREADS_PER_QUEUE](##THREADS_PER_QUEUE) section and can be only set when loading the module.
17+
18+
19+
### Configuration Examples
20+
21+
In redis.conf:
22+
23+
```
24+
loadmodule redisai.so OPT1 OPT2
25+
```
26+
27+
From redis-cli:
28+
29+
```
30+
127.0.0.6379> MODULE load redisai.so OPT1 OPT2
31+
```
32+
33+
From command line using relative path:
34+
35+
```
36+
$ redis-server --loadmodule ./redisai.so OPT1 OPT2
37+
```
38+
39+
From command line using full path:
40+
41+
```
42+
$ redis-server --loadmodule /usr/lib/redis/modules/redisai.so OPT1 OPT2
43+
```
44+
45+
46+
### THREADS_PER_QUEUE
47+
48+
```
49+
THREADS_PER_QUEUE {number}
50+
```
51+
Enable configuring the main thread to create a fixed number of worker threads up front per device. This controls the maximum number of threads to be used for parallel execution of independent different operations.
52+
53+
This option can significantly improve the model run performance for simple models (models that require low computation effort), since there is usually room for extra computation on modern CPU's and hardware accelerators (GPUs, TPUs, etc.).
54+
55+
#### THREADS_PER_QUEUE Default
56+
57+
By default only one worker thread is used per device.
58+
59+
#### THREADS_PER_QUEUE Example
60+
61+
```
62+
$ redis-server --loadmodule ./redisai.so THREADS_PER_QUEUE 4
63+
```
64+
65+
---
66+
67+
68+
## Setting Configuration Options In Run-Time
69+
70+
### AI.CONFIG BACKENDSPATH
71+
72+
Specify the default backends path to use when dynamically loading a backend.
73+
74+
```sql
75+
AI.CONFIG BACKENDSPATH <default_location_of_backend_libraries>
76+
```
77+
78+
#### AI.CONFIG BACKENDSPATH Example
79+
80+
81+
```sql
82+
AI.CONFIG BACKENDSPATH /usr/lib/redis/modules/redisai/backends
83+
```
84+
85+
### AI.CONFIG LOADBACKEND
86+
87+
Load a DL/ML backend.
88+
89+
```sql
90+
AI.CONFIG LOADBACKEND <backend_identifier> <location_of_backend_library>
91+
```
92+
93+
RedisAI currently supports PyTorch (libtorch), Tensorflow (libtensorflow), TensorFlow Lite, and ONNXRuntime as backends.
94+
95+
Allowed backend identifiers are:
96+
- `TF` (TensorFlow)
97+
- `TFLITE` (TensorFlow Lite)
98+
- `TORCH` (PyTorch)
99+
- `ONNX` (ONNXRuntime)
100+
101+
102+
103+
By default, RedisAI starts with the ability to set and get tensor data, but setting and running models and scritps requires a computing backend to be loaded, which can be done during loading, as [explained above](##-Configuration-Options-During-Loading), or at or run-time using the `AI.CONFIG` commmand.
104+
105+
This command allows to dynamically load a backend by specifying the backend identifier and the path to the backend library. Currently, once loaded, a backend cannot be unloaded, and there can be at most one backend per identifier loaded.
106+
107+
108+
If you don't specify a backend on load time, RedisAI will look into the default location lazily, when a model of a given backend is loaded.
109+
110+
The default location relative to the `<BACKENDSPATH>` directory. If unspecified, by default RedisAI will look for:
111+
- ONNXRuntime dynamic library at: `<BACKENDSPATH>/redisai_onnxruntime/redisai_onnxruntime.so`
112+
- TensorFlow dynamic library at: `<BACKENDSPATH>/redisai_tensorflow/redisai_tensorflow.so`
113+
- TensorFlow Lite dynamic library at: `<BACKENDSPATH>/redisai_tflite/redisai_tflite.so`
114+
- PyTorch dynamic library at: `<BACKENDSPATH>/redisai_torch/redisai_torch.so`
115+
116+
Any library dependency will be resolved automatically, and the mentioned directories are portable on all platforms.
117+
118+
If relative, it is relative to `<BACKENDSPATH>`.
119+
120+
121+
#### AI.CONFIG LOADBACKEND Examples
122+
123+
Load the TORCH backend, relative to `BACKENDSPATH`
124+
125+
```sql
126+
AI.CONFIG LOADBACKEND TORCH redisai_torch/redisai_torch.so
127+
```
128+
129+
Load the TORCH backend, specifying full path
130+
131+
132+
```sql
133+
AI.CONFIG LOADBACKEND TORCH /usr/lib/redis/modules/redisai/backends/redisai_torch/redisai_torch.so
134+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pages:
2727
- 'Quickstart': index.md
2828
- 'Commands': commands.md
2929
- 'Backend': dataandbackend.md
30+
- 'Configuration': configuring.md
3031

3132
markdown_extensions:
3233
- admonition

0 commit comments

Comments
 (0)