feat(ml): round-robin device assignment (#13237)

* round-robin device assignment

* docs and tests

clarify doc
This commit is contained in:
Mert 2024-10-07 17:37:45 -04:00 committed by GitHub
parent 063969ca05
commit bd826b0b9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 62 additions and 7 deletions

View file

@ -0,0 +1,12 @@
import os
from gunicorn.arbiter import Arbiter
from gunicorn.workers.base import Worker
device_ids = os.environ.get("MACHINE_LEARNING_DEVICE_IDS", "0").replace(" ", "").split(",")
env = os.environ
# Round-robin device assignment for each worker
def pre_fork(arbiter: Arbiter, _: Worker) -> None:
env["MACHINE_LEARNING_DEVICE_ID"] = device_ids[len(arbiter.WORKERS) % len(device_ids)]