Skip to content

Commit fcf17b8

Browse files
committed
Add command docs
1 parent eca36bc commit fcf17b8

File tree

1 file changed

+121
-19
lines changed

1 file changed

+121
-19
lines changed

docs/commands.md

Lines changed: 121 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,143 @@
11
# RedisAI Commands
22

3-
## AI.TENSORSET - Set a tensor
4-
Stores a tensor of defined type (FLOAT, DOUBLE, INT8, INT16, INT32, INT64, UINT8, UINT16) with N dimensions (dim) and shape given by shape1..shapeN
3+
## AI.TENSORSET - set a tensor
4+
> Stores a tensor of defined type with shape given by shape1..shapeN
55
6-
```sh
7-
AI.TENSORSET tensor_key data_type shape1..shapeN [BLOB data | VALUES val1..valN]
6+
```sql
7+
AI.TENSORSET tensor_key data_type shape1 shape2 ... [BLOB data | VALUES val1 val2 ...]
88
```
99

10-
## AI.TENSORGET - Get a tensor
10+
* tensor_key - key for storing the tensor
11+
* data_type - numeric data type of tensor elements, one of FLOAT, DOUBLE, INT8, INT16, INT32, INT64, UINT8, UINT16
12+
* shape - shape of the tensor, i.e. how many elements for each axis
1113

12-
```sh
14+
Optional args:
15+
* BLOB data - provide tensor content as a binary buffer
16+
* VALUES val1 val2 - provide tensor content as individual values
17+
18+
> If no BLOB or VALUES are specified, the tensor is allocated but not initialized to any value.
19+
20+
### Example
21+
> Set a 2x2 tensor at `foo`
22+
> 1 2
23+
> 3 4
24+
25+
```sql
26+
AI.TENSORSET foo FLOAT 2 2 VALUES 1 2 3 4
27+
```
28+
29+
## AI.TENSORGET - set a tensor
30+
```sql
1331
AI.TENSORGET tensor_key [BLOB | VALUES | META]
1432
```
1533

16-
## AI.MODELSET - Set a model
17-
Stores a model provided as a protobuf blob. Backend is TF or TORCH. The TF backend requires the name of input and output nodes to be specified in INPUTS and OUTPUTS.
18-
```sh
34+
* tensor_key - key for the tensor
35+
* BLOB - return tensor content as a binary buffer
36+
* VALUES - return tensor content as a list of values
37+
* META - only return tensor meta data (datat type and shape)
38+
39+
### Example
40+
> Get binary data for tensor at `foo`. Meta data is also returned.
41+
42+
```sql
43+
AI.TENSORGET foo BLOB
44+
```
45+
46+
## AI.MODELSET - set a model
47+
```sql
1948
AI.MODELSET model_key backend device [INPUTS name1 name2 ... OUTPUTS name1 name2 ...] model_blob
2049
```
2150

22-
## AI.MODELRUN - Run a model
23-
```sh
51+
* model_key - key for storing the model
52+
* backend - the backend corresponding to the model being set. Allowed values: `TF`, `TORCH`.
53+
* device - device where the model is loaded and where the computation will run. Allowed values: `CPU`, `GPU`.
54+
* INPUTS name1 name2 ... - name of the nodes in the provided graph corresponding to inputs [`TF` backend only]
55+
* OUTPUTS name1 name2 ... - name of the nodes in the provided graph corresponding to outputs [`TF` backend only]
56+
* model_blob - binary buffer containing the model protobuf saved from a supported backend
57+
58+
### Example
59+
60+
```sql
61+
AI.MODELSET resnet18 TORCH GPU < foo.pt
62+
```
63+
64+
```sql
65+
AI.MODELSET resnet18 TF CPU INPUTS in1 OUTPUTS linear4 < foo.pt
66+
```
67+
68+
## AI.MODELRUN - run a model
69+
```sql
2470
AI.MODELRUN model_key INPUTS input_key1 ... OUTPUTS output_key1 ...
2571
```
2672

27-
## AI.SCRIPTSET - Set a script
28-
Stores a TorchScript script provided as text.
29-
```sh
30-
AI.SCRIPTSET script_key device script_text
73+
* model_key - key for the model
74+
* INPUTS input_key1 ... - keys for tensors to use as inputs
75+
* OUTPUTS output_key2 ... - keys for storing output tensors
76+
77+
> The request is queued and evaded asynchronously from a separate thread. The client blocks until the computation finishes.
78+
79+
> If needed, input tensors are copied to the device specified in `AI.MODELSET` before execution.
80+
81+
### Example
82+
83+
```sql
84+
AI.MODELRUN resnet18 INPUTS image12 OUTPUTS label12
85+
```
86+
87+
88+
## AI.SCRIPTSET - set a script
89+
```sql
90+
AI.SCRIPTSET script_key device script_source
91+
```
92+
93+
* script_key - key for storing the script
94+
* device - the device where the script will execute
95+
* script_source - a string containing TorchScript source code
96+
97+
### Example
98+
99+
> Given addtwo.txt as:
100+
101+
```python
102+
def addtwo(a, b):
103+
return a + b
31104
```
32105

33-
## AI.SCRIPTGET - Get a script
34-
```sh
106+
```sql
107+
AI.SCRIPTSET addscript GPU < addtwo.txt
108+
```
109+
110+
## AI.SCRIPTGET - get a script
111+
112+
```sql
35113
AI.SCRIPTGET script_key
36114
```
37115

38-
## AI.SCRIPTRUN - Run a script
39-
```sh
116+
* script_key - key for the script
117+
118+
### Example
119+
120+
```sql
121+
AI.SCRIPTGET addscript
122+
```
123+
124+
125+
## AI.SCRIPTRUN - run a script
126+
127+
```sql
40128
AI.SCRIPTRUN script_key fn_name INPUTS input_key1 ... OUTPUTS output_key1 ...
41129
```
130+
131+
* tensor_key - key for the script
132+
* fn_name - name of the function to execute
133+
* INPUTS input_key1 ... - keys for tensors to use as inputs
134+
* OUTPUTS output_key1 ... - keys for storing output tensors
135+
136+
> If needed, input tensors are copied to the device specified in `AI.SCRIPTSET` before execution.
137+
138+
139+
### Example
140+
141+
```sql
142+
AI.SCRIPTRUN addscript addtwo INPUTS a b OUTPUTS c
143+
```

0 commit comments

Comments
 (0)