[WIP] Put the output of the model into existing NDArrays when provided - #618
[WIP] Put the output of the model into existing NDArrays when provided#618zemei wants to merge 1 commit into
Conversation
|
In general, this is a good idea to reuse the output NDArrays, but define NDList at Predictor is debatable. I think, this can be implemented at Translator level instead, and we can document how to reuse the NDList in Translator implementation. The outputs support at Block level is necessary to support reuse the NDList, but may not work for all block, we can add TODO to some of the Block implementation to make it reusable. |
|
@frankfliu @zemei Maybe we can try to tweak around on the ctx through implementing a cached NDArray holder. User are responsible to control the life-cycle of it. public O processInput(Context ctx, I input) {
NDArray array = ctx.getCachedNdArray("name");
}This CachedNDArray will not be vanished until the end of Model life cycle. But there is a risk for memory leak if use misuse this component. |
|
Are you still interested in this PR? I took a close look today. The idea to reuse input/output tensor is great, however I don't think this implementation is optimal:
|
Introducing an optional output
NDListparameter on thePredictor::predictinterface. When the output parameter is provided the underlying engine will copy the inference result into the correspondingNDArrayinstead of creating new objects.This functionality is useful for high throughput systems as it reduces the number of memory allocations and reduces the load on the garbage collector.
TODO: