code: def get_runnable(
      bento_model: bentoml.Model,
  ) -> t.Type[bentoml.Runnable]:
      """
      Private API: use :obj:`~bentoml.Model.to_runnable` instead.
      """
  
      bento_options = t.cast(DiffusersOptions, bento_model.info.options)
      partial_kwargs: dict[str, t.Any] = bento_options.partial_kwargs  # type: ignore
      pipeline_class: str | type[diffusers.DiffusionPipeline] = (
          bento_options.pipeline_class or diffusers.DiffusionPipeline
      )
      if isinstance(pipeline_class, str):
          pipeline_class = t.cast(
              type[diffusers.DiffusionPipeline],
              _str2cls(pipeline_class),
          )
  
      scheduler_class: str | type[
          diffusers.SchedulerMixin
      ] | None = bento_options.scheduler_class
  
      if scheduler_class and isinstance(scheduler_class, str):
          scheduler_class = t.cast(
              type[diffusers.SchedulerMixin], _str2cls(scheduler_class)
          )
  
      custom_pipeline: str | None = bento_options.custom_pipeline
      _enable_xformers: bool | None = bento_options.enable_xformers
      enable_attention_slicing: int | str | None = (
          bento_options.enable_attention_slicing
      )
      enable_sequential_cpu_offload: bool | None = (
          bento_options.enable_sequential_cpu_offload
      )
      enable_model_cpu_offload: bool | None = (
          bento_options.enable_model_cpu_offload
      )
      enable_torch_compile: bool | None = (
          bento_options.enable_torch_compile
      )
      low_cpu_mem_usage: bool | None = bento_options.low_cpu_mem_usage
      variant: str | None = bento_options.variant
      _torch_dtype: str | torch.dtype | None = bento_options.torch_dtype
      device_map: str | dict[
          str, int | str | torch.device
      ] | None = bento_options.device_map
      load_pretrained_extra_kwargs = (
          bento_options.load_pretrained_extra_kwargs
      )
  
      support_lora = (
          True if issubclass(pipeline_class, LoraLoaderMixin) else False
      )
      support_textual_inversion = (
          True
          if issubclass(pipeline_class, TextualInversionLoaderMixin)
          else False
      )
  
      lora_dir = bento_options.lora_dir
      lora_weights = bento_options.lora_weights
      textual_inversions = bento_options.textual_inversions
  
      if not support_lora and lora_weights:
          raise NotImplementedError(
              f"Class {pipeline_class} is not a subclass of LoraLoaderMixin, cannot load lora weights. "
              "Try using `bento_model.with_options(pipeline_class=diffusers.StableDiffusionPipeline) to specify the pipeline's class"
          )
  
      if not support_textual_inversion and textual_inversions:
          raise NotImplementedError(
              f"Class {pipeline_class} is not a subclass of TextualInversionLoaderMixin, cannot load textual inversions"
              "Try using `bento_model.with_options(pipeline_class=diffusers.StableDiffusionPipeline) to specify the pipeline's class"
          )
  
      class DiffusersRunnable(bentoml.Runnable):
          SUPPORTED_RESOURCES = ("nvidia.com/gpu", "cpu")
          SUPPORTS_CPU_MULTI_THREADING = True
  
          def __init__(self):
              super().__init__()
  
              if torch.cuda.is_available() and _torch_dtype is None:
                  torch_dtype = torch.float16
              else:
                  torch_dtype = _torch_dtype
  
              enable_xformers: bool = False
              if torch.cuda.is_available() and _enable_xformers is None:
                  if is_xformers_available():
                      enable_xformers: bool = True
  
              device_id: str | None = None
              if torch.cuda.is_available():
                  device_id = "cuda"
  
              self.lora_dir = lora_dir
  
              self.pipeline: diffusers.DiffusionPipeline = load_model(
                  bento_model,
                  device_id=device_id,
                  device_map=device_map,
                  pipeline_class=pipeline_class,
                  scheduler_class=scheduler_class,
                  torch_dtype=torch_dtype,
                  custom_pipeline=custom_pipeline,
                  enable_xformers=enable_xformers,
                  enable_attention_slicing=enable_attention_slicing,
                  enable_sequential_cpu_offload=enable_sequential_cpu_offload,
                  enable_model_cpu_offload=enable_model_cpu_offload,
                  enable_torch_compile=enable_torch_compile,
                  low_cpu_mem_usage=low_cpu_mem_usage,
                  variant=variant,
                  lora_weights=lora_weights,
                  textual_inversions=textual_inversions,
                  load_pretrained_extra_kwargs=load_pretrained_extra_kwargs,
              )
  
          @bentoml.Runnable.method(batchable=False)
          def _replace_scheduler(self, scheduler_txt: str):
              try:
                  scheduler_cls = _str2cls(scheduler_txt)
                  if isinstance(self.pipeline.scheduler, scheduler_cls):
                      return dict(success=True)
                  if (
                      scheduler_cls
                      in self.pipeline.scheduler.compatibles
                  ):
                      self.pipeline.scheduler = (
                          scheduler_cls.from_config(
                              self.pipeline.scheduler.config,
                          )
                      )
                      return dict(success=True)
                  else:
                      return dict(
                          success=False,
                          error_message="scheduler class is incompatible to this pipeline",
                      )
  
              except (ModuleNotFoundError, ValueError, AttributeError):
                  logger.info(f"Cannot import {scheduler_txt}")
                  return dict(
                      success=False,
                      error_message="cannot import scheduler class",
                  )
  
      if support_lora:
  
          def _load_lora_weights(
              self: DiffusersRunnable,
              lora_weights: LoraOptionType | list[LoraOptionType],
          ):
              _load_lora_weights_to_pipeline(
                  self.pipeline, lora_weights, self.lora_dir
              )
  
          def _unload_lora_weights(
              self: DiffusersRunnable,
          ):
              self.pipeline.unload_lora_weights()
  
              # clear cached lora weights from GPU memory
              torch.cuda.empty_cache()
  
      else:
  
          def _load_lora_weights(
              self: DiffusersRunnable,
              lora_args: LoraOptionType | list[LoraOptionType],
          ):
              raise NotImplementedError(
                  f"Class {pipeline_class} is not a subclass of LoraLoaderMixin, cannot load lora weights"
              )
  
          def _unload_lora_weights(
              self: DiffusersRunnable,
          ):
              raise NotImplementedError(
                  f"Class {pipeline_class} is not a subclass of LoraLoaderMixin, cannot unload lora weights"
              )
  
      setattr(
          DiffusersRunnable, "_load_lora_weights", _load_lora_weights
      )
      setattr(
          DiffusersRunnable,
          "_unload_lora_weights",
          _unload_lora_weights,
      )
  
      def make_run_method(
          method_name: str, partial_kwargs: dict[str, t.Any] | None
      ) -> t.Callable[..., t.Any]:
          if support_lora:
  
              def _run_method(
                  runnable_self: DiffusersRunnable,
                  *args: t.Any,
                  **kwargs: t.Any,
              ) -> t.Any:
                  if method_partial_kwargs is not None:
                      kwargs = dict(method_partial_kwargs, **kwargs)
  
                  lora_weights: str | None = kwargs.pop(
                      "lora_weights", None
                  )
  
                  try:
                      if lora_weights is not None:
                          runnable_self._load_lora_weights(lora_weights)
  
                      raw_method = getattr(
                          runnable_self.pipeline, method_name
                      )
                      res = raw_method(*args, **kwargs)
  
                  finally:
                      torch.cuda.empty_cache()
                      if lora_weights is not None:
                          runnable_self._unload_lora_weights()
  
                  # handle BaseOutput cannot be serialized yet
                  if isinstance(res, diffusers.utils.BaseOutput):
                      res = res.to_tuple()
  
                  return res
  
          else:
  
              def _run_method(
                  runnable_self: DiffusersRunnable,
                  *args: t.Any,
                  **kwargs: t.Any,
              ) -> t.Any:
                  if method_partial_kwargs is not None:
                      kwargs = dict(method_partial_kwargs, **kwargs)
  
                  raw_method = getattr(
                      runnable_self.pipeline, method_name
                  )
                  res = raw_method(*args, **kwargs)
  
                  # handle BaseOutput cannot be serialized yet
                  if isinstance(res, diffusers.utils.BaseOutput):
                      res = res.to_tuple()
  
                  return res
  
          return _run_method
  
      for method_name, options in bento_model.info.signatures.items():
          method_partial_kwargs = partial_kwargs.get(method_name)
          DiffusersRunnable.add_method(
              make_run_method(method_name, method_partial_kwargs),
              name=method_name,
              batchable=options.batchable,
              batch_dim=options.batch_dim,
              input_spec=options.input_spec,
              output_spec=options.output_spec,
          )
  
      return DiffusersRunnable
  
imports: from __future__ import annotations
  import logging
  import os
  import shutil
  import typing
  from typing import TYPE_CHECKING
  import attr
  import bentoml
  from bentoml import Tag
  from bentoml.exceptions import BentoMLException
  from bentoml.exceptions import MissingDependencyException
  from bentoml.exceptions import NotFound
  from bentoml.models import ModelContext
  from ..models.model import PartialKwargsModelOptions
  from .utils.transformers import extract_commit_hash
label_desc: Use image node_id 9 for calling a global function with example usage: get_runnable(bento_model) and returns: DiffusersRunnable, _run_method, res, res, dict, dict, dict, dict