Building production-grade offline VLM inference engines at scale
The engine that runs a model, and the system built around it
Anirudh Srinivasan · Team Lead - Vision
Srihari Bandarupalli · Generative AI Engineer - Vision
What we do
We build sovereign vision foundation models
Patram: vision-language models for Indian documents, and the whole stack that builds them.
Evaluation
PatramBench · Patram-Eval
Serving infrastructure
Patram-Serve
Models
Patram Suite
Training infrastructure
Patram-Core
Training data generation
Patram-Ingest · today
Raw data collection
Patram-Scraper · Patram-Syn
Annotation & visualization
DarshinAI
Storage
Patram-FS · Patram-DB
Patram Suite
Multi-task foundation models
Patram series
Task-specific models
Patram-GrounderPatram-LayoutPatram-CoT
Agents
PatramParse
Scale
A foundation model needs data at this scale
100TB+of image data
100M+training examples
100B+tokens of model output
500+GPUs generating them
Day 1Week 1Week 2Week 3Week 4
one data-generation run
One data-generation run takes weeks, and must not stop.
Training data
What one training example looks like
The model learns from millions of examples like this one.
One training example, for this page
“What is the payment due date?”
“15 July 2015”
the box on the page that shows it
Made automatically, in a chain
Understandan electricity bill›Askwrite a question›Answerfrom the page›Verifymatches the page ✓
× 100 million+ pages, in 22+ languages.
Today
A model, its engine, and the system around it
Patram-Ingestbuilt by our team
vLLMbuilt by many experts, open source
The modelwhat you use in this coursetokens in, next token out
The model
Turns tokens into the next token. On its own, it serves nobody.
Parts 1 and 2 · vLLM
Runs one model for many requests at once, without wasting GPU memory.
Parts 3 to 6 · Patram-Ingest
Uses that engine for weeks to create training data, and keeps going when machines fail.
Agenda
What we will talk about today
First
vLLM: the engine that runs the model
1
Why running a model is hardFrom one person to many: two problems
2
How vLLM solves itTwo answers, and what they leave to you
Then
Patram-Ingest: the system we built around it
3
The system around vLLMWhat can interrupt a run that lasts for weeks
4
Keeping the GPUs busyProcesses, threads, event loops and queues
5
Crash safeLosing no work when machines die
6
GraphsMany models, and a different route for every page
7
Wrap-up: the main lessons from both.
Please stop us with questions at any time. A few slides will ask you for an answer.
1
Part 1
Why running a model is hard
What changes when many people use one model?
One person
A model writes one token at a time
1
Read all the tokens so far
2
Predict one new token
3
Add it to the end, and go back to 1
The sequence
0passes through the model
0tokens read this time
0tokens read in total
A token is a word or a piece of a word.
One pass gives one token, and every pass reads the whole sequence again.
One person
Saving earlier work makes it fast
Without a cache
45 token computations for 6 new tokens
With a KV cache
10 token computations for the same 6 tokens
computed in this passread from the cache
The cost: this saved work, the KV cache, fills GPU memory and grows with every token.
Many people
One GPU has to serve many people at once
ABCDEFGHmany requests, of different lengths
→
One GPU
Problem 1 · Time
Some requests finish early
The GPU should never sit idle while others wait.
Problem 2 · Memory
Nobody knows how long an answer will be
So how much memory should each request get?
One person was easy. Many people at once raises two problems.
Problem 1 · Time
One long request keeps the whole batch waiting
A finished request's place stays empty until the whole batch is done.
Illustrative: 8 requests of different lengths, 4 places at a time.
Problem 2 · Memory
Reserving for the longest answer wastes memory
GPU memory for the KV cache
holds a tokenreserved, unusedfree
Request C needs room for 16 tokens in one piece. Only 8 are left, though most of the memory holds nothing.
20.4% to 38.2%
of the KV cache memory actually held data, in the existing systems the vLLM authors measured.
Source: Kwon et al., PagedAttention, SOSP 2023
2
Part 2
How vLLM solves it
Two problems, two answers.
Answer 1 · Time
A free place is filled straight away
Illustrative: 8 requests of different lengths, 4 places at a time.
Your turn
Where have you seen the memory problem before?
Many programs share one block of memory.
Nobody knows how much each one will need.
Each one grows a little at a time.
They start and finish at any moment.
Which course taught you the answer?
AnswerOperating systems: virtual memory and paging.
Operating system
vLLM
Process
Request
Byte
Token
Page
KV block
Source: Kwon et al., PagedAttention, SOSP 2023
Answer 2 · Memory
Memory is handed out in small blocks
GPU memory, split into blocks
A request takes a block only when it needs one, and frees them all when it finishes.
Simulated. Blocks hold 4 tokens here for drawing; the default is 16.
Together
Both answers fit in one simple loop
1
Pick
Fill any free places from the waiting requests, and give them blocks.
→
2
Run the model
Get one new token for each request.
→
3
Clean up
Add the new tokens. If a request is finished, free its blocks.
repeat while any request is unfinished
It is the same idea as for one person, now for many requests at once.
Source: A. Gordić, Inside vLLM (2025)
vLLM
These two answers are the core of vLLM
2 to 4×
more requests per second than earlier systems, at the same speed per request, in the original paper
UC Berkeley
where it started. The paper appeared at SOSP 2023
2000+
contributors today, from many dozens of academic institutions and companies
To read more
Aleksa Gordić, Inside vLLM: Anatomy of a High-Throughput LLM Inference System (August 2025). It goes much deeper than we will today.
Sources: Kwon et al., SOSP 2023 · github.com/vllm-project/vllm · aleksagordic.com/blog/vllm
From vLLM to our system
What vLLM handles, and what is left to you
vLLM handles
Picking requests on each pass
GPU memory
Batching
Using several GPUs
A web server
You still need to decide
Which prompt to send next, out of 100 million
Whether an answer is good enough to keep
What happens to a page when a node dies
Which model a page goes to next
How to use GPUs that come and go
vLLM answers one request very well. Nothing in it knows about your whole job.
3
Part 3
The system around vLLM
What does it take to use vLLM for weeks at a time?
On a shared cluster
Three things that interrupt a weeks-long run
1
Nodes die and restart
The run has to recover on its own: notice, restart what died and continue, with nobody watching.
2
GPUs are lent out
GPUs are lent to other jobs for a while. When they return, the run has to use them again without a restart.
3
Work spans nodes
Complex workloads need pipeline parallelism: every step running at once, split across nodes.
Requirements
Three requirements for the engine
1
Keep the GPUs busy
The GPUs are the expensive part. They should never wait for anything.
2
Be crash safe
Nodes die, GPUs come and go. Every record is still written exactly once.
3
Any workflow, in little code
A new pipeline should take a few lines of code to define, and one command to run on every node.
4
Part 4
Keeping the GPUs busy
The GPU is the expensive part. How do we keep it from waiting?
Where the time goes
The model run is one of three steps
CPU · before
Prepare
build the prompt read and check the image
→
GPU
Run the model
the only step the GPU does
→
CPU · after
Finish
parse and validate write to disk, record progress
One batch at a time
the GPU waits whenever the host is working
Overlapped
the host prepares the next batch and finishes the last one while the GPU works
The host work is unchanged. It now overlaps with GPU time.
The architecture
Inside one node
All of these run at the same time. Each needs the right kind of parallelism.
Background
Three kinds of concurrency in Python
Process
Separate programs
Truly parallel, even for Python code
A crash stays inside it
Heavier, and data is copied between them
Use forCPU-heavy work, anything that may crash, anything that owns a GPU
Thread
Helpers in one program
Easiest: they share memory, so a hand-off is just passing an object
One at a time in Python (the GIL)
A crash takes the whole program down
Use forwaiting on the disk, the network or the database
Event loop
One thread, many waits
Hundreds of calls in flight, almost free
No locks: one thing runs at a time
One slow step blocks every call
Use formany model calls at once
Rule of thumbcomputing → process
Rule of thumbwaiting → thread
Rule of thumbmany waits → event loop
Your turn
Which kind of parallelism for each piece?
Process?truly parallel, a crash stays inside
Thread?cheap helpers, good at waiting
Event loop?one thread, many calls in flight
Our choice
What we chose for each piece
Processesthe orchestrator, the pool, each worker: CPU work, crashes stay apart, one GPU each
Threadsprepare, collect, write, upload, dispatch, supervise: they mostly wait
Event loopinside each worker: many calls in flight at once
Load balancing
Sharing requests between workers
The simplest design: one shared queue that every worker pulls from.
Inside every pull
1Take the lock
2Pull one request
3Release the lock
Simple, and self-balancing: a fast worker pulls more often.
The lock is never released
A killed process runs no cleanup, so it never lets go. Every other worker waits forever.
pool statushealthy ✓throughput0
No error and no timeout. Throughput is zero.
What we changed
One inbox per worker
One dispatcher is the only reader of the shared queue. Each worker reads only its own inbox.
No shared lock
Only the dispatcher touches the shared queue, and it is a thread that does not get killed on its own.
A worker dies
It can only block its own inbox, which is thrown away. The dispatcher stops sending to it. The others keep working.
A replacement starts
The supervisor starts a new worker with a fresh inbox. Its unfinished requests are sent again.
No shared lock between processes that can be killed. Since this change, the pool has not hung.
What runs in a worker
A worker can call any backend
The pool, the inboxes and the crash handling are the same for all of them.
Hosted vLLM
Shared vLLM servers, called over HTTP. The node itself needs no GPU.
Hugging Face models
Any model loaded on this node’s own GPU.
CPU work
Rendering pages in a headless browser, image processing.
Vision models
SAM3, YOLO and other detectors and segmenters.
A backend is three functionsinit()·call(request)·terminate()
5
Part 5
Crash safe
Any process can die at any moment. What happens next?
Many nodes
Coordinating across nodes, with minimal overhead
Each box is one image. A node claims a batch, and the boxes take its colour. If a node dies, its batch goes back.
Problems 1 and 2, revisited
Recovery and scaling without intervention
1
Recovery
A process or node dies. It is restarted, and its work is not lost.
1 · Recovery
Each layer is restarted by the layer around it
A worker dies→ the supervisor starts a new oneits requests are sent again
The program stops, or the node reboots→ the watcher starts it againits samples go back to the table
A vLLM server crashes→ its own watcher restarts itrequests go back to the queue
2
Scaling
GPUs come and go. The run adjusts without a restart.
2 · Scaling
Pipelines do not own model servers
One day of a production run · samples per second · illustrative shape
1Launched before the models were upwork starts as each server comes online
2A colleague borrows GPUsworkers there drain and wait
3The GPUs are returnedworkers fetch from the database again
4A server crashesits requests go back; it restarts
5More GPUs become freenew servers; the run spreads onto them
Errors
Every error is followed through
At this scale, something fails every minute. Each error is sorted into one of two kinds.
An error
The sample’s fault
Retrying will not help
corrupt imageimage too largeunreadable fileanswer never parses
Discard itmark it failed and record why
The system’s fault
The sample is fine
server crashedout of memoryprocess killednetwork blipserver asleep
Retry iton another node, or later
6
Part 6
Graphs of stages
Each page takes its own path through many models. How do we describe such a workflow, and run it across nodes?
One example needs many models
One pipeline, a different route for every page
The full pipeline
The whole pipeline is one graph
Every page enters at the left. Each box is a model, a tool or a check. Three simple rules decide where a page goes and when a box may start.
1 · Routing After Understand, a small function looks at the page and picks the next box. A text page goes to two boxes at once.
2 · Needs both Grounded Q&A needs the text and the layout of the same page. It starts only when both have arrived.
3 · Either one is enough A page is a table or a chart, never both. So “Write a question” starts as soon as one arrives.
Every pipeline we run is built from these three rules. needs every input one input is enough
What our pipelines have in common
Three properties shared by all our pipelinesA dynamic DAG covers almost all our workloads
Graph
Declared once, in code
Each stage names its inputs. The engine works out the rest.
Acyclic
No loops
A retry is a bounded decision in a routing function, never a cycle.
Dynamic
Routes decided while it runs
Each sample’s path depends on what earlier stages found in it.
Chains, branches, merges and early exits are all special cases of one dynamic DAG.
How the engine runs a graph
Stages need a shared record of each page
Separate programs. Each stage runs as its own process, often on its own machine, and shares no memory with the others.
No messages. Stages also never talk to each other, so one stage cannot tell another that it has finished a page.
One record per page. The engine keeps it in the DB. Every stage reads it and writes to it, and that is how the graph is coordinated.
How the engine runs a graph
The record is one switch per stage
1 + 2 = 3stored in the DB as the single number 3
A seat number per stage. Every stage in the graph has a seat: its position, counted from 0. The record has one switch for each seat. They all start off.
A switch on means yes. Here the answer is yes for Understand and Text, and no for Layout and Grounded Q&A.
A row of switches is one number. Seat 0 is worth 1, seat 1 is worth 2, seat 2 is worth 4, and so on. Add up the switches that are on. This is called a bit mask.
How the engine runs a graph
Two rows per page: Finished and Ready
In the DB
pagefinishedready481201
One row per page that is still in flight. Two numbers, no more.
Once a page has finished its last stage, its row is deleted, so the DB never holds the whole dataset.
Finished. Which stages have finished this page. It fills up as the page moves through the graph.
Ready. Which stages may start on this page: it is now waiting in their queue.
A new page starts with nothing finished (0) and only Understand ready (1), because it is the first stage.
How the engine runs a graph
Following one page through the graph
The number is the row added up, with seats worth 1, 2, 4, 8. Ready stays on once switched on.
Last stage finished: the row is deleted
1 · A page arrives. Only Understand may start, so only its Ready switch is on.
2 · Understand finishes. Its routing function says this is a text page, so it goes to Text and Layout at once. Their Ready switches go on, then Understand’s Finished.
3 · Text finishes, on node 3. Grounded Q&A needs both Text and Layout, and Layout is not finished, so it waits.
4 · Layout finishes, on node 7, some minutes later. Both inputs of Grounded Q&A are now finished, but nobody has told it yet.
5 · The sweep notices. A background process reads the records every few seconds. It sees both inputs finished and switches Ready on for Grounded Q&A.
6 · Grounded Q&A finishes, the last stage. The page is done, and its row is deleted from the DB.
How the engine runs a graph
When the sweep lets a stage start
The sweep’s check. Each waiting stage has a row of the inputs it needs. Keep only those switches that are also on in Finished (third row). Here Layout is missing, so Grounded Q&A waits.
Layout has finished. Every needed switch is now on in Finished, so the third row matches the first. The stage may start.
Either one is enough. Write a question takes a table or a chart, never both. One needed switch on is enough, so it starts as soon as the chart is finished.
How the engine runs a graph
Ready makes a stage start exactly once
Sweep 1
Inputs finished?Not all of them.
Text ✓Layout
0Ready for Grounded Q&A
Wait
Sweep 2
Inputs finished?Yes, both.
Text ✓Layout ✓
1Ready is off, so switch it on
Start it
Sweep 3
Inputs finished?Yes, both.
Text ✓Layout ✓
1Ready is already on
Skip
Sweep 4, 5, 6 …
Inputs finished?Yes, both. This stays true.
Text ✓Layout ✓
1Ready is already on
Skip
Without the Ready switch, every sweep would match again:startstartstart…
The sweep runs again and again. At sweep 2 both inputs are finished, so it switches Ready on and the stage starts.
The inputs stay finished, so every later sweep matches too. But Ready is already on, so the sweep skips the stage.
Finished says the inputs are there. Ready remembers that the stage was started. Together they give exactly once.
How the engine runs a graph
A crash between writes never loses a page
Our orderwhen Understand finishes a page
1Put the page in the next stage’s queue
2Switch on Ready for that stage
⚡ crash
3Switch on its own Finished
The page survives ✓Finished is still off, so after the restart the page is run again. Repeating a write changes nothing: the queue row and the switch are already there.
The reverse ordershown for comparison
1Switch on its own Finished
⚡ crash
2Put the page in the next stage’s queue
3Switch on Ready for that stage
The page is lost ✕The record says Finished, so nobody runs the page again, and the next stage was never given it.
Three writes to the DB hand a page on. A machine can crash between any two of them, so the order matters.
Crash in the middle. Left: the page is handed on, and Finished is still off. Right: Finished is on, but the page was never handed on.
Hand the page on first, mark yourself finished last, and make every write safe to repeat.
The database holds only state. Results go to files, written in groups.
Above all
The DB is the single source of truth
Any component can restartAny component can crash and restart. It held nothing, so it lost nothing.
Nodes can be added or removedNo handover, nothing to move. A new node just asks the DB for work.
Recovery is a DB queryThe state of the run is always in the DB. There is no recovery procedure to run.
Context
Where Patram-Ingest sits in the stack
Evaluation
PatramBench · Patram-Eval
Serving infrastructure
Patram-Serve
Models
Patram Suite
Training infrastructure
Patram-Core
Training data generation
Patram-Ingest · today
Raw data collection
Patram-Scraper · Patram-Syn
Annotation & visualization
DarshinAI
Storage
Patram-FS · Patram-DB
Parts 3 to 6Patram-Ingestturns raw pages into training data, on a shared cluster, for weeks at a time.
Below itStorage and raw dataPatram-FS and Patram-DB hold everything. The scraper and Patram-Syn feed it; DarshinAI lets us annotate and look at it.
Above itFrom corpus to modelsPatram-Core turns that data into our training corpus, and trains the Patram Suite of foundation models. Patram-Serve, our serving infrastructure, sits above the models.
In summary
vLLM runs the model. Patram-Ingest keeps using it, through failures, for weeks.