Skip to content

Commit d2565ac

Browse files
authored
String tensor support (#832)
* Support string tensor in tensor set * fixed bug in creating scalar tensor (with 0 dims) * fix rdb v4 tests + allow string values not to be null-terminated when using tensor set from values * PR fixes + testing string tensor concatenation and slicing via LLAPI, remove deep copy (not used)
1 parent 53f16b6 commit d2565ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1849
-1511
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ commands:
112112
- save_cache:
113113
paths:
114114
- deps
115-
key: build-dependencies-{{ checksum "get_deps.sh" }}
115+
key: v1-dependencies-{{ checksum "get_deps.sh" }}
116116
- run:
117117
name: Build
118118
command: make -C opt all SHOW=1
@@ -151,7 +151,7 @@ commands:
151151
- checkout-all
152152
- restore_cache:
153153
keys:
154-
- build-dependencies-{{ checksum "get_deps.sh" }}
154+
- v1-dependencies-{{ checksum "get_deps.sh" }}
155155
# If no exact match is found will get dependencies from source
156156
- setup-build-system
157157
- run:
@@ -260,7 +260,7 @@ jobs:
260260
- checkout-all
261261
- restore_cache:
262262
keys:
263-
- build-dependencies-{{ checksum "get_deps.sh" }}
263+
- v1-dependencies-{{ checksum "get_deps.sh" }}
264264
# If no exact match is found will get dependencies from source
265265
- setup-build-system
266266
- run:
@@ -294,7 +294,7 @@ jobs:
294294
- checkout-all
295295
- restore_cache:
296296
keys:
297-
- build-dependencies-{{ checksum "get_deps.sh" }}
297+
- v1-dependencies-{{ checksum "get_deps.sh" }}
298298
# If no exact match is found will get dependencies from source
299299
- setup-build-system
300300
- run:

docs/commands.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ AI.TENSORSET <key> <type>
2727
_Arguments_
2828

2929
* **key**: the tensor's key name
30-
* **type**: the tensor's data type can be one of: `FLOAT`, `DOUBLE`, `INT8`, `INT16`, `INT32`, `INT64`, `UINT8` or `UINT16`
30+
* **type**: the tensor's data type can be one of: `FLOAT`, `DOUBLE`, `INT8`, `INT16`, `INT32`, `INT64`, `UINT8`, `UINT16`, `BOOL` or `STRING`
3131
* **shape**: one or more dimensions, or the number of elements per axis, for the tensor
3232
* **BLOB**: indicates that data is in binary format and is provided via the subsequent `data` argument
3333
* **VALUES**: indicates that data is numeric and is provided by one or more subsequent `val` arguments
@@ -45,6 +45,8 @@ This will set the key 'mytensor' to the 2x2 RedisAI tensor:
4545
```
4646
redis> AI.TENSORSET mytensor FLOAT 2 2 VALUES 1 2 3 4
4747
OK
48+
redis> AI.TENSORSET mytensor STRING 1 2 VALUES first second
49+
OK
4850
```
4951

5052
!!! note "Uninitialized Tensor Values"

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ADD_LIBRARY(redisai_obj OBJECT
3434
execution/command_parser.c
3535
execution/parsing/deprecated.c
3636
execution/parsing/dag_parser.c
37+
execution/parsing/tensor_commands_parsing.c
3738
execution/parsing/model_commands_parser.c
3839
execution/parsing/script_commands_parser.c
3940
execution/parsing/parse_utils.c

src/backends/libtorch_c/torch_c.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void deleter(DLManagedTensor *arg) {
198198
}
199199

200200
DLManagedTensor *toManagedDLPack(const torch::Tensor &src_) {
201-
ATenDLMTensor *atDLMTensor(new ATenDLMTensor);
201+
auto *atDLMTensor(new ATenDLMTensor);
202202
atDLMTensor->handle = src_;
203203
auto &src = atDLMTensor->handle;
204204
atDLMTensor->tensor.manager_ctx = atDLMTensor;
@@ -213,6 +213,7 @@ DLManagedTensor *toManagedDLPack(const torch::Tensor &src_) {
213213
atDLMTensor->tensor.dl_tensor.dtype = getDLDataType(src);
214214
atDLMTensor->tensor.dl_tensor.shape = const_cast<int64_t *>(src.sizes().data());
215215
atDLMTensor->tensor.dl_tensor.strides = const_cast<int64_t *>(src.strides().data());
216+
atDLMTensor->tensor.dl_tensor.elements_length = nullptr;
216217
atDLMTensor->tensor.dl_tensor.byte_offset = 0;
217218
return &(atDLMTensor->tensor);
218219
}

0 commit comments

Comments
 (0)