LLMs in production

5 concepts · 10 practice questions

Latency and streaming

LLM latency has two parts: time to first token, driven mostly by input size and queueing, and generation time, driven by the number of output tokens. Output tokens are generated one at a time, so shorter answers are the surest speed-up. Streaming does not make the total faster, but the user sees text at once. Other levers: a smaller model for easy steps, parallel calls for independent work, and fewer round trips.

# Independent steps: run them together, not one after another.
summary, tags, sentiment = await asyncio.gather(
    summarise(doc), tag(doc), classify_sentiment(doc)
)

# User-facing text: stream it.
async for chunk in client.stream(model=MODEL, messages=m, max_tokens=400):
    await send_to_client(chunk.text)

Also covered

Cost control
Caching
Rate limits and failures
Observability and safety

Sign in to read the rest and take the 10-question test.

Sign in to continue