This message was deleted.
# ask-for-help
s
This message was deleted.
d
Looks like this works and turns threading off. In case someone finds this message via slack search, something like this should also work, based on an earlier thread here:
Copy code
from bentoml._internal.runner.strategy import Strategy
from bentoml._internal.runner.runnable import Runnable
import typing as t


class SingleThreadStrategy(Strategy):
    @classmethod
    def get_worker_count(
        cls,
        runnable_class: t.Type[Runnable],
        resource_request: dict[str, t.Any],
    ) -> int:
        return 1

    @classmethod
    def get_worker_env(
        cls,
        runnable_class: t.Type[Runnable],
        resource_request: dict[str, t.Any],
        worker_index: int,
    ) -> dict[str, t.Any]:
        return {
            "BENTOML_NUM_THREAD": 1,
            "OMP_NUM_THREADS": 1,  # openmp
            "OPENBLAS_NUM_THREADS": 1,  # openblas,
            "MKL_NUM_THREADS": 1,  # mkl,
            "VECLIB_MAXIMUM_THREADS": 1,  # accelerate,
            "NUMEXPR_NUM_THREADS": 1,  # numexpr
            "RAYON_RS_NUM_CPUS": 1,
            "TF_NUM_INTEROP_THREADS": 1,
            "TF_NUM_INTRAOP_THREADS": 1,

model_runner = bentoml.Runner(bentoml.sklearn.get(m.tag).to_runnable(), scheduling_strategy=SingleThreadStrategy)
🔥 1