Skip to content
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

Execute Redis commands in Torch Script #489

Merged
merged 27 commits into from
Jan 13, 2021
Merged

Conversation

DvirDukhan
Copy link
Collaborator

@DvirDukhan DvirDukhan commented Nov 3, 2020

This PR scope:

  • Add redis namespace resolver to torch
  • Add redis.execute custom operator to execute RedisModule_Call within the operator scope or from auxiliary function.
  • Transform RedisModuleCallReply to a torch representation - using torch::IValue
  • Handle redis exceptions
  • Memory management
  • Tests

@DvirDukhan DvirDukhan self-assigned this Nov 3, 2020
@DvirDukhan DvirDukhan added this to In progress in RedisAI 1.2 via automation Nov 3, 2020
@codecov
Copy link

codecov bot commented Nov 19, 2020

Codecov Report

Merging #489 (e50e5cf) into master (2fc1827) will increase coverage by 1.89%.
The diff coverage is 82.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #489      +/-   ##
==========================================
+ Coverage   72.14%   74.04%   +1.89%     
==========================================
  Files          35       37       +2     
  Lines        5824     5915      +91     
==========================================
+ Hits         4202     4380     +178     
+ Misses       1622     1535      -87     
Impacted Files Coverage Δ
src/redisai.c 83.28% <ø> (-0.06%) ⬇️
src/command_parser.c 83.94% <66.66%> (-2.73%) ⬇️
src/libtorch_c/torch_extensions/torch_redis.cpp 84.44% <84.44%> (ø)
src/libtorch_c/torch_extensions/torch_redis.h 88.88% <88.88%> (ø)
src/libtorch_c/torch_c.cpp 57.89% <95.23%> (+0.37%) ⬆️
src/backends/torch.c 80.17% <100.00%> (+10.30%) ⬆️
src/script.c 64.05% <0.00%> (+0.65%) ⬆️
src/DAG/dag.c 83.94% <0.00%> (+1.73%) ⬆️
... and 4 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 2fc1827...e50e5cf. Read the comment docs.

@DvirDukhan DvirDukhan moved this from In progress to To do in RedisAI 1.2 Dec 2, 2020
@DvirDukhan DvirDukhan moved this from To do to In progress in RedisAI 1.2 Dec 9, 2020
@DvirDukhan DvirDukhan marked this pull request as ready for review December 30, 2020 12:41
@DvirDukhan DvirDukhan moved this from In progress to Review in progress in RedisAI 1.2 Dec 30, 2020
Copy link
Contributor

@lantiga lantiga 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, we need to add a test in which we run SCRIPT on the GPU and the tensor built from a Redis value gets moved to the GPU.

src/redisai.c Show resolved Hide resolved
@@ -0,0 +1,66 @@

def redis_string_int_to_tensor(redis_value: Any):
return torch.tensor(int(str(redis_value)))
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing we need to make sure is that we move the tensor to the right device. We can ask the user to do so, but it needs to be done otherwise a script running on GPU will find itself with an input on CPU and will fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just add a note here (and maybe in the docs) mentioning the device placement.
The ideal solution here would be to have a SCRIPT_DEVICE global to allow a user to do

a_tensor = torch.tensor(int(str(redis_value))).to(device=SCRIPT_DEVICE)

and have tensors created within the script be located on the same device as the eventual script inputs.

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, few comments on SCRIPTRUN command parsing

continue;
}
// Parse argument name
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this in a block?
And also, I think that the modified parsing logic allows to avoid INPUTS/OUTPUTS all together. For example, the following command would not raise an error (and will refer all the keys as inputs):
AI.SCRIPTRUN script_key func_name key1 key2 ...

} else if (!strcasecmp(arg_string, "$")) {
continue;
}
if (!strcasecmp(arg_string, "$")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (!strcasecmp(arg_string, "$") && is_input)
otherwise, varidic can inputs can come in the middle of OUTPUTS.

}

if (!strcasecmp(arg_string, "INPUTS") && !is_input) {
is_input = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that this way, INPUTS can appear after OUTPUTS (even more than once...)
Consider add another flag like "input_done"?

RedisAI 1.2 automation moved this from Review in progress to Reviewer approved Jan 13, 2021
Copy link
Contributor

@lantiga lantiga left a comment

Choose a reason for hiding this comment

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

LGTM

@DvirDukhan DvirDukhan merged commit 7947e6e into master Jan 13, 2021
RedisAI 1.2 automation moved this from Reviewer approved to Done Jan 13, 2021
@DvirDukhan DvirDukhan deleted the torchscript_extensions branch January 13, 2021 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
RedisAI 1.2
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants