Hugging Face reposted this
We made the transformers serve API server as fast as we could ⚡️ transformers serve gives you an OpenAI-compatible server for transformers models. Under load, its API server used to hold the GPU back. Not anymore. The problem: one Python process did everything. HTTP, the chat template, tokenizing, decoding, and the generation loop right next to them. Python runs one thread at a time, so they took turns, and while the server handled requests, the GPU waited. What we changed: - The model now runs in its own process. The API server handles everything else, and the two talk through queues: prompts go in, new tokens come out. The GPU never waits for HTTP anymore. - Then we went through every step of the API server. Tokenizing runs in its own thread, off the event loop. Streamed events are built from a template instead of from scratch. The model sends one message per generation step, not one per token. A client that reads slowly gets its waiting text in one event. And a lighter middleware no longer adds a task to every streamed chunk. - Use --api-server-count for more API servers on the same port. They share one model process, so the model still loads once. If one day, we are bottlenecked by the api server (hopefully), we will switch to a rust api server ! Next up: faster generation overall. I heard that Quentin Gallouédec and Rémi Ouazan are already cooking 🧑🍳 PR: https://lnkd.in/ey8Yc79J