Repository navigation
[serve] Refactor server and engine architecture - #50927
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
tarekziade
left a comment
There was a problem hiding this comment.
Nice work!
The description says invalid request values give a 400, and that the server exits when the model's process dies, but with --continuous-batching these two collides.
CBGenerateRunner.generate runs inline in the loop at the end of run_engine, which has no try/except, so a bad value like generation_config={"temperature": "hot"} ends the model's process instead of giving a 400, and the server exits for everyone.
I guess that's easy to fix with something like
while True:
method, request_id, *args = requests.get()
try:
getattr(runner, method)(request_id, *args)
except Exception as error:
logger.exception(f"Request {request_id} failed")
send_results([], [], [(request_id, error)])
|
Fixed the issue in the latest commit and added a test to cover that |
LysandreJik
left a comment
There was a problem hiding this comment.
Starts to look good! I haven't played with it yet, that's the next step for me.
Co-authored-by: Lysandre Debut <[email protected]>
Co-authored-by: Lysandre Debut <[email protected]>
LysandreJik
left a comment
There was a problem hiding this comment.
Tried it out, works well! Thanks for shipping this @SunMarc !
What does this PR do?
This PR refactors a bit how serve is designed so that we are not bottlenecked by the api server. I've tested this on H100 and on a mac laptop (M2). I tried to keep things as familiar as possible from the old arch. Some features like multiple API servers only work when there is one model (force-model) but could be added for multi-model if needed.
I've added only a few tests as we didn't really need a lot of new tests and made sure that existing tests were passing correctly !
Overall architecture
Before
Everything runs in one process. Python runs one thread at a time per process, so the GPU loop
waits whenever the server handles HTTP, and the reverse.
Now
Two kinds of processes. The API server handles HTTP and text: chat template, tokenizing, decoding. The model process holds the model: it gets the prompt's tokens (with the image or audio features of a multimodal request, or the function to run for transcription and SystemOne), and sends back the new tokens.
Major pros
Behaviour changes
/v1/responsesno longer streams by default: as in OpenAI's API, a request streams only with"stream": true.stream_options={"include_usage": true}, in a last chunk of its own./healthanswers 503, and the server exits with an error, for whatever runs it to restart it.seedthat isn't a number, a settinggeneraterejects) give a 400 instead of a 500.Benchmark: server alone, ours vs vLLM
We only measure the server's own work. In both servers, the model is replaced by the same fake, which answers right away.
The load: 256 clients. Each sends a streamed chat request, and the next one as soon as it ends. The requests take
turns between four kinds:
Tokens streamed per second (higher is better):
Time until a client gets its first token, under this load (median, lower is better):
Further details
A request goes down through these classes, and its tokens come back up.
Going in: the request
Coming back: the tokens
In the API server
Serve(serve.py)run()serves one API server;run_api_servers(n)starts the model process and n API servers.build_server(server.py)CancelOnDisconnectstops a request when its client leaves.BaseHandlerand subclasses)ModelManagerEngineClientper model. Starts the model of the command line right away, others on their first request or/load_model.EngineClient--model-timeoutseconds and notices a crash.DetokenizerModelLoaderSeveral API servers
With
--api-server-count 3, three API servers share one model process. The model loads once.Going in: the requests
Coming back: the tokens
transformers serve MODEL --api-server-count N. It needs a model on the command line.