diff --git a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc index eba0a8c2615aa..3f2ceb0f3d417 100644 --- a/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc +++ b/onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc @@ -1367,7 +1367,8 @@ Status QnnBackendManager::LoadCachedQnnContextFromBuffer(char* buffer, uint64_t void* bin_buffer = nullptr; #ifdef QNN_FILE_MAPPED_WEIGHTS_AVAILABLE - if (file_mapped_weights_enabled_) { + // A nonzero buffer length implies an embedded context + if (file_mapped_weights_enabled_ && buffer_length == 0) { ORT_RETURN_IF(!file_mapper_, "Attemping to use File Mapping feature but file_mapper_ is uninitialized"); ORT_RETURN_IF_ERROR(GetFileSizeIfValid(context_bin_filepath, buffer_length)); diff --git a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc index 7d9de02654230..6be50ac4da5c3 100644 --- a/onnxruntime/core/providers/qnn/qnn_execution_provider.cc +++ b/onnxruntime/core/providers/qnn/qnn_execution_provider.cc @@ -488,6 +488,11 @@ QNNExecutionProvider::QNNExecutionProvider(const ProviderOptions& provider_optio enable_file_mapped_weights_ = false; LOGS_DEFAULT(WARNING) << "File mapped weights feature is only available on Windows arm64 devices for QNN API versions >= 2.32. " << "Feature will be disabled by default"; +#else + if (qnn_context_embed_mode_ && enable_file_mapped_weights_) { + enable_file_mapped_weights_ = false; + LOGS_DEFAULT(WARNING) << "File mapped weights feature is incompatible with embedded EP contexts. Feature will be disabled by default."; + } #endif static const std::string QNN_DEVICE_ID = "device_id";