code: def get_runnable(
      bento_model: bentoml.Model,
  ) -> type[bentoml.Runnable]:
      """
      Private API: use :obj:`~bentoml.Model.to_runnable` instead.
      """
  
      is_predictor = bento_model.info.metadata.get(
          "_is_predictor", True
      )
      partial_kwargs = t.cast(
          ModelOptions, bento_model.info.options
      ).partial_kwargs
  
      class Detectron2Runnable(bentoml.Runnable):
          SUPPORTED_RESOURCES = ("nvidia.com/gpu", "cpu")
          SUPPORTS_CPU_MULTI_THREADING = True
  
          def __init__(self):
              super().__init__()
              if torch.cuda.is_available():
                  self.device_id = "cuda"
                  torch.set_default_tensor_type(
                      "torch.cuda.FloatTensor"
                  )
              else:
                  self.device_id = "cpu"
  
              self.model = load_model(
                  bento_model, device_id=self.device_id
              )
  
              if not is_predictor:
                  assert isinstance(self.model, torch.nn.Module)
                  # This predictor is a torch.nn.Module
                  self.model.train(False)
  
              self.is_predictor = is_predictor
  
              self.predict_fns: dict[str, t.Callable[..., t.Any]] = {}
              for method_name in bento_model.info.signatures:
                  self.predict_fns[method_name] = getattr(
                      self.model, method_name
                  )
  
      def add_runnable_method(
          method_name: str, options: ModelSignature
      ):
          def _run(
              self: Detectron2Runnable, *args: t.Any, **kwargs: t.Any
          ) -> t.Any:
              method_partial_kwargs = partial_kwargs.get(
                  method_name, {}
              )
  
              params = Params(*args, **kwargs)
  
              if self.is_predictor:
                  return self.predict_fns[method_name](
                      *params.args,
                      **dict(method_partial_kwargs, **params.kwargs),
                  )
  
              def mapping(item: ext.NpNDArray | torch.Tensor) -> t.Any:
                  if LazyType["ext.NpNDArray"](
                      "numpy.ndarray"
                  ).isinstance(item):
                      return torch.Tensor(item, device=self.device_id)
                  elif isinstance(item, torch.Tensor):
                      return item.to(self.device_id)
                  else:
                      return item
  
              with inference_mode_ctx():
                  params = params.map(mapping)
                  return self.predict_fns[method_name](
                      [{"image": image} for image in params.args],
                      **dict(method_partial_kwargs, **params.kwargs),
                  )
  
          Detectron2Runnable.add_method(
              _run,
              name=method_name,
              batchable=options.batchable,
              batch_dim=options.batch_dim,
              input_spec=options.input_spec,
              output_spec=options.output_spec,
          )
  
      for method_name, options in bento_model.info.signatures.items():
          add_runnable_method(method_name, options)
  
      return Detectron2Runnable
  
imports: from __future__ import annotations
  import logging
  import typing
  from types import ModuleType
  import bentoml
  from ...exceptions import MissingDependencyException
  from ...exceptions import NotFound
  from ..models.model import Model
  from ..models.model import ModelContext
  from ..models.model import ModelSignature
  from ..models.model import PartialKwargsModelOptions
  from ..runner.utils import Params
  from ..tag import Tag
  from ..types import LazyType
  from ..utils import LazyLoader
  from ..utils.pkg import get_pkg_version
  from .common.pytorch import PyTorchTensorContainer
  from .common.pytorch import inference_mode_ctx
  from .common.pytorch import torch
label_desc: Use image node_id 4 for calling a global function with example usage: get_runnable(bento_model) and returns: Detectron2Runnable, self, self, torch, item, item