Visual document question answering with Pix2Struct: takes a document Image and a natural-language String question, renders the question onto the page and decodes a free-text String answer in one pass, without a separate OCR stage.
Typical backends
Answer a fixed question about a page fetched over HTTP and publish the answer as JSON for a downstream service.
Render a PDF page, ask a question about it, and return the answer over HTTP.
Caveats
- I/O contractThe question is rendered as a header onto the page image before patch extraction, so the model answers directly from pixels with no OCR step; legible page resolution matters more than any text layer.
- FallbackA blank page or an empty question short-circuits to an empty
String answer, and an inference failure on a single message is logged and also returns an empty answer rather than crashing the stream. - AccuracyAnswers are short extractive spans; the lighter default checkpoint trades accuracy for speed, while the larger DocVQA checkpoint improves accuracy at higher latency and memory.
- LatencyThe answer length cap bounds decoding per call, and the model loads once at startup so the first call on a fresh container pays the download and load cost.
- CompatibilityRuns on CPU but is materially faster on a GPU, where half precision is used automatically; a GPU host is recommended for interactive latency.