@@ -82,9 +82,10 @@ Stub::Instantiate(
8282    const  std::string& shm_region_name, const  std::string& model_path,
8383    const  std::string& model_version, const  std::string& triton_install_path,
8484    bi::managed_external_buffer::handle_t  ipc_control_handle,
85-     const  std::string& name, const  std::string& platform )
85+     const  std::string& name, const  std::string& python_runtime_model )
8686{
87-   model_context_.Init (model_path, platform, triton_install_path, model_version);
87+   model_context_.Init (
88+       model_path, python_runtime_model, triton_install_path, model_version);
8889  name_ = name;
8990  health_mutex_ = nullptr ;
9091  initialized_ = false ;
@@ -1659,57 +1660,29 @@ PYBIND11_EMBEDDED_MODULE(c_python_backend_utils, module)
16591660
16601661void 
16611662ModelContext::Init (
1662-     const  std::string& model_path, const  std::string& platform ,
1663+     const  std::string& model_path, const  std::string& runtime_modeldir ,
16631664    const  std::string& triton_install_path, const  std::string& model_version)
16641665{
1665-   bool  python_model_found = false ;
1666-   std::string platform_model_path;
1667- 
1668-   if  (platform != " NONE" 
1669-     platform_model_path =
1670-         triton_install_path + " /platform_handlers/" " /model.py" 
1671-     //  Check if model file exists in the path.
1672-     struct  stat  buffer;
1673-     if  (stat (platform_model_path.c_str (), &buffer) == 0 ) {
1674-       //  Use the Platform model for serving the model.
1675-       python_model_found = true ;
1676-       type_ = ModelType::PLATFORM;
1677-       python_model_path_ = platform_model_path;
1678-       //  Trimming the model name from the model path, the platform model
1679-       //  will populate the expected default model file name into model_path_.
1680-       model_dir_ = model_path.substr (0 , model_path.find_last_of (" \\ /" 
1681-     } else  {
1682-       LOG_WARN << " Unable to find model(handler) \' " 
1683-                << " \'  for platform field \' " " \' " 
1684-     }
1685-   }
1686- 
1687-   if  (!python_model_found) {
1666+   type_ = ModelType::DEFAULT;
1667+   if  (runtime_modeldir != " DEFAULT" 
1668+     //  For python based backends, existence of `model.py` in the corresponding
1669+     //  backend folder happens on the core side, so we can omit this check here.
1670+     python_model_path_ = runtime_modeldir + " /model.py" 
1671+     type_ = ModelType::BACKEND;
1672+   } else  {
16881673    python_model_path_ = model_path;
16891674    //  Check if model file exists in this path.
16901675    struct  stat  buffer;
1691-     if  (stat (python_model_path_.c_str (), &buffer) == 0 ) {
1692-       python_model_found = true ;
1693-       type_ = ModelType::DEFAULT;
1694-     }
1695-     //  Initializing here for consistency with platform model case.
1696-     model_dir_ = model_path.substr (0 , model_path.find_last_of (" \\ /" 
1697-   }
1698- 
1699-   if  (!python_model_found) {
1700-     if  (platform != " NONE" 
1701-       throw  PythonBackendException (
1702-           (" Python model file not found in neither \' " 
1703-            " \'  nor \' " " \' " 
1704-     } else  {
1676+     if  (stat (python_model_path_.c_str (), &buffer) != 0 ) {
17051677      throw  PythonBackendException (
17061678          (" Python model file not found in \' " " \' " 
17071679    }
17081680  }
17091681
1682+   model_dir_ = model_path.substr (0 , model_path.find_last_of (" \\ /" 
17101683  python_backend_folder_ = triton_install_path;
17111684  model_version_ = model_version;
1712-   platform_  = platform ;
1685+   runtime_modeldir_  = runtime_modeldir ;
17131686}
17141687
17151688void 
@@ -1740,9 +1713,10 @@ ModelContext::StubSetup(py::module& sys)
17401713    sys = py::module_::import (
17411714        (std::string (model_version_) + " ." c_str ());
17421715  } else  {
1743-     std::string platform_model_dir (
1744-         python_backend_folder_ + " /platform_handlers/" " /" 
1745-     sys.attr (" path" attr (" append" 
1716+     std::string model_path_parent =
1717+         python_model_path_.substr (0 , python_model_path_.find_last_of (" /" 
1718+     std::string backend_model_dir (model_path_parent);
1719+     sys.attr (" path" attr (" append" 
17461720    sys.attr (" path" attr (" append" 
17471721    sys = py::module_::import (model_name_trimmed.c_str ());
17481722  }
@@ -1791,14 +1765,14 @@ main(int argc, char** argv)
17911765  int64_t  shm_growth_size = std::stol (argv[4 ]);
17921766  std::string triton_install_path = argv[6 ];
17931767  std::string name = argv[8 ];
1794-   std::string platform  = argv[9 ];
1768+   std::string runtime_modeldir  = argv[9 ];
17951769
17961770  std::unique_ptr<Stub>& stub = Stub::GetOrCreateInstance ();
17971771  try  {
17981772    stub->Instantiate (
17991773        shm_growth_size, shm_default_size, shm_region_name, model_path,
18001774        model_version, argv[6 ] /*  triton install path */ 
1801-         std::stoi (argv[7 ]) /*  IPCControl handle */ platform );
1775+         std::stoi (argv[7 ]) /*  IPCControl handle */ runtime_modeldir );
18021776  }
18031777  catch  (const  PythonBackendException& pb_exception) {
18041778    LOG_INFO << " Failed to preinitialize Python stub: " what ();
0 commit comments