Skip to content

AI.INFO command #259

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

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 79 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

## AI.CONFIG LOADBACKEND

### AI.CONFIG LOADBACKEND Example

Load a DL/ML backend.

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.
Expand All @@ -16,6 +14,8 @@ AI.CONFIG LOADBACKEND <backend_identifier> <location_of_backend_library>

It is possible to specify backends at the command-line when starting `redis-server`, see example below.

### AI.CONFIG LOADBACKEND Example

> Load the TORCH backend

```sql
Expand Down Expand Up @@ -234,3 +234,80 @@ If needed, input tensors are copied to the device specified in `AI.SCRIPTSET` be
```sql
AI.SCRIPTRUN addscript addtwo INPUTS a b OUTPUTS c
```

## AI.INFO

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

At each `MODELRUN` or `SCRIPTRUN`, RedisAI will collect statistcs specific for each `MODEL` or `SCRIPT`,
specific for the node (hence nodes in a cluster will have to be queried individually for their info).
The following information is collected:

- `KEY`: the key being run
- `TYPE`: either `MODEL` or `SCRIPT`
- `BACKEND`: the type of backend (always `TORCH` for `SCRIPT`)
- `DEVICE`: the device where the run has been executed
- `DURATION`: cumulative duration in microseconds
- `SAMPLES`: cumulative number of samples obtained from the 0-th (batch) dimension (for `MODEL` only)
- `CALLS`: number of calls
- `ERRORS`: number of errors generated after the run has been submitted (i.e. excluding errors generated during parsing of the command)

```sql
AI.INFO <model_or_script_key>
```

Statistcs are accumulated until the same command with an extra `RESETSTAT` argument is called. This resets the statistics relative to the model or script.

```sql
AI.INFO <model_or_script_key> RESETSTAT
```

The command can be called on a key until that key is removed using `MODELDEL` or `SCRIPTDEL`.

### AI.INFO Example

```sql
AI.INFO amodel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lantiga can we include the example output here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


> 1) KEY
> 2) "amodel"
> 3) TYPE
> 4) MODEL
> 5) BACKEND
> 6) TORCH
> 7) DEVICE
> 8) CPU
> 9) DURATION
> 10) (integer) 6511
> 11) SAMPLES
> 12) (integer) 2
> 13) CALLS
> 14) (integer) 1
> 15) ERRORS
> 16) (integer) 0
```

```sql
AI.INFO amodel RESETSTAT

> OK

AI.INFO amodel

> 1) KEY
> 2) "amodel"
> 3) TYPE
> 4) MODEL
> 5) BACKEND
> 6) TORCH
> 7) DEVICE
> 8) CPU
> 9) DURATION
> 10) (integer) 0
> 11) SAMPLES
> 12) (integer) 0
> 13) CALLS
> 14) (integer) 0
> 15) ERRORS
> 16) (integer) 0
```
15 changes: 14 additions & 1 deletion src/backends.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ RedisModuleString* RAI_GetModulePath(RedisModuleCtx *ctx) {
return module_path;
}


RedisModuleString* RAI_GetBackendsPath(RedisModuleCtx *ctx) {
Dl_info info;
RedisModuleString* backends_path = NULL;
Expand All @@ -36,6 +35,20 @@ RedisModuleString* RAI_GetBackendsPath(RedisModuleCtx *ctx) {
return backends_path;
}

const char* RAI_BackendName(int backend) {
switch (backend) {
case RAI_BACKEND_TENSORFLOW:
return "TF";
case RAI_BACKEND_TFLITE:
return "TFLITE";
case RAI_BACKEND_TORCH:
return "TORCH";
case RAI_BACKEND_ONNXRUNTIME:
return "ONNX";
}
return NULL;
}

int RAI_LoadBackend_TensorFlow(RedisModuleCtx *ctx, const char *path) {
if (RAI_backends.tf.model_run != NULL) {
RedisModule_Log(ctx, "warning", "Could not load TF backend: backend already loaded");
Expand Down
4 changes: 3 additions & 1 deletion src/backends.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ char* RAI_BackendsPath;
int RAI_LoadBackend(RedisModuleCtx *ctx, int backend, const char *path);
int RAI_LoadDefaultBackend(RedisModuleCtx *ctx, int backend);

#endif
const char* RAI_BackendName(int backend);

#endif
18 changes: 2 additions & 16 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,11 @@ static void RAI_Model_AofRewrite(RedisModuleIO *aof, RedisModuleString *key, voi
array_append(outputs_, RedisModule_CreateString(ctx, model->outputs[i], strlen(model->outputs[i])));
}

char backend[256] = "";
switch (model->backend) {
case RAI_BACKEND_TENSORFLOW:
strcpy(backend, "TF");
break;
case RAI_BACKEND_TFLITE:
strcpy(backend, "TFLITE");
break;
case RAI_BACKEND_TORCH:
strcpy(backend, "TORCH");
break;
case RAI_BACKEND_ONNXRUNTIME:
strcpy(backend, "ONNX");
break;
}
const char* backendstr = RAI_BackendName(model->backend);

RedisModule_EmitAOF(aof, "AI.MODELSET", "slccvcvb",
key,
backend, model->devicestr,
backendstr, model->devicestr,
"INPUTS", inputs_, model->ninputs,
"OUTPUTS", outputs_, model->noutputs,
buffer, len);
Expand Down
2 changes: 0 additions & 2 deletions src/model_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ typedef struct RAI_Model {
char **outputs;
size_t noutputs;
long long refCount;
long long backend_calls;
long long backend_us;
void* data;
} RAI_Model;

Expand Down
Loading