[code-reflection] RFR: Model lifetimes of onnx session-related objects more explicitly [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Mar 3 15:42:23 UTC 2025
On Mon, 3 Mar 2025 15:21:34 GMT, Adam Sotona <asotona at openjdk.org> wrote:
> I would suggest to merge this PR first as a fix.
If there's consensus, I'm happy to do that - let's hear from @PaulSandoz
>
> Current OnnxRuntime is a simple prototype focused on a single use case and needs to be refactored (maybe multiple times) to physically support all potential usecases (which we didn't even collected yet). A nice API box might be designed around it later.
If environment can only be created once, this seems to strongly argue for hiding the environment creation -- and instead expose the desired environment options in some other way.
>
> From all the discussion here I see the instantiation of the environment should be explicit (even doing it twice may cause a crash) and it might theoretically serve as a wrapper for default arena/allocator. However an option to shorten lifetime of the execution results should remain.
>
> I propose an alternative solution - create a new Arena.ofAuto() for each model/session execution and associate the results with it, so they are GCed and released when no more needed.
Using automatic arena is a good way to keep the API simple, but it is IMHO insufficient to deal with timely deallocation -- see the experiment mentioned here:
https://github.com/openjdk/babylon/pull/332#issuecomment-2690607634
-------------
PR Comment: https://git.openjdk.org/babylon/pull/332#issuecomment-2694799786
More information about the babylon-dev
mailing list