@@ -467,23 +467,29 @@ def test_onnx_use_custom_allocator(env):
467467 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
468468 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory" ]), 0 )
469469
470- # Expect using the allocator during model set for allocating the model, its input name and output name.
470+ # Expect using the allocator during model set for allocating the model, its input name and output name:
471+ # overall 3 allocations. The model raw size is 130B ,and the names are 2B each. In practice we allocate
472+ # more than 134B as Redis allocator will use additional memory for its internal management and for the
473+ # 64-Byte alignment. When the test runs with valgrind, redis will use malloc for the allocations
474+ # (hence will not use additional memory).
471475 ret = con .execute_command ('AI.MODELSET' , 'm{1}' , 'ONNX' , 'CPU' , 'BLOB' , model_pb )
472476 env .assertEqual (ret , b'OK' )
473477 ai_memory_config = {k .split (":" )[0 ]: k .split (":" )[1 ]
474478 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
475- env .assertTrue (int (ai_memory_config ["ai_onnxruntime_memory" ]) > 100 )
479+
480+ # Expect using at least 130+63+(size of an address) + 2*(2+63+(size of an address)) bytes.
481+ env .assertTrue (int (ai_memory_config ["ai_onnxruntime_memory" ]) > 334 )
476482 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory_access_num" ]), 3 )
477483
478- # Expect using the allocator free function when releasing the model.
484+ # Expect using the allocator free function when releasing the model and input and output names .
479485 con .execute_command ('AI.MODELDEL' , 'm{1}' )
480486 env .assertFalse (con .execute_command ('EXISTS' , 'm{1}' ))
481487 ai_memory_config = {k .split (":" )[0 ]: k .split (":" )[1 ]
482488 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
483489 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory" ]), 0 )
484490 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory_access_num" ]), 6 )
485491
486- # test allocator in model run op
492+ # test the use of Redis allocator in model run op.
487493 model_filename = os .path .join (test_data_path , 'mnist.onnx' )
488494 sample_filename = os .path .join (test_data_path , 'one.raw' )
489495
@@ -496,7 +502,8 @@ def test_onnx_use_custom_allocator(env):
496502 env .assertEqual (ret , b'OK' )
497503 con .execute_command ('AI.TENSORSET' , 'a{1}' , 'FLOAT' , 1 , 1 , 28 , 28 , 'BLOB' , sample_raw )
498504
499- # Expect 16 allocator's access from onnx during the run.
505+ # Expect 16 allocator's access from onnx during the run (in addition to the allocations that were made while
506+ # creating the model).
500507 ai_memory_config = {k .split (":" )[0 ]: k .split (":" )[1 ]
501508 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
502509 allocator_access_num_before = ai_memory_config ["ai_onnxruntime_memory_access_num" ]
@@ -528,15 +535,20 @@ def test_onnx_use_custom_allocator_with_GPU(env):
528535 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
529536 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory" ]), 0 )
530537
531- # Create the same model, once for CPU and once for GPU.
532- # Expect using the allocator during model set for allocating the model, its input name and output name in CPU,
533- # but for GPU, expcet using the allocator only for allocating input and output names.
538+ # Expect using the allocator during model set for allocating the model, its input name and output name:
539+ # overall 3 allocations. The model raw size is 130B ,and the names are 2B each. In practice we allocate
540+ # more than 134B as Redis allocator will use additional memory for its internal management and for the
541+ # 64-Byte alignment. When the test runs with valgrind, redis will use malloc for the allocations.
534542 ret = con .execute_command ('AI.MODELSET' , 'm_gpu{1}' , 'ONNX' , DEVICE , 'BLOB' , model_pb )
535543 env .assertEqual (ret , b'OK' )
544+
545+ # but for GPU, expect using the allocator only for allocating input and output names (not the model itself).
536546 ret = con .execute_command ('AI.MODELSET' , 'm_cpu{1}' , 'ONNX' , 'CPU' , 'BLOB' , model_pb )
537547 env .assertEqual (ret , b'OK' )
538548 ai_memory_config = {k .split (":" )[0 ]: k .split (":" )[1 ]
539549 for k in con .execute_command ("INFO MODULES" ).decode ().split ("#" )[4 ].split ()[1 :]}
540- env .assertTrue (int (ai_memory_config ["ai_onnxruntime_memory" ]) > 100 )
550+
551+ # Expect using at least 130+63+(size of an address) + 4*(2+63+(size of an address)) bytes.
552+ env .assertTrue (int (ai_memory_config ["ai_onnxruntime_memory" ]) > 472 )
541553 env .assertTrue (int (ai_memory_config ["ai_onnxruntime_memory" ]) < 705 )
542554 env .assertEqual (int (ai_memory_config ["ai_onnxruntime_memory_access_num" ]), 5 )
0 commit comments