liveBook · Manning

Streaming

As explained in Deep Learning with PyTorch, Second Edition

Sending generated output incrementally to a client as it becomes available rather than waiting for the full result to finish.

Streaming sends generated tokens to a client as they become available, rather than making the client wait for the complete response. This makes text-generation APIs feel more responsive. section 17.1.3 section 17.1.4

In a batched serving setup:

  • A background model worker generates tokens for queued requests; an asynchronous generator yields each request’s tokens to its client as they arrive. section 17.1.4

FastAPI endpoint

The /generate endpoint queues the prompt and returns a StreamingResponse backed by a generator that streams the results. section 17.1.4

Figure 17.2 Dataflow with request batching and streaming
figure

Trace how queued requests, batched model work, and streaming responses fit together. section 17.1.4

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains token delivery through an asynchronous generator and result queues, but does not detail the response-streaming implementation.
Examples
Uses generated text for chatbot or writing-assistant clients and illustrates a FastAPI streaming endpoint.
What you can do after
Apply it via FastAPI’s StreamingResponse to send generated tokens as they become available.
How it connects
Connects response streaming to asynchronous generators, request batching, queues, and background model workers.

Also explained in

Compare how 19 books explain streaming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.