determine num gpus in python

This commit is contained in:
Eugene Klitenik
2025-10-29 11:31:42 -04:00
parent 5c4edd15cc
commit 1ee18d06a9
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -52,5 +52,5 @@ RUN mkdir -p /usr/local/bin
COPY --chmod=755 start.sh /usr/local/bin/start.sh
# Start the handler
ENTRYPOINT ["/bin/bash", "/usr/local/bin/start.sh"]
#ENTRYPOINT ["/bin/bash", "/usr/local/bin/start.sh"]
CMD ["python3", "/src/handler.py"]
+14
View File
@@ -3,6 +3,20 @@ import runpod
from utils import JobInput
from engine import vLLMEngine, OpenAIvLLMEngine
# Detect number of visible GPUs
gpu_count = torch.cuda.device_count()
# Fallback to 1 if none detected
if gpu_count < 1:
gpu_count = 1
# Set the environment variable
os.environ["TENSOR_PARALLEL_SIZE"] = str(gpu_count)
print(f"Detected {gpu_count} GPU(s)")
print(f"Set TENSOR_PARALLEL_SIZE={os.environ['TENSOR_PARALLEL_SIZE']}")
vllm_engine = vLLMEngine()
OpenAIvLLMEngine = OpenAIvLLMEngine(vllm_engine)