From 7464a150a8852a2fa46f5bfff9d1b0bf2520e7dd Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Wed, 1 Jul 2026 11:27:39 -0700 Subject: [PATCH 01/12] Add weightless support for all initializers (API surface) Add API surface for expanding weightless mode to cover all initializers (internal and external), working in both JIT and AOT flows: Session options: - Add ep.enable_weightless: unified weightless option for all initializers - Add ep.context_source_model_path: runtime override for source model location - Deprecate ep.enable_weightless_ep_context_nodes (external-only, AOT-only) OrtEpApi: - Add GetWeightlessSupport: EP capability query for the handshake. App requests weightless (session option), EP confirms support (this API). OrtCompileApi: - Add ModelCompilationOptions_SetWeightlessCache: enable weightless for AOT compilation path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../core/session/onnxruntime_c_api.h | 24 +++++++++ .../core/session/onnxruntime_ep_c_api.h | 49 +++++++++++++++++++ .../onnxruntime_session_options_config_keys.h | 39 +++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index a73868527771a..3215123eee251 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -8359,6 +8359,30 @@ struct OrtCompileApi { ORT_API2_STATUS(ModelCompilationOptions_SetInputModel, _In_ OrtModelCompilationOptions* model_compile_options, _In_ const OrtModel* model); + + /** \brief Enable weightless mode for model compilation. + * + * When enabled, the compiled EPContext model will not embed constant initializer data in the EP's + * compiled binary. Instead, the initializer data must be provided at inference time, either from the + * source model (via the "onnx_model_filename" EPContext node attribute or the + * "ep.context_source_model_path" session option) or from externalized weights. + * + * This enables smaller compiled models and allows sharing initializer data across multiple compiled + * model variants (e.g., multi-platform caches for different hardware generations). + * + * ORT verifies that the target EP supports weightless mode by calling OrtEpApi::GetWeightlessSupport(). + * If the EP does not support weightless mode, an error is returned. + * + * \param[in] model_compile_options The OrtModelCompilationOptions instance. + * \param[in] use_weightless If true, enable weightless mode for the compiled model. + * + * \snippet{doc} snippets.dox OrtStatus Return Value + * + * \since Version 1.28. + */ + ORT_API2_STATUS(ModelCompilationOptions_SetWeightlessCache, + _In_ OrtModelCompilationOptions* model_compile_options, + _In_ bool use_weightless); }; /** diff --git a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h index 34a57b11e1748..3cd772748575c 100644 --- a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h @@ -2111,6 +2111,26 @@ typedef enum OrtGraphCaptureNodeAssignmentPolicy { OrtGraphCaptureNodeAssignmentPolicy_ALLOW_CPU_FOR_SHAPES = 1, } OrtGraphCaptureNodeAssignmentPolicy; +/** + * \brief Describes the scope of an EP's weightless mode support. + * + * Returned by OrtEp::GetWeightlessSupport() to indicate which types of initializers + * the EP can operate on without copying. + * + * \since Version 1.28. + */ +typedef enum OrtWeightlessSupport { + /** EP does not support weightless mode. */ + OrtWeightlessSupport_NONE = 0, + + /** EP supports weightless mode for external initializers only. + * Internal initializers are still copied by the EP during compilation. */ + OrtWeightlessSupport_EXTERNAL_ONLY = 1, + + /** EP supports weightless mode for all initializers (internal and external). */ + OrtWeightlessSupport_ALL = 2, +} OrtWeightlessSupport; + /** * \brief The OrtEp struct provides functions to implement for an execution provider. * \since Version 1.22. @@ -2630,6 +2650,35 @@ struct OrtEp { * \since Version 1.27. */ ORT_API2_STATUS(ReleaseCapturedGraph, _In_ OrtEp* this_ptr, _In_ int graph_annotation_id); + + /** \brief Query the execution provider's weightless mode support. + * + * When weightless mode is enabled (via the "ep.enable_weightless" session option), ORT calls this function + * to determine the scope of the EP's weightless support. The EP returns an OrtWeightlessSupport value + * indicating whether it supports weightless mode for all initializers, external initializers only, or not + * at all. + * + * The EP's response may depend on the underlying hardware or driver capabilities. For example, an EP may + * support weightless mode for all initializers on newer hardware but only for external initializers on + * older hardware that requires weight transformation. + * + * EPs that support weightless mode should: + * - During Compile(), obtain initializer data via ValueInfo_GetInitializerValue() and hold references + * to the underlying data buffers. ORT guarantees these buffers remain valid for the session lifetime. + * - Set drop_constant_initializers to true in OrtNodeFusionOptions, since the EP will use its own + * cached references rather than receiving initializers via KernelContext inputs. + * + * \param[in] this_ptr The OrtEp instance. + * \param[out] support Output parameter set to the EP's weightless support scope. + * + * \snippet{doc} snippets.dox OrtStatus Return Value + * + * \note Implementation of this function is optional. If set to NULL, ORT assumes the EP does not + * support weightless mode (equivalent to OrtWeightlessSupport_NONE). + * + * \since Version 1.28. + */ + ORT_API2_STATUS(GetWeightlessSupport, _In_ const OrtEp* this_ptr, _Out_ OrtWeightlessSupport* support); }; /** \brief The function signature that ORT will call to create OrtEpFactory instances. diff --git a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h index 3efa6ae50faa7..14a62ad26efbd 100644 --- a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h +++ b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h @@ -580,8 +580,47 @@ static const char* const kOrtSessionOptionsRecordEpGraphAssignmentInfo = "sessio // Option values: // - "0": disable. (default) // - "1": enable. +// +// \deprecated Since version 1.28. Use "ep.enable_weightless" instead, which covers all initializers +// (internal and external) and works in both JIT and AOT flows. static const char* const kOrtSessionOptionEpEnableWeightlessEpContextNodes = "ep.enable_weightless_ep_context_nodes"; +// Enable weightless mode for all initializers (internal and external). +// +// When enabled, ONNX Runtime requests that the execution provider operate without embedding or copying +// constant initializers. ORT extends the lifetime of initializer data past EP compilation so that the EP +// can hold references to the data without copying it. +// +// This option works in both JIT (non-cached) and AOT (EPContext model) flows: +// - JIT: ORT keeps initializer data alive for the session lifetime so the EP can reference it directly. +// - AOT: ORT generates EPContext models with weightless EPContext nodes. The EP should use the +// "onnx_model_filename" EPContext node attribute or the "ep.context_source_model_path" session option +// to locate the source model's initializer data at inference time. +// +// ORT checks that the EP supports weightless mode by calling OrtEpApi::GetWeightlessSupport(). +// If the EP does not support it, ORT returns an error. +// +// Option values: +// - "0": disable. (default) +// - "1": enable. +// +// \since Version 1.28. +static const char* const kOrtSessionOptionEpEnableWeightless = "ep.enable_weightless"; + +// Specifies the file path to the original (source) ONNX model when running inference with a weightless +// EPContext model. +// +// When an EPContext model is generated with weightless mode ("ep.enable_weightless" = "1"), the compiled +// model may not contain the original initializer data. At inference time, the EP needs to load the +// initializer data from the source model. This session option provides the runtime location of the source +// model, which may differ from the path used at compile time (stored in the EPContext node's +// "onnx_model_filename" attribute). +// +// If not set, the EP falls back to the "onnx_model_filename" attribute in the EPContext node. +// +// \since Version 1.28. +static const char* const kOrtSessionOptionEpContextSourceModelPath = "ep.context_source_model_path"; + // Controls the intra-op thread pool size for a session. // Value should be a base-10 int32 string. // Equivalent to OrtApi::SetIntraOpNumThreads. From fcc0a8d8c6c520359994c6624c4ed38d356118a1 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 2 Jul 2026 09:47:07 -0700 Subject: [PATCH 02/12] Update GetWeightlessSupport comment: KernelContext is current path Clarify that extending OrtValue lifetime past Compile() for direct pointer caching is planned but not yet implemented. Currently, EPs should use drop_constant_initializers=false and access initializers via KernelContext_GetInput() at Compute() time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../onnxruntime/core/session/onnxruntime_ep_c_api.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h index 3cd772748575c..a8445c625fa23 100644 --- a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h @@ -2662,11 +2662,14 @@ struct OrtEp { * support weightless mode for all initializers on newer hardware but only for external initializers on * older hardware that requires weight transformation. * - * EPs that support weightless mode should: - * - During Compile(), obtain initializer data via ValueInfo_GetInitializerValue() and hold references - * to the underlying data buffers. ORT guarantees these buffers remain valid for the session lifetime. - * - Set drop_constant_initializers to true in OrtNodeFusionOptions, since the EP will use its own - * cached references rather than receiving initializers via KernelContext inputs. + * EPs that support weightless mode should set drop_constant_initializers to false in OrtNodeFusionOptions + * so that ORT provides the initializer data as inputs to the compiled/fused node. The EP can then access + * these initializers at Compute() time via KernelContext_GetInput(). + * + * \note Extending the lifetime of initializer data obtained via ValueInfo_GetInitializerValue() during + * Compile() so that the EP can cache and reuse data pointers directly (without going through + * KernelContext) is planned but not yet implemented. Until then, KernelContext_GetInput() is the + * only supported way to access initializer data at Compute() time. * * \param[in] this_ptr The OrtEp instance. * \param[out] support Output parameter set to the EP's weightless support scope. From 966a441d761841a60ef60e5c9fa9c1891c620120 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 2 Jul 2026 11:54:26 -0700 Subject: [PATCH 03/12] Fix comment: initializers provided at session creation, not inference time Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- include/onnxruntime/core/session/onnxruntime_c_api.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 3215123eee251..5518a74f11d26 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -8363,9 +8363,9 @@ struct OrtCompileApi { /** \brief Enable weightless mode for model compilation. * * When enabled, the compiled EPContext model will not embed constant initializer data in the EP's - * compiled binary. Instead, the initializer data must be provided at inference time, either from the - * source model (via the "onnx_model_filename" EPContext node attribute or the - * "ep.context_source_model_path" session option) or from externalized weights. + * compiled binary. Instead, the initializer data must be provided when creating a session from the + * compiled model, either from the source model (via the "onnx_model_filename" EPContext node attribute + * or the "ep.context_source_model_path" session option) or from externalized weights. * * This enables smaller compiled models and allows sharing initializer data across multiple compiled * model variants (e.g., multi-platform caches for different hardware generations). From 8729eac56365303421094a41659af7aa171da8fc Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 2 Jul 2026 12:07:52 -0700 Subject: [PATCH 04/12] Update session option comments: current JIT path and session creation timing - ep.enable_weightless: clarify JIT uses KernelContext path (direct pointer caching is TODO), remove premature lifetime extension claim - ep.context_source_model_path: fix 'inference time' to 'session creation' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../onnxruntime_session_options_config_keys.h | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h index 14a62ad26efbd..d36b18265354e 100644 --- a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h +++ b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h @@ -588,14 +588,17 @@ static const char* const kOrtSessionOptionEpEnableWeightlessEpContextNodes = "ep // Enable weightless mode for all initializers (internal and external). // // When enabled, ONNX Runtime requests that the execution provider operate without embedding or copying -// constant initializers. ORT extends the lifetime of initializer data past EP compilation so that the EP -// can hold references to the data without copying it. +// constant initializers. // // This option works in both JIT (non-cached) and AOT (EPContext model) flows: -// - JIT: ORT keeps initializer data alive for the session lifetime so the EP can reference it directly. +// - JIT: The EP should set drop_constant_initializers to false in OrtNodeFusionOptions so that ORT +// provides the initializer data as inputs to the compiled/fused node. The EP can then access these +// initializers at Compute() time via KernelContext_GetInput(). +// NOTE: Extending the lifetime of initializer data obtained via ValueInfo_GetInitializerValue() during +// Compile() so that the EP can cache and reuse data pointers directly is planned but not yet implemented. // - AOT: ORT generates EPContext models with weightless EPContext nodes. The EP should use the // "onnx_model_filename" EPContext node attribute or the "ep.context_source_model_path" session option -// to locate the source model's initializer data at inference time. +// to locate the source model's initializer data when creating a session from the compiled model. // // ORT checks that the EP supports weightless mode by calling OrtEpApi::GetWeightlessSupport(). // If the EP does not support it, ORT returns an error. @@ -607,14 +610,14 @@ static const char* const kOrtSessionOptionEpEnableWeightlessEpContextNodes = "ep // \since Version 1.28. static const char* const kOrtSessionOptionEpEnableWeightless = "ep.enable_weightless"; -// Specifies the file path to the original (source) ONNX model when running inference with a weightless +// Specifies the file path to the original (source) ONNX model when creating a session with a weightless // EPContext model. // // When an EPContext model is generated with weightless mode ("ep.enable_weightless" = "1"), the compiled -// model may not contain the original initializer data. At inference time, the EP needs to load the -// initializer data from the source model. This session option provides the runtime location of the source -// model, which may differ from the path used at compile time (stored in the EPContext node's -// "onnx_model_filename" attribute). +// model may not contain the original initializer data. When creating a session from the compiled model, +// the EP needs to load the initializer data from the source model. This session option provides the +// runtime location of the source model, which may differ from the path used at compile time (stored in +// the EPContext node's "onnx_model_filename" attribute). // // If not set, the EP falls back to the "onnx_model_filename" attribute in the EPContext node. // From cc481da3448b7f3c2d2283e7fa1ae55071c8864b Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 6 Jul 2026 13:03:57 -0700 Subject: [PATCH 05/12] Add C APIs for weightless source model (file path and byte buffer) Add two new OrtApi functions for providing the source model's initializer data when creating a session from a weightless EPContext model: - SessionOptionsSetWeightlessSourceModelPath: file path to source model, acts as runtime override for the onnx_model_filename EPContext attribute. - SessionOptionsSetWeightlessSourceModelFromBuffer: in-memory byte buffer for scenarios where the source model is not on disk. Caller must keep the buffer alive for the session lifetime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../core/session/onnxruntime_c_api.h | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 5518a74f11d26..c4753717eeb4c 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -7517,6 +7517,45 @@ struct OrtApi { */ ORT_API2_STATUS(KernelContext_GetSyncStream, _In_ const OrtKernelContext* context, _Outptr_result_maybenull_ OrtSyncStream** out); + + /** \brief Set the file path of the original (source) ONNX model for weightless EPContext sessions. + * + * When creating a session from a weightless EPContext model, the EP may need access to the source model's + * initializer data. This function sets the file path to the source model, overriding the + * "onnx_model_filename" attribute in the EPContext node if one is present. + * + * This is useful when the source model is deployed to a different location than where it was at compile time. + * + * The file must remain accessible for the lifetime of the session. + * + * \param[in] options The OrtSessionOptions instance. + * \param[in] source_model_path Null terminated string of the file path (wchar on Windows, char otherwise). + * + * \snippet{doc} snippets.dox OrtStatus Return Value + * + * \since Version 1.28. + */ + ORT_API2_STATUS(SessionOptionsSetWeightlessSourceModelPath, _Inout_ OrtSessionOptions* options, + _In_ const ORTCHAR_T* source_model_path); + + /** \brief Set the source ONNX model as a byte buffer for weightless EPContext sessions. + * + * When creating a session from a weightless EPContext model, the EP may need access to the source model's + * initializer data. This function provides the source model as an in-memory byte buffer, for scenarios + * where the source model is not available as a file on disk (e.g., loaded from a package or downloaded). + * + * The caller retains ownership of the buffer and must ensure it remains valid for the lifetime of the session. + * + * \param[in] options The OrtSessionOptions instance. + * \param[in] source_model_data Pointer to the source model byte buffer. + * \param[in] source_model_data_length Size of the byte buffer in bytes. + * + * \snippet{doc} snippets.dox OrtStatus Return Value + * + * \since Version 1.28. + */ + ORT_API2_STATUS(SessionOptionsSetWeightlessSourceModelFromBuffer, _Inout_ OrtSessionOptions* options, + _In_ const void* source_model_data, _In_ size_t source_model_data_length); }; /* From b5867269e0392320b839935fe2acea104752ac79 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 6 Jul 2026 13:13:41 -0700 Subject: [PATCH 06/12] Implement weightless source model and compilation APIs SessionOptionsSetWeightlessSourceModelPath: - Stores file path in OrtSessionOptions for runtime override of onnx_model_filename EPContext attribute - Clears any previously set buffer source SessionOptionsSetWeightlessSourceModelFromBuffer: - Stores borrowed buffer pointer + size in OrtSessionOptions - Caller must keep buffer alive for session lifetime - Clears any previously set file path source ModelCompilationOptions_SetWeightlessCache: - Adds use_weightless_cache_ flag to ModelCompilationOptions - Sets ep.enable_weightless=1 in session config options - Registered in ort_compile_api table Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../core/session/abi_session_options_impl.h | 6 ++++ onnxruntime/core/session/compile_api.cc | 18 ++++++++++ onnxruntime/core/session/compile_api.h | 4 +++ .../core/session/model_compilation_options.cc | 9 +++++ .../core/session/model_compilation_options.h | 9 +++++ onnxruntime/core/session/onnxruntime_c_api.cc | 35 +++++++++++++++++++ onnxruntime/core/session/ort_apis.h | 9 +++++ 7 files changed, 90 insertions(+) diff --git a/onnxruntime/core/session/abi_session_options_impl.h b/onnxruntime/core/session/abi_session_options_impl.h index e2a9bf649f2e4..dcfbafbee37d9 100644 --- a/onnxruntime/core/session/abi_session_options_impl.h +++ b/onnxruntime/core/session/abi_session_options_impl.h @@ -38,4 +38,10 @@ struct OrtSessionOptions { // e.g. for EP called 'MyEP' an options 'device_id' would be added as 'ep.myep.device_id' // with GetProviderOptionPrefix returning 'ep.myep.' static std::string GetProviderOptionPrefix(const char* provider_name); + + // Weightless source model for EPContext sessions. + // Set via SessionOptionsSetWeightlessSourceModelPath or SessionOptionsSetWeightlessSourceModelFromBuffer. + onnxruntime::PathString weightless_source_model_path; + const void* weightless_source_model_data = nullptr; + size_t weightless_source_model_data_size = 0; }; diff --git a/onnxruntime/core/session/compile_api.cc b/onnxruntime/core/session/compile_api.cc index 54d26021d8c99..db479ec75ea9a 100644 --- a/onnxruntime/core/session/compile_api.cc +++ b/onnxruntime/core/session/compile_api.cc @@ -327,6 +327,22 @@ ORT_API_STATUS_IMPL(OrtCompileAPI::ModelCompilationOptions_SetInputModel, API_IMPL_END } +ORT_API_STATUS_IMPL(OrtCompileAPI::ModelCompilationOptions_SetWeightlessCache, + _In_ OrtModelCompilationOptions* ort_model_compile_options, + _In_ bool use_weightless) { + API_IMPL_BEGIN +#if !defined(ORT_MINIMAL_BUILD) + auto model_compile_options = reinterpret_cast(ort_model_compile_options); + ORT_API_RETURN_IF_STATUS_NOT_OK(model_compile_options->SetWeightlessCache(use_weightless)); + return nullptr; +#else + ORT_UNUSED_PARAMETER(ort_model_compile_options); + ORT_UNUSED_PARAMETER(use_weightless); + return OrtApis::CreateStatus(ORT_NOT_IMPLEMENTED, "Compile API is not supported in this build"); +#endif // !defined(ORT_MINIMAL_BUILD) + API_IMPL_END +} + ORT_API_STATUS_IMPL(OrtCompileAPI::CompileModel, _In_ const OrtEnv* env, _In_ const OrtModelCompilationOptions* ort_model_compile_options) { API_IMPL_BEGIN @@ -367,6 +383,8 @@ static constexpr OrtCompileApi ort_compile_api = { &OrtCompileAPI::ModelCompilationOptions_SetInputModel, // End of Version 24 - DO NOT MODIFY ABOVE + + &OrtCompileAPI::ModelCompilationOptions_SetWeightlessCache, }; // checks that we don't violate the rule that the functions must remain in the slots they were originally assigned diff --git a/onnxruntime/core/session/compile_api.h b/onnxruntime/core/session/compile_api.h index e8f171ee24295..81b81c0378bdf 100644 --- a/onnxruntime/core/session/compile_api.h +++ b/onnxruntime/core/session/compile_api.h @@ -45,4 +45,8 @@ ORT_API_STATUS_IMPL(ModelCompilationOptions_SetInputModel, _In_ OrtModelCompilationOptions* model_compile_options, _In_ const OrtModel* model); +ORT_API_STATUS_IMPL(ModelCompilationOptions_SetWeightlessCache, + _In_ OrtModelCompilationOptions* model_compile_options, + _In_ bool use_weightless); + } // namespace OrtCompileAPI diff --git a/onnxruntime/core/session/model_compilation_options.cc b/onnxruntime/core/session/model_compilation_options.cc index 9f6d1f9f1a9bc..6c5f26715be7b 100644 --- a/onnxruntime/core/session/model_compilation_options.cc +++ b/onnxruntime/core/session/model_compilation_options.cc @@ -251,6 +251,15 @@ Status ModelCompilationOptions::SetGraphOptimizationLevel(GraphOptimizationLevel return Status::OK(); } +Status ModelCompilationOptions::SetWeightlessCache(bool use_weightless) { + use_weightless_cache_ = use_weightless; + if (use_weightless) { + ORT_RETURN_IF_ERROR( + session_options_.value.config_options.AddConfigEntry(kOrtSessionOptionEpEnableWeightless, "1")); + } + return Status::OK(); +} + Status ModelCompilationOptions::Check() const { const ConfigOptions& config_options = session_options_.value.config_options; diff --git a/onnxruntime/core/session/model_compilation_options.h b/onnxruntime/core/session/model_compilation_options.h index a15af565c4d54..d7f4ddc691b83 100644 --- a/onnxruntime/core/session/model_compilation_options.h +++ b/onnxruntime/core/session/model_compilation_options.h @@ -182,6 +182,14 @@ class ModelCompilationOptions { /// Status SetGraphOptimizationLevel(GraphOptimizationLevel graph_optimization_level); + /// + /// Enable weightless mode for model compilation. + /// When enabled, the compiled EPContext model will not embed constant initializer data. + /// + /// True to enable weightless mode + /// Status indicating potential error + Status SetWeightlessCache(bool use_weightless); + /// /// Checks if the compilation options described by this object are valid. /// @@ -235,6 +243,7 @@ class ModelCompilationOptions { const void* input_model_data_ = nullptr; size_t input_model_data_size_ = 0; const OrtModel* input_model_ = nullptr; // Borrowed pointer + bool use_weightless_cache_ = false; }; } // namespace onnxruntime #endif // !defined(ORT_MINIMAL_BUILD) diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 22df898ca3227..d9db3a50dcf14 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -2758,6 +2758,38 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsSetCustomJoinThreadFn, _Inout_ OrtSes API_IMPL_END } +ORT_API_STATUS_IMPL(OrtApis::SessionOptionsSetWeightlessSourceModelPath, _Inout_ OrtSessionOptions* options, + _In_ const ORTCHAR_T* source_model_path) { + API_IMPL_BEGIN + if (source_model_path == nullptr || source_model_path[0] == '\0') { + return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Invalid source model path: path is null or empty"); + } + + options->weightless_source_model_path = source_model_path; + options->weightless_source_model_data = nullptr; + options->weightless_source_model_data_size = 0; + return nullptr; + API_IMPL_END +} + +ORT_API_STATUS_IMPL(OrtApis::SessionOptionsSetWeightlessSourceModelFromBuffer, _Inout_ OrtSessionOptions* options, + _In_ const void* source_model_data, _In_ size_t source_model_data_length) { + API_IMPL_BEGIN + if (source_model_data == nullptr) { + return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Invalid source model: data pointer is null"); + } + + if (source_model_data_length == 0) { + return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Invalid source model: data size is 0"); + } + + options->weightless_source_model_data = source_model_data; + options->weightless_source_model_data_size = source_model_data_length; + options->weightless_source_model_path.clear(); + return nullptr; + API_IMPL_END +} + ORT_API(void, OrtApis::ReleaseValueInfo, _Frees_ptr_opt_ OrtValueInfo* value_info) { delete value_info; } @@ -4918,6 +4950,9 @@ static constexpr OrtApi ort_api_1_to_28 = { &OrtApis::GetExperimentalFunction, &OrtApis::KernelContext_GetSyncStream, + + &OrtApis::SessionOptionsSetWeightlessSourceModelPath, + &OrtApis::SessionOptionsSetWeightlessSourceModelFromBuffer, }; // OrtApiBase can never change as there is no way to know what version of OrtApiBase is returned by OrtGetApiBase. diff --git a/onnxruntime/core/session/ort_apis.h b/onnxruntime/core/session/ort_apis.h index e747d0d0ab2d8..040e101ed0499 100644 --- a/onnxruntime/core/session/ort_apis.h +++ b/onnxruntime/core/session/ort_apis.h @@ -829,4 +829,13 @@ ORT_API_STATUS_IMPL(GetTensorElementTypeAndShapeDataReference, _In_ const OrtVal // Experimental API ORT_API(OrtExperimentalFnPtr, GetExperimentalFunction, _In_ const char* name); +ORT_API_STATUS_IMPL(KernelContext_GetSyncStream, _In_ const OrtKernelContext* context, + _Outptr_result_maybenull_ OrtSyncStream** out); + +// Weightless source model APIs +ORT_API_STATUS_IMPL(SessionOptionsSetWeightlessSourceModelPath, _Inout_ OrtSessionOptions* options, + _In_ const ORTCHAR_T* source_model_path); +ORT_API_STATUS_IMPL(SessionOptionsSetWeightlessSourceModelFromBuffer, _Inout_ OrtSessionOptions* options, + _In_ const void* source_model_data, _In_ size_t source_model_data_length); + } // namespace OrtApis From ce87089252136c671a5a3355fb198dcdfb03a25f Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 6 Jul 2026 13:52:44 -0700 Subject: [PATCH 07/12] Auto-set drop_constant_initializers=false when weightless is enabled When the app requests weightless mode and the EP confirms support via GetWeightlessSupport(), ORT automatically overrides drop_constant_initializers to false in GetCapability(). This ensures constant initializers remain as fused node inputs so the EP can access them via KernelContext_GetInput() at Compute() time. The override is logged at INFO level for diagnostics. Constructor queries the EP's weightless support at creation time and stores the result in weightless_enabled_ for use during GetCapability(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ep_plugin_provider_interfaces.cc | 27 ++++++++++++++++++- .../plugin_ep/ep_plugin_provider_interfaces.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc index c4b8dc86bb965..d823b1c1684a9 100644 --- a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc +++ b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc @@ -29,6 +29,7 @@ #include "core/session/plugin_ep/ep_event_profiling.h" #include "core/session/ort_apis.h" #include "core/providers/partitioning_utils.h" +#include "core/session/onnxruntime_session_options_config_keys.h" namespace onnxruntime { @@ -185,6 +186,20 @@ PluginExecutionProvider::PluginExecutionProvider(UniqueOrtEp ep, const OrtSessio kernel_registry_(std::move(kernel_registry)) { generate_ep_ctx_model_ = session_options.value.GetEpContextGenerationOptions().enable; + // Check if the app requested weightless mode and the EP supports it. + { + const auto weightless_requested = + session_options.value.config_options.GetConfigOrDefault(kOrtSessionOptionEpEnableWeightless, "0") != "0"; + if (weightless_requested && ort_ep_->ort_version_supported >= 28 && ort_ep_->GetWeightlessSupport != nullptr) { + OrtWeightlessSupport support = OrtWeightlessSupport_NONE; + auto* ort_status = ort_ep_->GetWeightlessSupport(ort_ep_.get(), &support); + if (ort_status == nullptr && support != OrtWeightlessSupport_NONE) { + weightless_enabled_ = true; + } + OrtApis::ReleaseStatus(ort_status); + } + } + // Extract EP-scoped session config entries (ep..* keys). // Arena options go to session_arena_options_; the rest go to provider_options_. { @@ -396,11 +411,21 @@ PluginExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_vie // TODO(adrianlizarraga): Do not use the heavy-weight CreateSupportedPartitions just to check if the user // provided a single partition. Use utils::MakeCapability() and create a new helper to check that there are no // unsupported nodes in any path between supported nodes. + + // When weightless mode is enabled, override drop_constant_initializers to false so that ORT keeps + // constant initializers as fused node inputs. The EP can then access them via KernelContext_GetInput(). + bool drop_constant_initializers = node_grouping.fusion_options.drop_constant_initializers; + if (weightless_enabled_ && drop_constant_initializers) { + LOGS(logger, INFO) << "Weightless mode enabled for " << Type() + << ": overriding drop_constant_initializers to false."; + drop_constant_initializers = false; + } + auto metadef_gen_functor = PluginEpMetaDefNameFunctor(metadef_id_generator_, graph_viewer, this->Type()); std::vector> capabilities = utils::CreateSupportedPartitions( graph_viewer, node_set, /*stop_ops*/ {}, std::move(metadef_gen_functor), this->Type(), this->Type(), /*node_unit_map*/ nullptr, - node_grouping.fusion_options.drop_constant_initializers); + drop_constant_initializers); if (capabilities.size() != 1) { LOGS(logger, ERROR) << "OrtEp::GetCapability() for " << Type() << " set nodes that cannot be fused together. " diff --git a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.h b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.h index 486d3c68c5c34..6f1af3fa9932a 100644 --- a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.h +++ b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.h @@ -174,6 +174,7 @@ class PluginExecutionProvider : public IExecutionProvider { std::vector ep_devices_; std::vector allocator_mem_infos_; bool generate_ep_ctx_model_ = false; + bool weightless_enabled_ = false; // Set if app requested weightless AND EP supports it // Provider options extracted from session-level config (ep..* keys, excluding arena.*). // Exposed through GetProviderOptions() so the framework reports the effective EP configuration. From 5cf46123988517ae03dd88fee4cfa1dd2cbddd48 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Wed, 8 Jul 2026 09:55:45 -0700 Subject: [PATCH 08/12] Add weightless_support EpDevice metadata key and update to version 1.29 Add kOrtEpDevice_EpMetadataKey_WeightlessSupport to onnxruntime_ep_device_ep_metadata_keys.h. EPs set this during GetSupportedDevices() so apps can query device-specific weightless capability before compilation via EpDevice_EpMetadata(). Valid values: 'none', 'external_only', 'all'. Update all new weightless APIs from version 1.28 to 1.29: - Session options: ep.enable_weightless, ep.context_source_model_path - OrtEpApi: OrtWeightlessSupport enum, GetWeightlessSupport - OrtApi: SessionOptionsSetWeightlessSourceModelPath, SessionOptionsSetWeightlessSourceModelFromBuffer - OrtCompileApi: ModelCompilationOptions_SetWeightlessCache - Version gate in PluginExecutionProvider constructor Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../onnxruntime/core/session/onnxruntime_c_api.h | 6 +++--- .../core/session/onnxruntime_ep_c_api.h | 4 ++-- .../onnxruntime_ep_device_ep_metadata_keys.h | 15 +++++++++++++++ .../onnxruntime_session_options_config_keys.h | 6 +++--- .../plugin_ep/ep_plugin_provider_interfaces.cc | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 095aab606f465..68aa8f7217ff1 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -7533,7 +7533,7 @@ struct OrtApi { * * \snippet{doc} snippets.dox OrtStatus Return Value * - * \since Version 1.28. + * \since Version 1.29. */ ORT_API2_STATUS(SessionOptionsSetWeightlessSourceModelPath, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* source_model_path); @@ -7552,7 +7552,7 @@ struct OrtApi { * * \snippet{doc} snippets.dox OrtStatus Return Value * - * \since Version 1.28. + * \since Version 1.29. */ ORT_API2_STATUS(SessionOptionsSetWeightlessSourceModelFromBuffer, _Inout_ OrtSessionOptions* options, _In_ const void* source_model_data, _In_ size_t source_model_data_length); @@ -8420,7 +8420,7 @@ struct OrtCompileApi { * * \snippet{doc} snippets.dox OrtStatus Return Value * - * \since Version 1.28. + * \since Version 1.29. */ ORT_API2_STATUS(ModelCompilationOptions_SetWeightlessCache, _In_ OrtModelCompilationOptions* model_compile_options, diff --git a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h index 4703e216cc874..6a7d508a1bbec 100644 --- a/include/onnxruntime/core/session/onnxruntime_ep_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_ep_c_api.h @@ -2117,7 +2117,7 @@ typedef enum OrtGraphCaptureNodeAssignmentPolicy { * Returned by OrtEp::GetWeightlessSupport() to indicate which types of initializers * the EP can operate on without copying. * - * \since Version 1.28. + * \since Version 1.29. */ typedef enum OrtWeightlessSupport { /** EP does not support weightless mode. */ @@ -2679,7 +2679,7 @@ struct OrtEp { * \note Implementation of this function is optional. If set to NULL, ORT assumes the EP does not * support weightless mode (equivalent to OrtWeightlessSupport_NONE). * - * \since Version 1.28. + * \since Version 1.29. */ ORT_API2_STATUS(GetWeightlessSupport, _In_ const OrtEp* this_ptr, _Out_ OrtWeightlessSupport* support); }; diff --git a/include/onnxruntime/core/session/onnxruntime_ep_device_ep_metadata_keys.h b/include/onnxruntime/core/session/onnxruntime_ep_device_ep_metadata_keys.h index cc83b7bca50c5..027ae172a2bbb 100644 --- a/include/onnxruntime/core/session/onnxruntime_ep_device_ep_metadata_keys.h +++ b/include/onnxruntime/core/session/onnxruntime_ep_device_ep_metadata_keys.h @@ -30,3 +30,18 @@ static const char* const kOrtEpDevice_EpMetadataKey_LibraryPath = "library_path" // if this metadata key is not present. // - "1": OrtHardwareDevice is virtual. static const char* const kOrtHardwareDevice_MetadataKey_IsVirtual = "is_virtual"; + +// Key for the execution provider's weightless mode support on a specific device. +// Set by the EP during GetSupportedDevices() via CreateEpDevice() metadata. +// The app can read it via EpDevice_EpMetadata() to check device-specific weightless capability +// before calling ModelCompilationOptions_SetWeightlessCache(). +// +// Possible values: +// - "none": EP does not support weightless mode on this device. This is the assumed default value +// if this metadata key is not present. +// - "external_only": EP supports weightless mode for external initializers only (e.g., older +// hardware/driver that must transform internal constants). +// - "all": EP supports weightless mode for all initializers (internal and external). +// +// \since Version 1.29. +static const char* const kOrtEpDevice_EpMetadataKey_WeightlessSupport = "weightless_support"; diff --git a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h index 5ddd2674301f7..b52d3b7f72e77 100644 --- a/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h +++ b/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h @@ -584,7 +584,7 @@ static const char* const kOrtSessionOptionsRecordEpGraphAssignmentInfo = "sessio // - "0": disable. (default) // - "1": enable. // -// \deprecated Since version 1.28. Use "ep.enable_weightless" instead, which covers all initializers +// \deprecated Since version 1.29. Use "ep.enable_weightless" instead, which covers all initializers // (internal and external) and works in both JIT and AOT flows. static const char* const kOrtSessionOptionEpEnableWeightlessEpContextNodes = "ep.enable_weightless_ep_context_nodes"; @@ -610,7 +610,7 @@ static const char* const kOrtSessionOptionEpEnableWeightlessEpContextNodes = "ep // - "0": disable. (default) // - "1": enable. // -// \since Version 1.28. +// \since Version 1.29. static const char* const kOrtSessionOptionEpEnableWeightless = "ep.enable_weightless"; // Specifies the file path to the original (source) ONNX model when creating a session with a weightless @@ -624,7 +624,7 @@ static const char* const kOrtSessionOptionEpEnableWeightless = "ep.enable_weight // // If not set, the EP falls back to the "onnx_model_filename" attribute in the EPContext node. // -// \since Version 1.28. +// \since Version 1.29. static const char* const kOrtSessionOptionEpContextSourceModelPath = "ep.context_source_model_path"; // Controls the intra-op thread pool size for a session. diff --git a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc index 660ef417e1c4d..a82715bcaa726 100644 --- a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc +++ b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc @@ -190,7 +190,7 @@ PluginExecutionProvider::PluginExecutionProvider(UniqueOrtEp ep, const OrtSessio { const auto weightless_requested = session_options.value.config_options.GetConfigOrDefault(kOrtSessionOptionEpEnableWeightless, "0") != "0"; - if (weightless_requested && ort_ep_->ort_version_supported >= 28 && ort_ep_->GetWeightlessSupport != nullptr) { + if (weightless_requested && ort_ep_->ort_version_supported >= 29 && ort_ep_->GetWeightlessSupport != nullptr) { OrtWeightlessSupport support = OrtWeightlessSupport_NONE; auto* ort_status = ort_ep_->GetWeightlessSupport(ort_ep_.get(), &support); if (ort_status == nullptr && support != OrtWeightlessSupport_NONE) { From e54cc91e6debf930d27a391cac94fcabf1d7ceae Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Wed, 8 Jul 2026 10:06:46 -0700 Subject: [PATCH 09/12] lintrunner -a --- onnxruntime/core/session/onnxruntime_c_api.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index d30f5a87f1e82..a2afa2f190d69 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -4949,7 +4949,7 @@ static constexpr OrtApi ort_api_1_to_29 = { &OrtApis::GetExperimentalFunction, &OrtApis::KernelContext_GetSyncStream, - // End of Version 28 - DO NOT MODIFY ABOVE (see above text for more information) + // End of Version 28 - DO NOT MODIFY ABOVE (see above text for more information) &OrtApis::SessionOptionsSetWeightlessSourceModelPath, &OrtApis::SessionOptionsSetWeightlessSourceModelFromBuffer, From c5ca19beb7c650796d71878bd164e592470fa782 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 9 Jul 2026 09:38:34 -0700 Subject: [PATCH 10/12] address reviewer's comments --- onnxruntime/core/session/onnxruntime_c_api.cc | 5 +++++ onnxruntime/core/session/ort_apis.h | 3 --- .../plugin_ep/ep_plugin_provider_interfaces.cc | 11 +---------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index a2afa2f190d69..27a356d49c87c 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -2765,6 +2766,10 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsSetWeightlessSourceModelPath, _Inout_ return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Invalid source model path: path is null or empty"); } + if (!std::filesystem::exists(source_model_path)) { + return OrtApis::CreateStatus(ORT_NO_SUCHFILE, "Weightless source model path does not exist"); + } + options->weightless_source_model_path = source_model_path; options->weightless_source_model_data = nullptr; options->weightless_source_model_data_size = 0; diff --git a/onnxruntime/core/session/ort_apis.h b/onnxruntime/core/session/ort_apis.h index 040e101ed0499..bec15a247d99f 100644 --- a/onnxruntime/core/session/ort_apis.h +++ b/onnxruntime/core/session/ort_apis.h @@ -829,9 +829,6 @@ ORT_API_STATUS_IMPL(GetTensorElementTypeAndShapeDataReference, _In_ const OrtVal // Experimental API ORT_API(OrtExperimentalFnPtr, GetExperimentalFunction, _In_ const char* name); -ORT_API_STATUS_IMPL(KernelContext_GetSyncStream, _In_ const OrtKernelContext* context, - _Outptr_result_maybenull_ OrtSyncStream** out); - // Weightless source model APIs ORT_API_STATUS_IMPL(SessionOptionsSetWeightlessSourceModelPath, _Inout_ OrtSessionOptions* options, _In_ const ORTCHAR_T* source_model_path); diff --git a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc index a82715bcaa726..662048e30eda2 100644 --- a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc +++ b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc @@ -412,20 +412,11 @@ PluginExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_vie // provided a single partition. Use utils::MakeCapability() and create a new helper to check that there are no // unsupported nodes in any path between supported nodes. - // When weightless mode is enabled, override drop_constant_initializers to false so that ORT keeps - // constant initializers as fused node inputs. The EP can then access them via KernelContext_GetInput(). - bool drop_constant_initializers = node_grouping.fusion_options.drop_constant_initializers; - if (weightless_enabled_ && drop_constant_initializers) { - LOGS(logger, INFO) << "Weightless mode enabled for " << Type() - << ": overriding drop_constant_initializers to false."; - drop_constant_initializers = false; - } - auto metadef_gen_functor = PluginEpMetaDefNameFunctor(metadef_id_generator_, graph_viewer, this->Type()); std::vector> capabilities = utils::CreateSupportedPartitions( graph_viewer, node_set, /*stop_ops*/ {}, std::move(metadef_gen_functor), this->Type(), this->Type(), /*node_unit_map*/ nullptr, - drop_constant_initializers); + node_grouping.fusion_options.drop_constant_initializers); if (capabilities.size() != 1) { LOGS(logger, ERROR) << "OrtEp::GetCapability() for " << Type() << " set nodes that cannot be fused together. " From 4ca3f3076039d53597129fe114df3dcae13a9622 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 9 Jul 2026 09:40:54 -0700 Subject: [PATCH 11/12] remove empty line --- .../core/session/plugin_ep/ep_plugin_provider_interfaces.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc index 662048e30eda2..d0c4c9fe89759 100644 --- a/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc +++ b/onnxruntime/core/session/plugin_ep/ep_plugin_provider_interfaces.cc @@ -411,7 +411,6 @@ PluginExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_vie // TODO(adrianlizarraga): Do not use the heavy-weight CreateSupportedPartitions just to check if the user // provided a single partition. Use utils::MakeCapability() and create a new helper to check that there are no // unsupported nodes in any path between supported nodes. - auto metadef_gen_functor = PluginEpMetaDefNameFunctor(metadef_id_generator_, graph_viewer, this->Type()); std::vector> capabilities = utils::CreateSupportedPartitions( graph_viewer, node_set, /*stop_ops*/ {}, std::move(metadef_gen_functor), From 218dba401bc102bad16b69a8cc0125ed46280c06 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Thu, 9 Jul 2026 14:16:55 -0700 Subject: [PATCH 12/12] address reviewer's comment --- .../core/session/model_package/model_package_context.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/session/model_package/model_package_context.cc b/onnxruntime/core/session/model_package/model_package_context.cc index 351ef2498dcd5..6a3eecd514fae 100644 --- a/onnxruntime/core/session/model_package/model_package_context.cc +++ b/onnxruntime/core/session/model_package/model_package_context.cc @@ -33,7 +33,8 @@ bool IsModelPackagePathSessionOption(std::string_view key) { // Session-option config keys whose values are path references (sha256:, relative, or // absolute) that must be resolved against the model package. Add new path-valued keys here. return key == kOrtSessionOptionsModelExternalInitializersFileFolderPath || - key == kOrtSessionOptionEpContextFilePath; + key == kOrtSessionOptionEpContextFilePath || + key == kOrtSessionOptionEpContextSourceModelPath; } namespace {