GPU fleet lifecycle for inference
Turning GPU instances on and off to match actual demand instead of running them continuously — coordinated safely across concurrent processes, in service of a pipeline that was built to be low-cost by design.
Problem
The video pipeline combined third-party APIs (SyncLabs, ElevenLabs) with self-hosted open-source models that needed GPU compute — LatentSync for lip-sync, Bhashini for voice, and other Hugging-Face-hosted models. Generation demand was bursty and unpredictable, which put GPU cost in tension with itself: running instances continuously to always be ready is wasteful against idle time, but cold-starting one on every request is too slow. This part of the stack was built to be isolated and low-cost, so neither option was acceptable as-is.
Constraints
- Budget-sensitive by design — GPU spend was never meant to be a fixed cost accepted without question.
- GPU spend needed to track actual demand, not sit idle waiting for the next request.
- Multiple processes could try to start or stop the same instance at the same time; lifecycle changes needed safe coordination, not a race between them.
- Transient inference failures needed retries that didn't take down the whole pipeline job over one bad call.
- Once an instance was up, it needed to be used efficiently — maximizing work completed per paid GPU-hour, not just latency on any single call.
What I built
IAM-scoped roles paired with the boto3 EC2 SDK to programmatically start and stop GPU instances on demand, rather than leaving them running continuously. Because more than one process could reasonably want to change an instance's state at once, I built an async mechanism guarded by Redis locks, so processes coordinate instance lifecycle safely instead of two of them racing to start or stop the same instance. Once instances were running, requests were batched and executed with tensor parallelization and caching to maximize concurrency and throughput, using Hugging Face APIs for the open-source models, and retries absorbed transient inference failures without failing the whole job.
The trade-off
Distributed locking and async coordination between processes was the real cost here: every GPU start or stop had to clear a Redis lock first, because two processes reaching for the same instance at the same time was a real possibility, not a hypothetical edge case. That coordination code is complexity that always-on infrastructure would never have needed, but a pipeline built around bursty, unpredictable demand needed GPU spend that tracked actual usage, not a fixed idle cost sitting underneath it by default.
Outcome
On-demand start/stop via boto3 and IAM meant GPU instances only ran while there was work for them to do, with Redis locks keeping that lifecycle safe whenever more than one process reached for the same instance at once. It's one piece of the platform designed to sustain 2,000+ pipeline-based video generations a day for Indira IVF, platform-wide.