Skip to content
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

Add Set terminate Option for user #985

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Conversation

ajindal1
Copy link
Contributor

Add an option to Terminate the current session and the session remains in the terminated state until the user calls the unset terminate option.

src/models/model.cpp Outdated Show resolved Hide resolved
src/generators.h Outdated Show resolved Hide resolved
src/generators.cpp Outdated Show resolved Hide resolved
src/generators.cpp Outdated Show resolved Hide resolved
src/generators.cpp Outdated Show resolved Hide resolved
src/generators.cpp Outdated Show resolved Hide resolved
src/generators.h Outdated Show resolved Hide resolved
Copy link
Contributor

@baijumeswani baijumeswani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a unit test for this feature?

@baijumeswani
Copy link
Contributor

Do we intend to expose this in other language bindings?

test/c_api_tests.cpp Outdated Show resolved Hide resolved
src/generators.cpp Show resolved Hide resolved
@@ -65,7 +65,18 @@ void State::Run(OrtSession& session, int new_batch_size) {
}
Copy link
Member

@RyanUnderhill RyanUnderhill Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In session.Run(...) above on line 58, we don't do anything on termination?

The issue is that there's a potential error race. If the user calls 'SetTerminate()' and then a non terminate error was thrown from session.Run() the user will not know it was a non termination related error (unless they look at the string).

Can we detect termination from session.Run? If so, we should rename session_terminated to session_terminate_set and have a second variable for "session_terminated" for if we actually hit the termination case (or if we call ThrowErrorIfSessionTerminated, as that will catch the non session.Run terminate cases).

This way we separate requesting termination from hitting termination, and IsTerminated() should only return true if we hit termination. This does mean that IsTerminated() will return false after SetTerminate() is called, and won't return true until a function is called that checks for termination. This could be a problem.

@baijumeswani can review my thinking also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's an interesting question. I believe the condition you are mentioning is rare, if the session is already terminated then it might be possible that the error might be different because of it being in terminated state. Also, if the error occurs because of some other reason, it should be produced in another run when the processing happens in non-terminated state and can be caught at that time.

@ajindal1
Copy link
Contributor Author

Since we wanted to add runoptions instead of individual APIs, created a new PR for this work #1011. Will close this once the PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants