Serialization - refactor and handle short reads#488
Conversation
7f7e517 to
aa2c3c7
Compare
Codecov Report
@@ Coverage Diff @@
## master #488 +/- ##
==========================================
- Coverage 76.16% 75.74% -0.43%
==========================================
Files 25 35 +10
Lines 5433 5701 +268
==========================================
+ Hits 4138 4318 +180
- Misses 1295 1383 +88
Continue to review full report at Codecov.
|
eda88f9 to
b4c3d33
Compare
|
Hi @DvirDukhan can you do a format pass of the code? |
alonre24
left a comment
There was a problem hiding this comment.
I added few minor comments and a few questions
| .dtype = dtype, | ||
| .shape = shape, | ||
| .strides = strides, | ||
| .byte_offset = 0}, |
There was a problem hiding this comment.
Why the byte_offset field is initialized to 0 and not to the loaded byte_offset?
There was a problem hiding this comment.
from docs:
/*! \brief The offset in bytes to the beginning pointer to data */
uint64_t byte_offset;
There was a problem hiding this comment.
We could do this indeed. Right now every tensor that has been set from the client will have byte offset of 0, but let's load it from the serialization, it's a good idea.
|
|
||
| void *RAI_RDBLoadModel(RedisModuleIO *io); | ||
|
|
||
| void *RAI_RDBLoadScript(RedisModuleIO *io); No newline at end of file |
|
|
||
| #include "../serialization_include.h" | ||
|
|
||
| int ModelType_Register(RedisModuleCtx *ctx); No newline at end of file |
| RAI_TensorDim(tensor, i)); | ||
| } | ||
|
|
||
| RedisModule_EmitAOF(aof, "AI.TENSORSET", "scvcb", key, dtypestr, dims, ndims, "BLOB", data, |
There was a problem hiding this comment.
What does the "scvcb" stands for?
There was a problem hiding this comment.
see robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap) in Redis repo
One input of the function RedisModule_EmitAOF is fmt which is the string scvcb, after this input you have var args input, and the RedisModule_EmitAOF function calls moduleCreateArgvFromUserFormatto know how to handle the inputs, according to the chars infmt`
|
|
||
| const char *backendstr = RAI_BackendName(model->backend); | ||
|
|
||
| RedisModule_EmitAOF(aof, "AI.MODELSET", "slccclclcvcvcv", key, backendstr, model->devicestr, |
There was a problem hiding this comment.
Here also, I couldn't understand what is "slccclclcvcvcv" (looks very random...)
|
|
||
| void RAI_AOFRewriteScript(RedisModuleIO *aof, RedisModuleString *key, void *value) { | ||
| RAI_Script *script = (RAI_Script *)value; | ||
| RedisModule_EmitAOF(aof, "AI.SCRIPTSET", "scccc", key, script->devicestr, script->tag, "SOURCE", |
There was a problem hiding this comment.
Same here, not clear what is "scccc"
| RAI_Script *script = (RAI_Script *)value; | ||
| RedisModule_EmitAOF(aof, "AI.SCRIPTSET", "scccc", key, script->devicestr, script->tag, "SOURCE", | ||
| script->scriptdef); | ||
| } No newline at end of file |
lantiga
left a comment
There was a problem hiding this comment.
I agree on reading / writing the byte_offset.
One note: I'm not sure the definition of the data types should be under the serialization directory. Let's take the data type out of that and into a dedicated directory.
Also, coverage is giving several warnings, we should make sure we are testing those functions for the most part.
| .dtype = dtype, | ||
| .shape = shape, | ||
| .strides = strides, | ||
| .byte_offset = 0}, |
There was a problem hiding this comment.
We could do this indeed. Right now every tensor that has been set from the client will have byte offset of 0, but let's load it from the serialization, it's a good idea.
lantiga
left a comment
There was a problem hiding this comment.
LGTM. Just as a heads up (I'm sure you are aware of this), with the binary strings PR we have changed tag to be a binary string, so older RDB's won't load.
lantiga
left a comment
There was a problem hiding this comment.
LGTM. How do we test encode/decode from previous versions in CI?
|
@lantiga You are right |
| dtype.lanes = RedisModule_LoadUnsigned(io); | ||
|
|
||
| size_t ndims = RedisModule_LoadUnsigned(io); | ||
| if (RedisModule_IsIOError(io)) |
There was a problem hiding this comment.
Why do you decide to check for IOError specifically in lines 24 and 41?
| .backends_inter_op_parallelism = getBackendsInterOpParallelism(), | ||
| }; | ||
|
|
||
| len; |
There was a problem hiding this comment.
What is the meaning of this declaration (line 112)?
| RedisModule_FreeString(NULL, tag); | ||
|
|
||
| return NULL; | ||
| } No newline at end of file |
| def test_v0_torch_model(self): | ||
| key_name = "pt_minimal{1}" | ||
| con = self.env.getConnection() | ||
| model_rdb = b'\x07\x81\x00\x8f\xff0\xe0\xc4,\x00\x02\x02\x05\x04CPU\x00\x05\x0ePT_MINIMAL_V0\x00\x02\x00\x02\x00\x02\x00\x02\x00\x05\xc3C\x0eEH\x0ePK\x03\x04\x00\x00\x08\x08\x00\x00\x86\xb0zO\x00\xe0\x02\x00\x1a\x12\x00\x10\x00pt-minimal/versionFB\x0c\x00Z\xe0\x02\x00\n1\nPK\x07\x08S\xfcQg\x02 ;@\x03\x00P Q\x00\x14 Q\x00\x08\xe0\x08Q\x02\x1c\x004\xe0\x03Q\x13code/__torch__.pyFB0\xe0\x04[\xe0\x1b\x00\x1f5LK\n\x830\x10\xdd{\x8a\xb7T\xb0\x82\xdb\x80\xbd\x81\xbb\xeeJ\t\xa3\x19\xab\x90fd\x12[z\xfb\x1f\x06\xad\xab\xf7\x7f\xb2\xda7k\\$\xd8\xc8\t\x1d\xdab\xf4\x14#\xfao/n\xf3\\\x1eP\x99\x02\xb0v\x1f%\xa5\x17\xa7\xbc\xb06\x97\xef\x8f\xec&\xa5%,\xe1\t\x83A\xc4g\xc7\xf1\x84I\xf4C\xea\xca\xc8~2\x1fy\x99D\xc7\xd9\xda\xe6\xfc\xads\x0f \x83\x1b\x87(z\xc8\xe1\x94\x15.\xd7?5{\xa2\x9c6\r\xd8_\r\x1ar\xae\xa4\x1aC\r\xf2\xebL][\x15?A\x0b\x04a\xc1#I\x8e!\x0b\x00\xc8 \x03\xe1\x11\x0b\x02&\x00\x1e\xe1\x14\x0b\x0c.debug_pklFB\x1a\xe1\x12\x15\x1f5\x8eA\n\xc20\x10EcU\x90\x82+/0\xcb\x8a%\x07p\xe5V\x06t\xdb\x9d\xa4mB"m\xd3\x1f\xa4\x11q\xe7\xca\x1e\xc7S\xa8\xd72)\xe4m\x06\xde\x87?\xff\x99d\xb8)\x88\xc7\x10I\x90\x8cf\x86\xe1\x1f\xbc\xf0]\x9c\xbd\x05\xcf\xc1i[IzU\x8e\x0e\x95U\xbd\xbb\xb4\xdcI]\xa7!\xac\xb9\x00\xa1\xed\x9d\xd9\x1f:\x1bx#r`9\x94\xdb\xfd\x14\x06,w7\xdb\x01\x83\x1d\x94\xa9I\x8a\xb5o\r\x15\xaaS-kh\x15\xff0s\\\x8df\x81G<\xf9\xb7\x1f\x19\x07|et\xbf\xe8\x9cY\xd2a\x08\x04\xa7\x94\x1a\x02\x97!\x04\x00\xb2 \x03A\x08\xe2\rf\x02\x18\x00#\xe1\x05\x08\x07nstants.`\xfa\x00\x1f\xe0\x12\xfa`\x00\x03\x80\x02).Au\x03m/\tW a\x00\x00@\x03\xe0\x11l\x02\x13\x00;\xe0\x03l\x03data\x80g\x007\xe0\x17g\xe0\x0f\x00\x02\x80\x02c\xe2\x00\xc2\x10\nMyModule\nq\x00)\x81}(X#U\x0f\x00trainingq\x01\x88ubq\x02`\xac\x04z\xb8\x18\x811 \x1b@\x03\x02PK\x01C5#0\x83\x82\xe3\x03J\x00\x12 \x17\xe0\x05\x00\xe3\t\x90\x80?\xe3\x01p\xe2\x03~\x00\x1c\xe0\x04<\x00R \r\xe0\x02?\xe3\x08~\xe0\x07I\xe1\x03\xbf\x00& ;\xe0\x01\x00\x01^\x01\xe0\x15I\xe2\x01\xbc\x80S\xe0\x01\xdd\xe1\x03\xa6\x00\x18 \x17\xe0\x01\x00D?\xe0\x04\x9d\xe2\x02\x07\xe0\x07E\xe1\x03?\x00\x13\xe0\x01B \x00\x00\xd4!K\xe0\x02E\xc1\xe0\x04PK\x06\x06, \x1e@\x00\x02\x1e\x03-@\x06`\x00\x00\x05`\x05\xe0\x01\x07\x00e \xd8@\x00\x01\x81\x03@\x05A\x9c\x01\x06\x07 \x06\x01\x00\xe6BV \x00@\x1e\x03PK\x05\x06 \n ;\x00\x05`/@+\x01\x00\x00\x00\t\x00MQ\xab\x8e\xfdc\x97>' |
There was a problem hiding this comment.
Are you sure that you want the model_rdb to be hard coded instead of reading it from a file?
!!! WIP !!! DO NOT REVIEW OR MERGE UNTIL READY
This PR scope: