docs(examples/server): add health-check trap when switching to background load#13558
Open
NazarKozak wants to merge 1 commit intohuggingface:mainfrom
Open
docs(examples/server): add health-check trap when switching to background load#13558NazarKozak wants to merge 1 commit intohuggingface:mainfrom
NazarKozak wants to merge 1 commit intohuggingface:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a "Production deployment notes" section to
examples/server/README.mdcovering one of the easier traps to fall into when adapting the example for orchestrated production environments (Kubernetes, Cloud Run, Vertex AI, AWS Fargate).Why
The shipped
examples/server/server.pyloads the pipeline synchronously at module import, beforeuvicorn.run(...)binds the HTTP port. That is the safe default — the orchestrator's readiness probe naturally fails (connection refused) until the model is on GPU. No health-check work is required.The trouble starts when users adapt the example for cold-start–sensitive deployments of large pipelines (SD3, FLUX.2, etc.) where the orchestrator's startup probe times out before
from_pretrainedreturns. The natural fix is to spawn the load on a background thread and bind the port immediately, which moves the readiness signal to/health. At that point a route likereturn {"status": "ok"}will return200 OKfrom the moment the process starts, the orchestrator marks the replica ready, and traffic gets routed to a replica that hasn't loaded the model yet — every request returns 5xx until the background load finishes. If the load crashes, the replica keeps returning 200 indefinitely.This bug is easy to hit and silent in logs (the orchestrator is happy; only end-user requests fail).
Changes
## Production deployment notessection inexamples/server/README.mdwith two subsections:server.pyalready does and why it works for free under most orchestrators./healthpattern that returns503while loading or on load error,200only when the pipe is ready.threading.Threadfrom@app.on_event("startup"), which mirrors whatserverasync.pyalready does at startup but adds the gated/healthroute.Behavioral change
None — docs only. No code changes. No new dependencies.
Fixes # (no related issue — surfaced repeatedly across orchestrated deployments)
Before submitting
Who can review?
Docs: @stevhliu @sayakpaul