May we use cookies so Meta, Google, LinkedIn and ChatGPT see your visit and we learn which ads work? PrivacyMay we use cookies to see which pages help, and let Meta, Google, LinkedIn and ChatGPT see your visit, so we know which of our ads work? That way we spend less on ads that do not work. We do not sell your data, and the site works the same if you decline. You can change your answer at any time under Cookie settings at the foot of the page. Privacy policy
Loading...
AI Engineering · Serving And Inference
Free preview: the first 2 parts of this 32-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
Generative AI and Agentic AI Engineering
Unlock this lesson and the 208 other paid lessons
$35 once, by card or PayPal
See the Generative AI and Agentic AI courseread the rest of this lesson in
Generative AI and Agentic AI Engineering
Unlock this lesson and the 208 other paid lessons
$35 once, by card or PayPal
See the Generative AI and Agentic AI coursein Serving And Inference
This lesson is part of the AI Engineering course. Unlock the full course, a separate one-time payment, for lifetime access.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime AccessFoundation lessons of this course are free, no payment needed. Try them now
Let me start at a desk in an office, early in the morning.
The desk opens at nine. The first person in the queue walks up at one minute past. The clerk has to switch on the lights and the computer, wait for it to start, open the right program and find the right drawer. Only then can she help. The second person waits only for the first one to finish.

Nobody did anything wrong. The desk was simply not ready yet. A new copy of a prediction service has the same problem. Before it can answer anyone, it must start a program, load its tools, load the model and open its door. And the very first question it answers may still be slower than the ones after it.
In this lesson I measure that start, piece by piece, on a rented machine. I ask where the time goes, and which parts a real user would feel. Then I try four ways to hide those parts from users. I keep the files in memory, send a warm-up request, put a readiness check in front, and run the service in a container.
This is lesson 6 of the chapter on serving a model. Lesson 2, latency anatomy, took one request apart. Lesson 3, tail latency, found that the slowest request of a run was always the first one, but it measured only after the service had started. Lesson 5, workers and threads, showed that one worker with one thread was the best choice on one core. So in this lesson the service always runs with one worker and one thread.
The model, the service code and the rented machine are the same as in lessons 2 to 5, so I do not explain them again. In short: the model is the features chapter's gradient boosted tree model, which scores one customer of a real online shop and reached a test AP of 0.5450. The service is a small FastAPI web service run by uvicorn. It reads the customer's six features from SQLite.
The container image follows packaging lesson 5, container images, which showed how to build a slim image and what was inside it. I do not repeat that here. This lesson asks a different question about the same kind of image: how long does it take to start?