-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support DisposableNamedOnnxValue inputs in c# Run() #3175
Conversation
Synced offline with @fs-eire. After discussing, we felt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed offline with @hariharans29 , NamedOnnxValue
should be kept stateless. it does not implement interface IDisposable
so it should not hold the IntPtr inside. ToNativeOnnxValue
may need to be updated so that it outputs a boolean value to help Run()
to determine whether to clean up the value or not.
for adding a setter to Name
, this is a valid requirement for users to pass the output as input to another inference session. There are 2 options to support this :
- enabling users to change the
Name
property of aNamedOnnxValue
object - enabling users to create a new
NamedOnnxValue
object by performing a shallow copy from another.
it looks like both options have pros and cons so I would like to hear from more people - @jignparm @pranavsharma
protected IDisposable _nativeMemoryManager; | ||
protected DisposableNamedOnnxValue(string name, Object value, IDisposable nativeMemoryManager) | ||
private NativeMemoryHandler _nativeMemoryManager; | ||
private DisposableNamedOnnxValue(string name, Object value, NativeMemoryHandler nativeMemoryManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctor is private now as per @fs-eire 's suggestion
Made the change to keep |
// Make sure that this instance hasn't been disposed yet | ||
if (disposedValue) | ||
{ | ||
throw new Exception("This instance of DisposableNamedOnnxValue has already been disposed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance of DisposableNamedOnnxValue has already been disposed [](start = 37, length = 67)
Should be a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug in the user code ? Probably. But they get a user friendly error message this way...
csharp/src/Microsoft.ML.OnnxRuntime/DisposableNamedOnnxValue.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Description:
DisposableNamedOnnxValue
inputs in c# Run() inputs are to be supported as ``DisposableNamedOnnxValueis
NamedOnnxValue`.This change has the following parts:
DisposableNamedOnnxValue
inputs to Session Run()NamedOnnxValue
/DisposableNamedOnnxValue
. This is required if someone were to pass in the output of Run() to the input of another Run() as the names of the input feed is likely to be different from the name of the output feed.Motivation and Context
Resolve #2983