Skip to content

Commit 7da959d

Browse files
authored
fix: disable GPU allocation if CUDA_VISIBLE_DEVICES is set (#5368)
* fix: disable GPU allocation if CUDA_VISIBLE_DEVICES is set Signed-off-by: Frost Ming <me@frostming.com> * fix: onnx tests Signed-off-by: Frost Ming <me@frostming.com>
1 parent 3ede80c commit 7da959d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
"keras": ["keras>=3.4"],
3030
"lightgbm": ["lightgbm"],
31-
"onnx": ["onnx", "onnxruntime", "skl2onnx"],
31+
"onnx": ["onnx==1.17.0", "onnxruntime", "skl2onnx"],
3232
"picklable_model": [],
3333
"pytorch": [],
3434
"pytorch_lightning": ["lightning"],

src/_bentoml_impl/server/allocator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ def __init__(self) -> None:
2525
for _ in range(self.remaining_gpus)
2626
]
2727

28+
@staticmethod
29+
def gpu_allocation_disabled() -> bool:
30+
return (
31+
DISABLE_GPU_ALLOCATION_ENV in os.environ
32+
or "CUDA_VISIBLE_DEVICES" in os.environ
33+
)
34+
2835
def assign_gpus(self, count: float) -> list[int]:
2936
if count > self.remaining_gpus:
3037
warnings.warn(
@@ -101,7 +108,7 @@ def get_worker_env(
101108
return num_workers, worker_env
102109
else: # workers is a number
103110
num_workers = workers
104-
if num_gpus and DISABLE_GPU_ALLOCATION_ENV not in os.environ:
111+
if num_gpus and not self.gpu_allocation_disabled():
105112
assigned = self.assign_gpus(num_gpus)
106113
# assign gpus to all workers
107114
worker_env = [

0 commit comments

Comments
 (0)