Skip to content

Allow customizing ONNX SessionOptions in TransformersEmbeddingModel - #7126

Open
Emryswu wants to merge 1 commit into
spring-projects:mainfrom
Emryswu:transformers-session-options
Open

Emryswu wants to merge 1 commit into
spring-projects:mainfrom
Emryswu:transformers-session-options

Conversation

@Emryswu

@Emryswu Emryswu commented Oct 9, 2026

Copy link
Copy Markdown

Add a SessionOptionsCustomizer callback to TransformersEmbeddingModel so that users can tune the ONNX Runtime session before it is created, for example to limit CPU usage:

model.setSessionOptionsCustomizer(options -> options.setIntraOpNumThreads(2));

The customizer runs after the existing GPU configuration from setGpuDeviceId.

While here, the SessionOptions are no longer closed right after the session is created. ONNX Runtime requires them to outlive the session (as pointed out in #2152), so they are now kept open and released in close() after the session.

Fixes #3761

Add a `SessionOptionsCustomizer` callback to
`TransformersEmbeddingModel` so users can tune the ONNX Runtime
session, for example to limit the number of intra-op threads.

The session options are now kept open for the lifetime of the
session and released in `close()`, as required by ONNX Runtime.

Fixes spring-projects#3761

Signed-off-by: Emrys <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TransformersEmbeddingModel and configuration of Threads

2 participants