diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index f09af8ac2e7..b7cd7fa8d12 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -805,6 +805,15 @@ Error Method::init( pte_data_map = pte_data_map_res.get(); } + ET_CHECK_OR_RETURN_ERROR( + !(pte_data_map && named_data_map), + NotSupported, + "NamedDataMap merge not supported; both pte_data_map and named_data_map are non-empty. If you see this error please file an issue at https://github.com/pytorch/executorch/issues"); + + if (!named_data_map || named_data_map->get_num_keys().get() == 0) { + named_data_map = pte_data_map; + } + // n_delegate_ counts the number of successfully-initialized delegates for // ~Method() to clean up, and is incremented at the bottom of the loop. This // makes it safe for errors to return without updating any state. @@ -816,7 +825,7 @@ Error Method::init( method_allocator, /*event_tracer=*/event_tracer_, /*method_name=*/serialization_plan_->name()->c_str(), - /*named_data_map=*/pte_data_map); + /*named_data_map=*/named_data_map); Error err = BackendDelegate::Init( delegate, program_, backend_init_context, &delegates_[i]); if (err != Error::Ok) {