Skip to content

Commit 620a273

Browse files
committed
Merge branch 'master' into Refactor_get_model/script_from_keyspace
2 parents 179076c + 7c82c60 commit 620a273

File tree

16 files changed

+158
-73
lines changed

16 files changed

+158
-73
lines changed

.circleci/config.yml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ commands:
1717
- run:
1818
name: Setup automation
1919
command: |
20-
PIP=1 ./opt/readies/bin/getpy3
20+
./opt/readies/bin/getpy3
2121
./opt/system-setup.py
2222
2323
build-steps:
@@ -125,6 +125,7 @@ jobs:
125125
- run:
126126
name: Submodule checkout
127127
command: git submodule update --init --recursive
128+
- setup-automation
128129
- run:
129130
name: lint
130131
command: |
@@ -201,7 +202,63 @@ jobs:
201202
- run:
202203
name: Test with valgrind
203204
command: |
204-
make -C opt test VALGRIND=1
205+
make -C opt test VALGRIND=1 CLUSTER=0 AOF=0
206+
no_output_timeout: 120m
207+
208+
valgrind-cluster:
209+
docker:
210+
- image: redisfab/rmbuilder:6.0.5-x64-buster
211+
steps:
212+
- checkout
213+
- run:
214+
name: Submodule checkout
215+
command: git submodule update --init --recursive
216+
- restore_cache:
217+
keys:
218+
- build-dependencies-{{ checksum "get_deps.sh" }}
219+
# If no exact match is found will get dependencies from source
220+
- setup-automation
221+
- run:
222+
name: Install dependencies
223+
command: |
224+
./opt/readies/bin/getredis -v 6 --valgrind --force
225+
./get_deps.sh cpu
226+
- run:
227+
name: Build for valgrind with cluster
228+
command: |
229+
make -C opt all VALGRIND=1 SHOW=1
230+
- run:
231+
name: Test with valgrind and cluster
232+
command: |
233+
make -C opt test VALGRIND=1 GEN=0 AOF=0
234+
no_output_timeout: 120m
235+
236+
valgrind-AOF:
237+
docker:
238+
- image: redisfab/rmbuilder:6.0.5-x64-buster
239+
steps:
240+
- checkout
241+
- run:
242+
name: Submodule checkout
243+
command: git submodule update --init --recursive
244+
- restore_cache:
245+
keys:
246+
- build-dependencies-{{ checksum "get_deps.sh" }}
247+
# If no exact match is found will get dependencies from source
248+
- setup-automation
249+
- run:
250+
name: Install dependencies
251+
command: |
252+
./opt/readies/bin/getredis -v 6 --valgrind --force
253+
./get_deps.sh cpu
254+
- run:
255+
name: Build for valgrind with AOF
256+
command: |
257+
make -C opt all VALGRIND=1 SHOW=1
258+
- run:
259+
name: Test with valgrind and AOF
260+
command: |
261+
make -C opt test VALGRIND=1 GEN=0 CLUSTER=0
205262
no_output_timeout: 120m
206263

207264
build-macos:
@@ -385,7 +442,8 @@ workflows:
385442
version: 2
386443
build_and_package:
387444
jobs:
388-
- lint
445+
- lint:
446+
<<: *on-any-branch
389447
- build-debian:
390448
<<: *on-any-branch
391449
<<: *after-linter
@@ -405,7 +463,13 @@ workflows:
405463
<<: *on-any-branch
406464
<<: *after-linter
407465
- valgrind:
408-
<<: *on-master
466+
<<: *on-any-branch
467+
<<: *after-linter
468+
- valgrind-cluster:
469+
<<: *on-integ-branch
470+
<<: *after-linter
471+
- valgrind-AOF:
472+
<<: *on-integ-branch
409473
<<: *after-linter
410474
- build-and-test-gpu:
411475
<<: *on-any-branch

docs/intro.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This introduction is intended to present the core concepts it uses and the funct
88
!!! important "Prerequisites"
99
Before diving into RedisAI please make sure that you are familiar with the basic concepts of machine learning and Redis.
1010

11+
This video will introduce you to RedisAI at a high level. Give it a watch, then keep reading for more details.
12+
13+
<iframe width="560" height="315" src="https://www.youtube.com/embed/gbiqF-eyTW4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
14+
1115
In broad strokes, RedisAI's looks as follows:
1216

