@@ -174,22 +174,42 @@ inline std::unique_ptr<Module> load_module_from_buffer(
174174}
175175
176176inline  std::unique_ptr<Module> load_module_from_file (
177-     const  std::string& path,
177+     const  std::string& program_path,
178+     std::optional<const  std::string>& data_map_path,
178179    std::unique_ptr<runtime::EventTracer> event_tracer,
179180    Program::Verification program_verification) {
180181  EXECUTORCH_SCOPE_PROF (" load_module_from_file" 
181182
182-   Result<MmapDataLoader> res  = MmapDataLoader::from (
183-       path .c_str (), MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
183+   Result<MmapDataLoader> program_loader_res  = MmapDataLoader::from (
184+       program_path .c_str (), MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
184185  THROW_IF_ERROR (
185-       res .error (),
186+       program_loader_res .error (),
186187      " Failed to create MmapDataLoader from file %s, error: 0x:%" 
187-       path.c_str (),
188-       static_cast <uint32_t >(res.error ()));
189- 
190-   auto  loader = std::make_unique<MmapDataLoader>(std::move (res.get ()));
188+       program_path.c_str (),
189+       static_cast <uint32_t >(program_loader_res.error ()));
190+   auto  program_loader =
191+       std::make_unique<MmapDataLoader>(std::move (program_loader_res.get ()));
192+ 
193+   if  (data_map_path.has_value ()) {
194+     Result<MmapDataLoader> data_map_loader_res = MmapDataLoader::from (
195+         data_map_path->c_str (),
196+         MmapDataLoader::MlockConfig::UseMlockIgnoreErrors);
197+     THROW_IF_ERROR (
198+         data_map_loader_res.error (),
199+         " Failed to create MmapDataLoader from file %s, error: 0x:%" 
200+         data_map_path->c_str (),
201+         static_cast <uint32_t >(data_map_loader_res.error ()));
202+     auto  data_map_loader =
203+         std::make_unique<MmapDataLoader>(std::move (data_map_loader_res.get ()));
204+     return  std::make_unique<Module>(
205+         std::move (program_loader),
206+         nullptr , //  memory_allocator
207+         nullptr , //  temp_allocator
208+         std::move (event_tracer), //  event_tracer
209+         std::move (data_map_loader)); //  data_map_loader
210+   }
191211  return  std::make_unique<Module>(
192-       std::move (loader ),
212+       std::move (program_loader ),
193213      nullptr , //  memory_allocator
194214      nullptr , //  temp_allocator
195215      std::move (event_tracer), //  event_tracer
@@ -510,14 +530,16 @@ struct PyModule final {
510530            program_verification)) {}
511531
512532  explicit  PyModule (
513-       const  std::string& path,
533+       const  std::string& program_path,
534+       std::optional<const  std::string>& data_path,
514535      bool  enable_etdump,
515536      size_t  debug_buffer_size = 0 ,
516537      Program::Verification program_verification =
517538          Program::Verification::InternalConsistency)
518539      : debug_buffer_size_(debug_buffer_size),
519540        module_(load_module_from_file(
520-             path,
541+             program_path,
542+             data_path,
521543            setup_event_tracer (enable_etdump, debug_buffer_size),
522544            program_verification)) {}
523545
@@ -536,14 +558,20 @@ struct PyModule final {
536558    return  std::make_unique<PyModule>(
537559        buffer, enable_etdump, debug_buffer_size, program_verification);
538560  }
561+ 
539562  static  std::unique_ptr<PyModule> load_from_file (
540-       const  std::string& path,
563+       const  std::string& program_path,
564+       std::optional<const  std::string>& data_path,
541565      bool  enable_etdump,
542566      size_t  debug_buffer_size = 0 ,
543567      Program::Verification program_verification =
544568          Program::Verification::InternalConsistency) {
545569    return  std::make_unique<PyModule>(
546-         path, enable_etdump, debug_buffer_size, program_verification);
570+         program_path,
571+         data_path,
572+         enable_etdump,
573+         debug_buffer_size,
574+         program_verification);
547575  }
548576
549577  static  std::unique_ptr<PyModule> load_from_bundled_program (
@@ -1351,7 +1379,8 @@ PYBIND11_MODULE(EXECUTORCH_PYTHON_MODULE_NAME, m) {
13511379  m.def (
13521380      " _load_for_executorch" 
13531381      PyModule::load_from_file,
1354-       py::arg (" path" 
1382+       py::arg (" program_path" 
1383+       py::arg (" data_path" nullopt ,
13551384      py::arg (" enable_etdump" false ,
13561385      py::arg (" debug_buffer_size" 0 ,
13571386      py::arg (" program_verification" 
0 commit comments