Slackbot
10/13/2022, 2:16 PMDominik Müller
10/13/2022, 3:39 PMfrom 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)