Skip to content

script execute command #682

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 41 commits into from
May 5, 2021
Merged

script execute command #682

merged 41 commits into from
May 5, 2021

Conversation

DvirDukhan
Copy link
Collaborator

@DvirDukhan DvirDukhan commented Apr 13, 2021

This PR implements the new command:

AI.SCRIPTEXECUTE <key> <function>
[KEYS <keys_count> <key> [key ...]]
[[INPUTS <input_count> <input> [input ...]]? 
[LIST_INPUTS <size> <input> [input...]]* 
[OUTPUTS <output_count> <output> [output ...]]?
[TIMEOUT <time>]?

The new command infers the types of its inputs from the function signature and allows support for the following types:

  1. torch::Tensor
  2. torch::string
  3. int
  4. float
  5. List[T] where T is one of the above.

This support allows better flexibility and expressiveness on the torch-redis commands extension in RedisAI.

The new command structure scopes:

  1. KEYS - mandatory scope - this scope was added in order to infer the execution shard according to a given hash slot tag, or a list of keys that the script execution is going to access, either is inputs, outputs, or during the script run itself via the torch-redis extension.
    For example, for a script key s{1}. if the inputs are a{1}, b{1} and the output is c{1} than the user just needs to provide KEYS 1 {1}. if the inputs are a, b, and the output is c, and the user is not sure about the hash slot, the user need to provide KEYS 3 a b c.
  2. INPUTS - In this new command, an input is a union of torch::Tensor | torch::string | int | float, meaning that inputs now may not be tensors in the keyspace. If there are keyspace tensors in the inputs they either should be mentioned on the KEYS scope or have the KEYS scope aware of their hash slot tagging. The inputs should be provided in the order they are appearing in the function signature (without lists). Inputs number must be provided.
  3. LIST_INPUTS - a list of inputs. Multiple lists can be provided and they should be provided in the order they are appearing in the function signature. list size must be provided
  4. OUTPUTS - key names to store output tensors in the keyspace. Outputs number must be provided.
  5. TIMEOUT - same as before

@DvirDukhan DvirDukhan changed the title added function dictionary script execute command Apr 17, 2021
@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #682 (f7b870e) into master (9d8faa8) will increase coverage by 0.06%.
The diff coverage is 78.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #682      +/-   ##
==========================================
+ Coverage   78.86%   78.93%   +0.06%     
==========================================
  Files          43       48       +5     
  Lines        6865     7343     +478     
==========================================
+ Hits         5414     5796     +382     
- Misses       1451     1547      +96     
Impacted Files Coverage Δ
src/execution/run_info.c 93.54% <ø> (+20.97%) ⬆️
src/execution/utils.c 67.85% <ø> (-1.11%) ⬇️
src/execution/execution_contexts/scriptRun_ctx.c 70.22% <70.22%> (ø)
src/backends/libtorch_c/torch_c.cpp 63.44% <71.09%> (+5.55%) ⬆️
src/execution/parsing/script_commands_parser.c 71.73% <71.73%> (ø)
src/execution/parsing/deprecated.c 77.93% <77.55%> (ø)
src/execution/execution_contexts/modelRun_ctx.c 78.70% <78.70%> (ø)
src/redis_ai_objects/script.c 87.20% <82.35%> (+4.70%) ⬆️
src/execution/parsing/model_commands_parser.c 93.40% <93.40%> (ø)
src/redisai.c 85.82% <95.23%> (+0.16%) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a60ff12...f7b870e. Read the comment docs.

@DvirDukhan DvirDukhan marked this pull request as ready for review April 28, 2021 21:24
@DvirDukhan DvirDukhan requested review from alonre24 and lantiga April 28, 2021 21:24
Copy link
Collaborator

@alonre24 alonre24 left a comment

Choose a reason for hiding this comment

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

Nice work!!! liked the new files structure and organization. I left some comments and suggestions, we can discuss it also tomorrow. Besides that, looks like there are quite a few cases of parsing errors that are not tested, consider adding some tests to increase coverage (depends on how thorough we want to be...)

Copy link
Collaborator

@alonre24 alonre24 left a comment

Choose a reason for hiding this comment

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

Looks good, added another few comments and suggestions.

docs/commands.md Outdated
@@ -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.
Copy link
Collaborator

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"

Copy link
Collaborator Author

@DvirDukhan DvirDukhan May 4, 2021

Choose a reason for hiding this comment

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

It accepts one or more inputs, where the inputs could be tensors stored in RedisAI, int, float, or strings and stores the script outputs as RedisAI tensors if required.

docs/commands.md Outdated
**Redis API**

```
AI.SCRIPTRUN <key> <function>
Copy link
Collaborator

Choose a reason for hiding this comment

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

AI.SCRIPTEXECUTE
KEYS n <key> [keys...]
[INPUTS m <input> [input ...]
| LIST_INPUTS l <input> [input ...]]*
[OUTPUTS k <output> [output ...]] [TIMEOUT t]

Copy link
Collaborator Author

@DvirDukhan DvirDukhan May 4, 2021

Choose a reason for hiding this comment

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

AI.SCRIPTEXECUTE <key> <function> 
KEYS n <key> [keys...] 
[INPUTS m <input> [input ...] | [LIST_INPUTS l <input> [input ...]]*]+
[OUTPUTS k <output> [output ...] [TIMEOUT t]]+

docs/commands.md Outdated
return a + torch.stack(args).sum()
```

then one can provide an arbitrary number of inputs after the `$` sign:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a leftover... should be replaced with "LIST_INPUTS"

docs/commands.md Outdated
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}
Copy link
Collaborator

Choose a reason for hiding this comment

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

ai.scriptexecute

docs/commands.md Outdated
```

### 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rephrase the last sentence: "here, the script sets an integer value (3) under the key 'x{1}' and then gets this value and set it into a tensor which is eventually stored under the key 'y{1}'."

alonre24
alonre24 previously approved these changes May 4, 2021
@DvirDukhan DvirDukhan merged commit 8a3461f into master May 5, 2021
@DvirDukhan DvirDukhan deleted the script_execute branch May 5, 2021 06:14
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants