Skip to content

Commit

Permalink
fix: fix bug with cuda devices in clip-nebullvm
Browse files Browse the repository at this point in the history
  • Loading branch information
morgoth95 committed May 10, 2022
1 parent f06133e commit f9ce0ae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/clip_server/model/clip_nebullvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,21 @@ class EnvRunner:
def __init__(self, device: str, num_threads: int = None):
self.device = device
self.cuda_str = None
self.rm_cuda_flag = False
self.num_threads = num_threads

def __enter__(self):
if self.device == "cpu" and torch.cuda.is_available():
self.cuda_str = os.environ.get("CUDA_VISIBLE_DEVICES") or "1"
self.cuda_str = os.environ.get("CUDA_VISIBLE_DEVICES")
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
self.rm_cuda_flag = self.cuda_str is None
if self.num_threads is not None:
os.environ["NEBULLVM_THREADS_PER_MODEL"] = f"{self.num_threads}"

def __exit__(self, exc_type, exc_val, exc_tb):
if self.cuda_str is not None:
os.environ["CUDA_VISIBLE_DEVICES"] = self.cuda_str
elif self.rm_cuda_flag:
os.environ.pop("CUDA_VISIBLE_DEVICES")
if self.num_threads is not None:
os.environ.pop("NEBULLVM_THREADS_PER_MODEL")

0 comments on commit f9ce0ae

Please sign in to comment.