1317
```

opt/redis_valgrind.sup

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
obj:*/libtorch.so.*
2727
}
2828

29+
{
30+
ignore_unversioned_libs
31+
Memcheck:Overlap
32+
...
33+
obj:*/libtorch_cpu.so*
34+
}
35+
2936
{
3037
ignore_unversioned_libs
3138
Memcheck:Leak

opt/system-setup.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,28 @@ def __init__(self, nop=False):
1818

1919
def common_first(self):
2020
self.install_downloaders()
21-
self.setup_pip()
22-
self.pip_install("wheel virtualenv")
21+
self.pip_install("wheel")
2322

24-
if self.os == 'linux':
25-
self.install("ca-certificates")
26-
self.install("git unzip wget patchelf")
23+
self.install("git unzip patchelf")
2724
self.install("coreutils") # for realpath
2825

2926
def debian_compat(self):
3027
self.install("gawk")
3128
self.install("build-essential")
3229
self.install("libssl-dev")
33-
self.install("clang-format")
3430
self.install("python3-regex")
3531
self.install("python3-psutil python3-networkx python3-numpy")
36-
if self.arch == 'arm64v8' or self.arch == 'arm32v7':
32+
if self.platform.is_arm():
3733
self.install("python3-dev") # python3-skimage
3834
self.install("libmpich-dev libopenblas-dev") # for libtorch
3935
self.install_git_lfs_on_linux()
4036

4137
def redhat_compat(self):
4238
self.install("redhat-lsb-core")
43-
self.run("%s/readies/bin/enable-utf8" % HERE)
39+
self.run("%s/bin/enable-utf8" % READIES)
4440

45-
self.group_install("'Development Tools'")
4641
self.run("%s/bin/getgcc --modern" % READIES)
47-
self.install("llvm-toolset-7")
42+
# self.install("llvm-toolset-7")
4843

4944
if self.arch == 'x64':
5045
self.install_linux_gnu_tar()
@@ -63,7 +58,6 @@ def redhat_compat(self):
6358
def fedora(self):
6459
self.group_install("'Development Tools'")
6560
self.install("python3 python3-psutil python3-networkx")
66-
self.install("clang")
6761
self.install_git_lfs_on_linux()
6862

6963
def linux_last(self):
@@ -73,18 +67,13 @@ def macos(self):
7367
self.install_gnu_utils()
7468
self.install("git-lfs")
7569
self.install("redis")
76-
self.install("clang-format")
7770

7871
def common_last(self):
72+
self.run("%s/bin/getclang --format" % READIES)
7973
self.run("%s/bin/getcmake" % READIES)
8074

81-
self.run("python3 -m pip uninstall -y ramp-packer RLTest || true")
82-
# redis-py-cluster should be installed from git due to redis-py dependency
83-
self.pip_install("--no-cache-dir git+https://github.com/Grokzen/redis-py-cluster.git@master")
84-
self.pip_install("--no-cache-dir git+https://github.com/RedisLabsModules/RLTest.git@master")
85-
self.pip_install("--no-cache-dir git+https://github.com/RedisLabs/RAMP@master")
75+
self.run("{PYTHON} {READIES}/bin/getrmpytools".format(PYTHON=self.python, READIES=READIES))
8676

87-
self.pip_install("-r %s/readies/paella/requirements.txt" % HERE)
8877
self.pip_install("-r %s/tests/flow/test_requirements.txt" % ROOT)
8978

9079
self.pip_install("awscli")

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ file (GLOB BACKEND_COMMON_SRC
1616
err.c
1717
util/dict.c
1818
tensor.c
19+
util/string_utils.c
1920
serialization/ai_datatypes.c)
2021

2122
ADD_LIBRARY(redisai_obj OBJECT

src/DAG/dag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ static int _StoreTensorInKeySpace(RedisModuleCtx *ctx, RAI_Tensor *tensor,
122122
RedisModule_ReplyWithError(ctx, "ERR could not save tensor");
123123
goto clean_up;
124124
}
125-
if (RedisModule_ModuleTypeSetValue(key, RedisAI_TensorType, RAI_TensorGetShallowCopy(tensor)) !=
126-
REDISMODULE_OK) {
125+
if (RedisModule_ModuleTypeSetValue(key, RedisAI_TensorType, tensor) != REDISMODULE_OK) {
127126
RedisModule_ReplyWithError(ctx, "ERR could not save tensor");
128127
RedisModule_CloseKey(key);
129128
goto clean_up;
@@ -152,6 +151,7 @@ static void _DAG_PersistTensors(RedisModuleCtx *ctx, RedisAI_RunInfo *rinfo) {
152151
persist_entry = AI_dictNext(persist_iter);
153152
continue;
154153
}
154+
tensor = RAI_TensorGetShallowCopy(tensor);
155155
if (_StoreTensorInKeySpace(ctx, tensor, persist_key_name, true) == REDISMODULE_ERR) {
156156
*rinfo->dagError = 1;
157157
RedisModule_Log(ctx, "warning",

src/backends.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int RAI_LoadBackend_TensorFlow(RedisModuleCtx *ctx, const char *path) {
122122
}
123123

124124
backend.model_serialize = (int (*)(RAI_Model *, char **, size_t *, RAI_Error *))(
125-
unsigned long)dlsym(handle, "RAI_ModelSerializeTF");
125+
(unsigned long)dlsym(handle, "RAI_ModelSerializeTF"));
126126
if (backend.model_serialize == NULL) {
127127
dlclose(handle);
128128
RedisModule_Log(ctx, "warning",

src/backends/tensorflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ RAI_Model *RAI_ModelCreateTF(RAI_Backend backend, const char *devicestr, RAI_Mod
247247

248248
for (size_t i = 0; i < ninputs; ++i) {
249249
TF_Operation *oper = TF_GraphOperationByName(model, inputs[i]);
250-
if (oper == NULL) {
250+
if (oper == NULL || strcmp(TF_OperationOpType(oper), "Placeholder") != 0) {
251251
size_t len = strlen(inputs[i]);
252252
char *msg = RedisModule_Calloc(60 + len, sizeof(*msg));
253253
sprintf(msg, "ERR Input node named \"%s\" not found in TF graph.", inputs[i]);

src/libtorch_c/torch_extensions/torch_redis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ torch::IValue redisExecute(std::string fn_name, std::vector<std::string> args )
5656
RedisModuleCallReply *reply = RedisModule_Call(ctx, fn_name.c_str(), "!v", arguments, len);
5757
RedisModule_ThreadSafeContextUnlock(ctx);
5858
torch::IValue value = IValueFromRedisReply(reply);
59-
RedisModule_FreeThreadSafeContext(ctx);
6059
RedisModule_FreeCallReply(reply);
60+
RedisModule_FreeThreadSafeContext(ctx);
6161
for(int i= 0; i < len; i++){
6262
RedisModule_FreeString(NULL, arguments[i]);
6363
}

src/tensor.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "rmutil/alloc.h"
1616
#include "tensor_struct.h"
1717
#include "util/dict.h"
18+
#include "util/string_utils.h"
1819
#include <assert.h>
1920
#include <pthread.h>
2021
#include <stddef.h>
@@ -96,7 +97,8 @@ int Tensor_DataTypeStr(DLDataType dtype, char *dtypestr) {
9697

9798
RAI_Tensor *RAI_TensorCreateWithDLDataType(DLDataType dtype, long long *dims, int ndims,
9899
int tensorAllocMode) {
99-
const size_t dtypeSize = Tensor_DataTypeSize(dtype);
100+
101+
size_t dtypeSize = Tensor_DataTypeSize(dtype);
100102
if (dtypeSize == 0) {
101103
return NULL;
102104
}
@@ -132,11 +134,6 @@ RAI_Tensor *RAI_TensorCreateWithDLDataType(DLDataType dtype, long long *dims, in
132134
break;
133135
}
134136

135-
if (tensorAllocMode != TENSORALLOC_NONE && data == NULL) {
136-
RedisModule_Free(ret);
137-
return NULL;
138-
}
139-
140137
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
141138
.data = data,
142139
.ndim = ndims,
@@ -162,18 +159,14 @@ void RAI_RStringDataTensorDeleter(DLManagedTensor *arg) {
162159
RedisModuleString *rstr = (RedisModuleString *)arg->manager_ctx;
163160
RedisModule_FreeString(NULL, rstr);
164161
}
165-
162+
RedisModule_Free(arg->dl_tensor.data);
166163
RedisModule_Free(arg);
167164
}
168165

169-
RAI_Tensor *RAI_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, long long *dims, int ndims,
170-
RedisModuleString *rstr) {
171-
const size_t dtypeSize = Tensor_DataTypeSize(dtype);
172-
if (dtypeSize == 0) {
173-
return NULL;
174-
}
166+
RAI_Tensor *_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, size_t dtypeSize,
167+
long long *dims, int ndims,
168+
RedisModuleString *rstr, RAI_Error *err) {
175169

176-
RAI_Tensor *ret = RedisModule_Alloc(sizeof(*ret));
177170
int64_t *shape = RedisModule_Alloc(ndims * sizeof(*shape));
178171
int64_t *strides = RedisModule_Alloc(ndims * sizeof(*strides));
179172

@@ -188,9 +181,21 @@ RAI_Tensor *RAI_TensorCreateWithDLDataTypeAndRString(DLDataType dtype, long long
188181
}
189182

190183
DLContext ctx = (DLContext){.device_type = kDLCPU, .device_id = 0};
184+
size_t nbytes = len * dtypeSize;
185+
186+
size_t blob_len;
187+
const char *blob = RedisModule_StringPtrLen(rstr, &blob_len);
188+
if (blob_len != nbytes) {
189+
RedisModule_Free(shape);
190+
RedisModule_Free(strides);
191+
RAI_SetError(err, RAI_ETENSORSET, "ERR data length does not match tensor shape and type");
192+
return NULL;
193+
}
194+
char *data = RedisModule_Alloc(nbytes);
195+
memcpy(data, blob, nbytes);
196+
RAI_HoldString(NULL, rstr);
191197

192-
char *data = (char *)RedisModule_StringPtrLen(rstr, NULL);
193-
198+
RAI_Tensor *ret = RedisModule_Alloc(sizeof(*ret));
194199
ret->tensor = (DLManagedTensor){.dl_tensor = (DLTensor){.ctx = ctx,
195200
.data = data,
196201
.ndim = ndims,
@@ -637,13 +642,16 @@ int RAI_parseTensorSetArgs(RedisModuleString **argv, int argc, RAI_Tensor **t, i
637642
RAI_SetError(error, RAI_ETENSORSET, "wrong number of arguments for 'AI.TENSORSET' command");
638643
return -1;
639644
}
645+
640646
// get the tensor datatype
641647
const char *typestr = RedisModule_StringPtrLen(argv[2], NULL);
642-
size_t datasize = RAI_TensorDataSizeFromString(typestr);
643-
if (!datasize) {
648+
DLDataType datatype = RAI_TensorDataTypeFromString(typestr);
649+
size_t datasize = Tensor_DataTypeSize(datatype);
650+
if (datasize == 0) {
644651
RAI_SetError(error, RAI_ETENSORSET, "ERR invalid data type");
645652
return -1;
646653
}
654+
647655
const char *fmtstr;
648656
int datafmt = TENSOR_NONE;
649657
int tensorAllocMode = TENSORALLOC_CALLOC;
@@ -699,23 +707,17 @@ int RAI_parseTensorSetArgs(RedisModuleString **argv, int argc, RAI_Tensor **t, i
699707
}
700708
}
701709

702-
const long long nbytes = len * datasize;
703-
size_t datalen;
704-
const char *data;
705-
DLDataType datatype = RAI_TensorDataTypeFromString(typestr);
706710
if (datafmt == TENSOR_BLOB) {
707711
RedisModuleString *rstr = argv[argpos];
708-
RedisModule_RetainString(NULL, rstr);
709-
*t = RAI_TensorCreateWithDLDataTypeAndRString(datatype, dims, ndims, rstr);
712+
*t = _TensorCreateWithDLDataTypeAndRString(datatype, datasize, dims, ndims, rstr, error);
710713
} else {
711714
*t = RAI_TensorCreateWithDLDataType(datatype, dims, ndims, tensorAllocMode);
712715
}
713-
714-
if (!t) {
716+
if (!(*t)) {
715717
array_free(dims);
716-
RAI_SetError(error, RAI_ETENSORSET, "ERR could not create tensor");
717718
return -1;
718719
}
720+
719721
long i = 0;
720722
if (datafmt == TENSOR_VALUES) {
721723
for (; (argpos <= argc - 1) && (i < len); argpos++) {

tests/flow/tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ valgrind_config() {
7272

7373
RLTEST_ARGS+="\
7474
--use-valgrind \
75-
--vg-no-fail-on-errors \
7675
--vg-suppressions $VALGRIND_SUPRESSIONS"
7776
}
7877

0 commit comments

Comments
 (0)