Repository navigation
gpu_startup_lock.sh: opt-in free-memory gate (GPU_STARTUP_MIN_FREE_GB) - #84
Conversation
With GPU_STARTUP_MIN_FREE_GB=n the script takes the start-up lock, reads the GPU's free memory from nvidia-smi and runs the command only if at least n GiB are free; otherwise it releases the lock, waits GPU_STARTUP_RETRY_WAIT seconds (default 60) and retries up to GPU_STARTUP_TRIES times (default 30), then exits 75 without running the command. Unset, the script still execs flock -o as before. The lock descriptor is closed for the command, so a background server never holds it. CPU tests fake nvidia-smi on PATH.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Verdict: APPROVE Reviewed head dd97139, one commit on main 36db481. Codex finished on dd97139 with no findings. (1) The unset path behaves exactly as before. I put a fake (2) On the gated path, the command does not get the lock.
(3) Exit codes.
Run here.
The commit is Sam's, with no AI attribution. Deployment note, as the author says: jobs execute this script while they run, so update |
Shared GPU jobs that start SGLang servers can leave each other too little memory. SGLang sizes its pools as roughly
--mem-fraction-statictimes the free memory it sees at start-up, minus the weights. At 04:11 a DFlash server at 0.25 found 0.46 GB for its pools while five shared holders were running, and it exited ("Not enough GPU memory for hybrid (mamba/linear-attention) state cache"). Kernel's dflash_check failed the same way.This PR adds an opt-in free-memory gate to
scripts/gpu_startup_lock.sh:GPU_STARTUP_MIN_FREE_GB=n: take the start-up lock and read the free memory of GPUGPU_STARTUP_GPU(default 0) fromnvidia-smi. If at least n GiB are free, run the command while holding the lock. Otherwise release the lock, waitGPU_STARTUP_RETRY_WAITseconds (default 60) and try again, up toGPU_STARTUP_TRIEStimes (default 30). When the tries run out, exit 75 without running the command. Each retry is logged to stderr. An unreadablenvidia-smivalue counts as too little memory, and invalid settings exit 64.exec flock -o ...as before.{fd}>&-), so a background server never holds it, and the lock is released explicitly once the command returns.Tests:
tests/test_gpu_startup_lock.py(CPU only, withnvidia-smifaked onPATH), 12 cases. They cover: the unset path, including exit-status pass-through and no memory query; a gate that passes; a gate that gives up after N tries without running the command; retries until memory frees; a fractional threshold; an unreadable value; invalid settings; the lock being held during the command and not inherited by a background child, checked through/proc/<pid>/fd(the test fails if{fd}>&-is removed); and a lock-wait timeout exiting 75 on both paths.pre-commitis clean, including shellcheck. The script header gives a dry run (GPU_STARTUP_MIN_FREE_GB=40 GPU_STARTUP_TRIES=1 scripts/gpu_startup_lock.sh nvidia-smi --query-gpu=memory.free --format=csv), which printed 52,156 MiB free and exited 0 here.Deployment: jobs execute this script while they run. A
gitcheckout or merge replaces the file with a new inode, so a running bash keeps reading the old one. Any manual update should also write a temporary file andmvit into place, never edit in place.First user:
experiments/drafter/serve_run.pyondrafter/buffered-verify(778bb23) now takes the start-up lock through this script, with--min-free-gbsetting the variable. That change goes in through the buffered-verify PR, not this one. The coordinator will add the variable to BRIEF.md once this merges.