Skip to content

Commit

Permalink
feat: allow disabling GPU allocation via env (#4453)
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Jan 30, 2024
1 parent 5ebf28e commit 5713dab
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/_bentoml_impl/server/allocator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
import warnings
from typing import Any

Expand All @@ -12,6 +13,7 @@
from bentoml.exceptions import BentoMLConfigException

NVIDIA_GPU = "nvidia.com/gpu"
DISABLE_GPU_ALLOCATION_ENV = "BENTOML_DISABLE_GPU_ALLOCATION"


class ResourceAllocator:
Expand All @@ -26,7 +28,9 @@ def __init__(self) -> None:
def assign_gpus(self, count: float) -> list[int]:
if count > self.remaining_gpus:
warnings.warn(
f"Requested {count} GPUs, but only {self.remaining_gpus} are remaining.",
f"Requested {count} GPUs, but only {self.remaining_gpus} are remaining. "
f"Serving may fail due to inadequate GPUs. Set {DISABLE_GPU_ALLOCATION_ENV}=1 "
"to disable automatic allocation and allocate GPUs manually.",
ResourceWarning,
stacklevel=3,
)
Expand Down Expand Up @@ -97,7 +101,7 @@ def get_worker_env(
return num_workers, worker_env
else: # workers is a number
num_workers = workers
if num_gpus:
if num_gpus and DISABLE_GPU_ALLOCATION_ENV not in os.environ:
assigned = self.assign_gpus(num_gpus)
# assign gpus to all workers
worker_env = [
Expand Down

0 comments on commit 5713dab

Please sign in to comment.