-
Notifications
You must be signed in to change notification settings - Fork 106
script execute command #682
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
Changes from 33 commits
f76ef0e
737e005
0310e2b
0f5e542
57816a0
91d2dee
664c637
9145971
62347e1
01420ef
03e9281
a53d6ec
a4ee7a3
ae4b0bd
eb9802c
cf13c59
2e447c7
2dc8f46
22997c9
9fffa16
a802039
9e819a5
85debbb
5545bf0
86bf299
12bcbce
7dcb8bf
bd9911a
c4150d6
742f8fb
fef615c
7399de8
2daf94d
65a083a
2b827f1
a2a93ad
8ac0e71
7143e89
5f5af5d
7b57f13
f7b870e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -514,7 +514,122 @@ OK | |
| The `AI.SCRIPTDEL` is equivalent to the [Redis `DEL` command](https://redis.io/commands/del) and should be used in its stead. This ensures compatibility with all deployment options (i.e., stand-alone vs. cluster, OSS vs. Enterprise). | ||
|
|
||
|
|
||
| ## AI.SCRIPTEXECUTE | ||
|
|
||
| The **`AI.SCRIPTEXECUTE`** command runs a script stored as a key's value on its specified device. It accepts one or more input tensors, int, float or strings and store output tensors. | ||
|
|
||
| The run request is put in a queue and is executed asynchronously by a worker thread. The client that had issued the run request is blocked until the script run is completed. When needed, tensors data is automatically copied to the device prior to execution. | ||
|
|
||
| A `TIMEOUT t` argument can be specified to cause a request to be removed from the queue after it sits there `t` milliseconds, meaning that the client won't be interested in the result being computed after that time (`TIMEDOUT` is returned in that case). | ||
|
|
||
| !!! warning "Intermediate memory overhead" | ||
| The execution of models will generate intermediate tensors that are not allocated by the Redis allocator, but by whatever allocator is used in the TORCH backend (which may act on main memory or GPU memory, depending on the device), thus not being limited by `maxmemory` configuration settings of Redis. | ||
|
|
||
| **Redis API** | ||
|
|
||
| ``` | ||
| AI.SCRIPTRUN <key> <function> | ||
|
||
| KEYS n <key> [keys...] | ||
| INPUTS m <input> [input ...] | ||
| LIST_INPUTS l <input> [input ...] | ||
| OUTPUTS k <output> [output ...] [TIMEOUT t] | ||
| ``` | ||
|
|
||
| _Arguments_ | ||
|
|
||
| * **key**: the script's key name | ||
| * **function**: the name of the function to run | ||
| * **KEYS**: Either a squence of key names that the script will access before, during and after its execution, or a tag which all those keys share. | ||
alonre24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * **INPUTS**: Denotes the beginning of the input parameters list, followed by its length and one or more inputs; The inputs can be tensor key name, `string`, `int` or `float`. The order of the input should be aligned with the order of their respected parameter at the function signature. Note that list inputs are treated in the **LIST_INPUTS** scope. | ||
| * **LIST_INPUTS** Denotes the beginning of a list, followed by its length and one or more inputs; The inputs can be tensor key name, `string`, `int` or `float`. The order of the input should be aligned with the order of their respected parameter at the function signature. Note that if more than one list is provided, their order should be aligned with the order of their respected paramter at the function signature. | ||
|
|
||
| * **OUTPUTS**: denotes the beginning of the output tensors keys' list, followed by its length and one or more key names | ||
| * **TIMEOUT**: the time (in ms) after which the client is unblocked and a `TIMEDOUT` string is returned | ||
|
|
||
| _Return_ | ||
|
|
||
| A simple 'OK' string, a simple `TIMEDOUT` string, or an error. | ||
|
|
||
| **Examples** | ||
|
|
||
| The following is an example of running the previously-created 'myscript' on two input tensors: | ||
|
|
||
| ``` | ||
| redis> AI.TENSORSET mytensor1 FLOAT 1 VALUES 40 | ||
| OK | ||
| redis> AI.TENSORSET mytensor2 FLOAT 1 VALUES 2 | ||
| OK | ||
| redis> AI.SCRIPTEXECUTE myscript addtwo KEYS 3 mytensor1 mytensor2 result INPUTS 2 mytensor1 mytensor2 OUTPUTS 1 result | ||
| OK | ||
| redis> AI.TENSORGET result VALUES | ||
| 1) FLOAT | ||
| 2) 1) (integer) 1 | ||
| 3) 1) "42" | ||
| ``` | ||
|
|
||
| Note: The above command could be executed with a shorter version, given all the keys are tagged with the same tag: | ||
|
|
||
| ``` | ||
| redis> AI.TENSORSET mytensor1{tag} FLOAT 1 VALUES 40 | ||
| OK | ||
| redis> AI.TENSORSET mytensor2{tag} FLOAT 1 VALUES 2 | ||
| OK | ||
| redis> AI.SCRIPTEXECUTE myscript{tag} addtwo KEYS 1 {tag} INPUTS 2 mytensor1{tag} mytensor2{tag} OUTPUTS 1 result{tag} | ||
| OK | ||
| redis> AI.TENSORGET result{tag} VALUES | ||
| 1) FLOAT | ||
| 2) 1) (integer) 1 | ||
| 3) 1) "42" | ||
| ``` | ||
|
|
||
| If 'myscript' supports `List[Tensor]` arguments: | ||
| ```python | ||
| def addn(a, args : List[Tensor]): | ||
| return a + torch.stack(args).sum() | ||
| ``` | ||
|
|
||
| then one can provide an arbitrary number of inputs after the `$` sign: | ||
|
||
|
|
||
| ``` | ||
| redis> AI.TENSORSET mytensor1{tag} FLOAT 1 VALUES 40 | ||
| OK | ||
| redis> AI.TENSORSET mytensor2{tag} FLOAT 1 VALUES 1 | ||
| OK | ||
| redis> AI.TENSORSET mytensor3{tag} FLOAT 1 VALUES 1 | ||
| OK | ||
| redis> AI.SCRIPTRUN myscript{tag} addn keys 1 {tag} INPUTS 1 mytensor1{tag} LIST_INPUTS 2 mytensor2{tag} mytensor3{tag} OUTPUTS 1 result{tag} | ||
|
||
| OK | ||
| redis> AI.TENSORGET result{tag} VALUES | ||
| 1) FLOAT | ||
| 2) 1) (integer) 1 | ||
| 3) 1) "42" | ||
| ``` | ||
|
|
||
| ### Redis Commands support. | ||
| In RedisAI TorchScript now supports simple (non-blocking) Redis commnands via the `redis.execute` API. The following (usless) script gets a key name, an `int` value and sets it in a tensor. Note that the inputs are `str` and `int`. The script sets and gets the value and set it into a tensor. | ||
|
||
|
|
||
| ``` | ||
| def redis_int_to_tensor(redis_value: int): | ||
| return torch.tensor(redis_value) | ||
|
|
||
| def int_set_get(key:str, value:int): | ||
| redis.execute("SET", key, str(value)) | ||
| res = redis.execute("GET", key) | ||
| return redis_string_int_to_tensor(res) | ||
| ``` | ||
| ``` | ||
| redis> AI.SCRIPTEXECUTE redis_scripts{1} int_set_get KEYS 1 {1} INPUTS 2 x{1} 3 OUTPUTS 1 y{1} | ||
| OK | ||
| redis> AI.TENSORGET y{1} VALUES | ||
| 1) (integer) 3 | ||
| ``` | ||
|
|
||
| !!! warning "Intermediate memory overhead" | ||
| The execution of scripts may generate intermediate tensors that are not allocated by the Redis allocator, but by whatever allocator is used in the backends (which may act on main memory or GPU memory, depending on the device), thus not being limited by `maxmemory` configuration settings of Redis. | ||
|
|
||
| ## AI.SCRIPTRUN | ||
| _This command is deprecated and will not be available in future versions. consider using AI.MODELEXECUTE command instead._ | ||
|
|
||
| The **`AI.SCRIPTRUN`** command runs a script stored as a key's value on its specified device. It accepts one or more input tensors and store output tensors. | ||
|
|
||
| The run request is put in a queue and is executed asynchronously by a worker thread. The client that had issued the run request is blocked until the script run is completed. When needed, tensors data is automatically copied to the device prior to execution. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of "it accepts one or more input tensors..." say something like: "it uses one or more Redis keys both as inputs and/or by directly accessing them from within the script itself. Inputs may include tensors, integers, floats or strings, while outputs are tensors to be stored in Redis"
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.