Skip to content

Improve script API for RedisAI 1.2 #792

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 21 commits into from
Jul 4, 2021
Merged

Conversation

DvirDukhan
Copy link
Collaborator

@DvirDukhan DvirDukhan commented Jun 18, 2021

This PR introduces

  1. AI.SCRIPTSTORE command which will replace AI.SCRIPTSET. In the new command, user will have to specify entry points for the script, all with the signature def entry_point(tensors: List[Tensor], keys: List[Str], args: List[Str]) , so the AI.SCRIPTSTORE command will look like AI.SCRIPTSTORE <key> ENTRY_POINTS <n_ep> <ep_1> ... <ep_n> SOURCE <script>
  2. Modifications to the new AI.SCRIPTEXECUTE command which introduced a new but awkward interface. In the new modification the user will have to specify either INPUTS which are RedisAI tensors (either from keyspace or from DAG execution context), KEYS which are the keys that the function will touch during its execution (by calling redis.Execute command in the function, and ARGS which are strings representing any value the user needs. Those values should be cast later by the user in the script itself.
  • compile script with entry point validation
  • modify AI.SCRIPTSTORE command
  • modify AI.SCRIPTEXECUTE command
  • flow test
  • backward comptablity
  • RDB v3

@DvirDukhan DvirDukhan requested review from alonre24 and lantiga June 21, 2021 21:52
@DvirDukhan DvirDukhan marked this pull request as ready for review June 21, 2021 21:53
@codecov
Copy link

codecov bot commented Jun 21, 2021

Codecov Report

Merging #792 (a3c5ed8) into master (c9f0198) will increase coverage by 0.02%.
The diff coverage is 80.70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #792      +/-   ##
==========================================
+ Coverage   79.92%   79.95%   +0.02%     
==========================================
  Files          52       53       +1     
  Lines        7767     8035     +268     
==========================================
+ Hits         6208     6424     +216     
- Misses       1559     1611      +52     
Impacted Files Coverage Δ
src/redisai.h 96.34% <ø> (-0.33%) ⬇️
src/serialization/AOF/rai_aof_rewrite.c 0.00% <0.00%> (ø)
.../serialization/RDB/decoder/previous/v2/decode_v2.c 36.74% <0.00%> (ø)
src/serialization/RDB/decoder/decode_previous.c 66.66% <33.33%> (-8.34%) ⬇️
src/backends/libtflite_c/tflite_c.cpp 58.16% <50.00%> (+0.56%) ⬆️
...c/serialization/RDB/decoder/current/v3/decode_v3.c 68.13% <68.13%> (ø)
src/execution/parsing/script_commands_parser.c 77.12% <77.87%> (+1.67%) ⬆️
src/execution/parsing/deprecated.c 81.38% <78.84%> (-0.49%) ⬇️
src/execution/parsing/dag_parser.c 96.00% <81.81%> (-0.45%) ⬇️
...ckends/libtorch_c/torch_extensions/torch_redis.cpp 94.73% <96.87%> (+10.29%) ⬆️
... and 28 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 a472c90...a3c5ed8. Read the comment docs.

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, much cleaner logic for executing scripts! I added many comments about missing tests (sorry...), and I saw that many tests were disabled (most of them in tests_deprecated_commands.py), for a reason that I couldn't understand...

if not TEST_PT:
env.debugPrint("skipping {} since TEST_PT=0".format(sys._getframe().f_code.co_name), force=True)
return

con = env.getConnection()

check_error(env, con, 'AI.SCRIPTSET', 'ket{1}', DEVICE, 'SOURCE', 'return 1')
check_error(env, con, 'AI.SCRIPTSTORE', 'ket{1}', DEVICE, 'SOURCE', 'return 1')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we check for the error message in these 4 tests?

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.

Added few more comments. Also, there are still some parsing errors in script execute that are not tested. I'm suppose to talk with Meir on Sunday about making the KEYS not mandatory, then we could close this PR...
One last thing - the aof issue. I see that we are still not covering aof rewrite which is very strange. I will take a look and fix it a new PR

docs/commands.md Outdated
## AI.SCRIPTSET
_This command is deprecated and will not be available in future versions. consider using AI.MODELSTORE command instead._
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider using AI.SCRIPTSTORE command instead._

return function->getSchema().arguments().size();
}

extern "C" TorchScriptFunctionArgumentType torchScript_FunctionArgumentType(void* scriptCtx, size_t fn_index, size_t arg_index) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this function still needed now that we have torchScript_FunctionArgumentTypeByFunctionName?

@@ -687,8 +593,27 @@ extern "C" size_t torchScript_FunctionArgumentCount(void* scriptCtx, size_t fn_i
return functions[fn_index]->getSchema().arguments().size();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

DO we still need torchScript_FunctionArgumentCount now that we have torchScript_FunctionArgumentCountByFunctionName?

for (size_t i = 0; i < nEntryPoints; i++) {
const char *entryPoint;
if (AC_GetString(&ac, &entryPoint, NULL, 0) != AC_OK) {
return RedisModule_ReplyWithError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

test?

check_error_message(env, con, "Already encountered KEYS scope in current command",
"AI.DAGEXECUTE KEYS 1 a{1} |> AI.SCRIPTEXECUTE script{1} bar KEYS 1 a{1}")
# # ERR KEYS section in an inner AI.SCRIPTEXEUTE command within a DAG is not allowed.
# check_error_message(env, con, "Already encountered KEYS scope in current command",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right... ok let's leave it open, I'll discuss it with Meir on Sunday

"AI.DAGEXECUTE KEYS 1 a{1} |> AI.SCRIPTEXECUTE script{1} bar KEYS 1 a{1}")
# # ERR KEYS section in an inner AI.SCRIPTEXEUTE command within a DAG is not allowed.
# check_error_message(env, con, "Already encountered KEYS scope in current command",
# "AI.DAGEXECUTE KEYS 1 a{1} |> AI.SCRIPTEXECUTE script{1} bar KEYS 1 a{1}")


# Todo: this test should change once the script store command is implemented.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant that the #todo comment is no longer needed since script store is now implemented. Also, I think that the tests for AI.SCRIPTSTORE syntax (i.e., tests that catches errors in the RedisAI parsing phase, before we call torch.CompileScript) should be in this file, as we did for similar tests of the AI.MODELSTORE command.

if (localArgpos >= argc) {
RAI_SetError(error, RAI_ESCRIPTRUN, "ERR Invalid arguments provided to AI.SCRIPTEXECUTE");
return REDISMODULE_ERR;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

And if there is any difference, these errors are not tested....

@DvirDukhan DvirDukhan force-pushed the fix_script_api_for_1.2 branch from 4e67931 to 6de3a1c Compare July 4, 2021 11:53
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! final 3 comments... and lets merge it!

@DvirDukhan DvirDukhan merged commit e954d21 into master Jul 4, 2021
@DvirDukhan DvirDukhan deleted the fix_script_api_for_1.2 branch July 4, 2021 21:34
# 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