def get_runnable(bento_model: bentoml.Model) -> type[bentoml.Runnable]:
    """
    Private API: use :obj:`~bentoml.Model.to_runnable` instead.
    """

    class TransformersRunnable(bentoml.Runnable):
        SUPPORTED_RESOURCES = ("nvidia.com/gpu", "cpu")
        SUPPORTS_CPU_MULTI_THREADING = True

        def __init__(self):
            super().__init__()

            available_gpus = os.getenv("CUDA_VISIBLE_DEVICES", "")
            # assign CPU resources
            kwargs = {}

            if available_gpus not in ("", "-1"):
                # assign GPU resources
                if not available_gpus.isdigit():
                    raise ValueError(
                        f"Expecting numeric value for CUDA_VISIBLE_DEVICES, got {available_gpus}."
                    )
                if "_pretrained_class" not in bento_model.info.metadata:
                    # NOTE: then this is a pipeline. We then pass the device to it.
                    kwargs["device"] = int(available_gpus)
            if "_pretrained_class" not in bento_model.info.metadata:
                self.model = load_model(bento_model, **kwargs)
            else:
                if "_framework" in bento_model.info.metadata:
                    if (
                        "torch" == bento_model.info.metadata["_framework"]
                        or "pt" == bento_model.info.metadata["_framework"]
                    ):
                        self.model = t.cast(
                            transformers.PreTrainedModel,
                            load_model(bento_model, **kwargs),
                        ).to(
                            torch.device(
                                "cuda" if available_gpus not in ("", "-1") else "cpu"
                            )
                        )
                        torch.set_default_tensor_type("torch.cuda.FloatTensor")
                    elif "tf" == bento_model.info.metadata["_framework"]:
                        with tf.device(
                            "/device:CPU:0"
                            if available_gpus in ("", "-1")
                            else f"/device:GPU:{available_gpus}"
                        ):
                            self.model = t.cast(
                                transformers.TFPreTrainedModel,
                                load_model(bento_model, **kwargs),
                            )
                    else:
                        # NOTE: we need to hide all GPU from TensorFlow, otherwise it will try to allocate
                        # memory on the GPU and make it unavailable for JAX.
                        tf.config.experimental.set_visible_devices([], "GPU")
                        self.model = t.cast(
                            transformers.FlaxPreTrainedModel,
                            load_model(bento_model, **kwargs),
                        )
                else:
                    logger.warning(
                        "Current %s is saved with an older version of BentoML. Setting GPUs on this won't work as expected. Make sure to save it with a newer version of BentoML.",
                        bento_model,
                    )
                    self.model = load_model(bento_model, **kwargs)

            # NOTE: backward compatibility with previous BentoML versions.
            self.pipeline = self.model

            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: TransformersRunnable, *args: t.Any, **kwargs: t.Any) -> t.Any:
            return self.predict_fns[method_name](*args, **kwargs)

        TransformersRunnable.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 TransformersRunnable
Private API: use :obj:`~bentoml.Model.to_runnable` instead.
src/bentoml/_internal/frameworks/transformers.py