Skip to content

Commit 14e82db

Browse files
author
DvirDukhan
authored
Merge pull request #580 from RedisAI/backend_version
Backend version
2 parents a4173a1 + 5bceebc commit 14e82db

File tree

18 files changed

+230
-14
lines changed

18 files changed

+230
-14
lines changed

docs/commands.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,14 @@ Because `AI.DAGRUN` provides the `PERSIST` option it is flagged as a 'write' com
660660
Refer to the Redis [`READONLY` command](https://redis.io/commands/readonly) for further information about read-only cluster replicas.
661661

662662
## AI.INFO
663-
The **`AI.INFO`** command returns information about the execution a model or a script.
663+
The **`AI.INFO`** command returns general module information or information about the execution a model or a script.
664664

665665
Runtime information is collected each time that [`AI.MODELRUN`](#aimodelrun) or [`AI.SCRIPTRUN`](#aiscriptrun) is called. The information is stored locally by the executing RedisAI engine, so when deployed in a cluster each shard stores its own runtime information.
666666

667667
**Redis API**
668668

669669
```
670-
AI.INFO <key> [RESETSTAT]
670+
AI.INFO [<key>] [RESETSTAT]
671671
```
672672

673673
_Arguments_
@@ -677,7 +677,15 @@ _Arguments_
677677

678678
_Return_
679679

680-
An array with alternating entries that represent the following key-value pairs:
680+
For a module genernal information: An array with alternating entries that represent the following key-value pairs:
681+
682+
* **Version**: a string showing the current module version.
683+
* **Low level API Version**: a string showing the current module's low level api version.
684+
* **RDB Encoding version**: a string showing the current module's RDB encoding version.
685+
* **TensorFlow version**: a string showing the current loaded TesnorFlow backend version.
686+
* **ONNX version**: a string showing the current loaded ONNX Runtime backend version.
687+
688+
For model or script runtime information: An array with alternating entries that represent the following key-value pairs:
681689

682690
* **KEY**: a String of the name of the key storing the model or script value
683691
* **TYPE**: a String of the type of value (i.e. 'MODEL' or 'SCRIPT')

src/backends.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ int RAI_LoadBackend_TensorFlow(RedisModuleCtx *ctx, const char *path) {
132132
return REDISMODULE_ERR;
133133
}
134134

135+
backend.get_version =
136+
(const char *(*)(void))(unsigned long)dlsym(handle, "RAI_GetBackendVersionTF");
137+
if (backend.get_version == NULL) {
138+
dlclose(handle);
139+
RedisModule_Log(ctx, "warning",
140+
"Backend does not export RAI_GetBackendVersionTF. TF backend "
141+
"not loaded from %s",
142+
path);
143+
return REDISMODULE_ERR;
144+
}
145+
135146
RAI_backends.tf = backend;
136147

137148
RedisModule_Log(ctx, "notice", "TF backend loaded from %s", path);
@@ -213,6 +224,17 @@ int RAI_LoadBackend_TFLite(RedisModuleCtx *ctx, const char *path) {
213224
return REDISMODULE_ERR;
214225
}
215226

227+
backend.get_version =
228+
(const char *(*)(void))(unsigned long)dlsym(handle, "RAI_GetBackendVersionTFLite");
229+
if (backend.get_version == NULL) {
230+
dlclose(handle);
231+
RedisModule_Log(ctx, "warning",
232+
"Backend does not export RAI_GetBackendVersionTFLite. TFLite backend "
233+
"not loaded from %s",
234+
path);
235+
return REDISMODULE_ERR;
236+
}
237+
216238
RAI_backends.tflite = backend;
217239

218240
RedisModule_Log(ctx, "notice", "TFLITE backend loaded from %s", path);
@@ -327,6 +349,17 @@ int RAI_LoadBackend_Torch(RedisModuleCtx *ctx, const char *path) {
327349
return REDISMODULE_ERR;
328350
}
329351

352+
backend.get_version =
353+
(const char *(*)(void))(unsigned long)dlsym(handle, "RAI_GetBackendVersionTorch");
354+
if (backend.get_version == NULL) {
355+
dlclose(handle);
356+
RedisModule_Log(ctx, "warning",
357+
"Backend does not export RAI_GetBackendVersionTorch. TORCH backend "
358+
"not loaded from %s",
359+
path);
360+
return REDISMODULE_ERR;
361+
}
362+
330363
RAI_backends.torch = backend;
331364

332365
RedisModule_Log(ctx, "notice", "TORCH backend loaded from %s", path);
@@ -407,6 +440,17 @@ int RAI_LoadBackend_ONNXRuntime(RedisModuleCtx *ctx, const char *path) {
407440
return REDISMODULE_ERR;
408441
}
409442

443+
backend.get_version =
444+
(const char *(*)(void))(unsigned long)dlsym(handle, "RAI_GetBackendVersionORT");
445+
if (backend.get_version == NULL) {
446+
dlclose(handle);
447+
RedisModule_Log(ctx, "warning",
448+
"Backend does not export RAI_GetBackendVersionORT. ONNX backend "
449+
"not loaded from %s",
450+
path);
451+
return REDISMODULE_ERR;
452+
}
453+
410454
RAI_backends.onnx = backend;
411455

412456
RedisModule_Log(ctx, "notice", "ONNX backend loaded from %s", path);

src/backends.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ typedef struct RAI_LoadedBackend {
7474
// RAI_ScriptRunCtx pointer
7575
int (*script_run)(RAI_ScriptRunCtx *, RAI_Error *);
7676

77+
// Returns the backend version.
78+
const char *(*get_version)(void);
79+
7780
} RAI_LoadedBackend;
7881

7982
typedef struct RAI_LoadedBackends {

src/backends/onnxruntime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,5 @@ int RAI_ModelSerializeORT(RAI_Model *model, char **buffer, size_t *len, RAI_Erro
670670

671671
return 0;
672672
}
673+
674+
const char *RAI_GetBackendVersionORT(void) { return OrtGetApiBase()->GetVersionString(); }

src/backends/onnxruntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ int RAI_ModelRunORT(RAI_ModelRunCtx **mctxs, RAI_Error *error);
1717

1818
int RAI_ModelSerializeORT(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
1919

20+
const char *RAI_GetBackendVersionORT(void);
21+
2022
#endif /* SRC_BACKENDS_ONNXRUNTIME_H_ */

src/backends/tensorflow.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,5 @@ int RAI_ModelSerializeTF(RAI_Model *model, char **buffer, size_t *len, RAI_Error
591591

592592
return 0;
593593
}
594+
595+
const char *RAI_GetBackendVersionTF(void) { return TF_Version(); }

src/backends/tensorflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ int RAI_ModelRunTF(RAI_ModelRunCtx **mctxs, RAI_Error *error);
1919

2020
int RAI_ModelSerializeTF(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
2121

22+
const char *RAI_GetBackendVersionTF(void);
23+
2224
#endif /* SRC_BACKENDS_TENSORFLOW_H_ */

src/backends/tflite.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,5 @@ int RAI_ModelSerializeTFLite(RAI_Model *model, char **buffer, size_t *len, RAI_E
237237

238238
return 0;
239239
}
240+
241+
const char *RAI_GetBackendVersionTFLite(void) { return "NA"; }

src/backends/tflite.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef SRC_BACKENDS_TFLITE_H_
2-
#define SRC_BACKENDS_TFLITE_H_
1+
#pragma once
32

43
#include "config.h"
54
#include "tensor_struct.h"
@@ -17,4 +16,4 @@ int RAI_ModelRunTFLite(RAI_ModelRunCtx **mctxs, RAI_Error *error);
1716

1817
int RAI_ModelSerializeTFLite(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
1918

20-
#endif /* SRC_BACKENDS_TFLITE_H_ */
19+
const char *RAI_GetBackendVersionTFLite(void);

src/backends/torch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,5 @@ int RAI_ScriptRunTorch(RAI_ScriptRunCtx *sctx, RAI_Error *error) {
367367

368368
return 0;
369369
}
370+
371+
const char *RAI_GetBackendVersionTorch(void) { return "NA"; }

0 commit comments

Comments
 (0)