Playbook · DGX Spark

CUDA graphs on DGX Spark: how they work and how to shrink them.

What a CUDA graph records and replays, why it costs memory and start-up time, and how to cut that cost in vLLM and SGLang without guessing.

Do not turn graphs off in a setup that works. Try every change on a copy, and expect a restart.

How to shrink CUDA graphs on a DGX Spark

  1. A CUDA graph records GPU work once and replays it, mainly saving the processor's launch work.
  2. Each captured batch size adds start-up time and can take memory from the Spark's shared pool.
  3. On a copy of your setup, measure first, then change one thing: request limit, captured sizes, then graph mode.
  4. Turn graphs off only to troubleshoot, and never add --enforce-eager to a tuned recipe that works.

Checked on 26 November 2026 against: NVIDIA's CUDA guide; PyTorch's notes; vLLM 0.34.0 and SGLang 0.5.23 documentation and source. Nothing was run or measured. We have not yet run this playbook start to finish on our own hardware.

Watch, or step through

Choose a part.

Each part has a short video and its own slides, with each warning before the step it is about. Press Next step when you are ready. The page remembers your place.

Part 1 of 2: How CUDA graphs work

Video, part 1: How CUDA graphs work. It covers: Every launch costs time; Record once, replay often; What must stay fixed; Memory and start-up time. Chapters and transcript
Read the words of this video

How CUDA graphs work. Here's how CUDA graphs work on DGX Spark. Part two shows how to shrink what they cost.

The AI stack. Start at the bottom: the machine. Its GPU runs small programs called kernels.

Every launch costs time. Normally the processor sets up each kernel launch. Then it launches it on the GPU. And it pays that cost again for the next one.

Record once, replay often. Capture records the work instead of running it. New data goes into the same memory places. One launch then replays all of it. The main saving is launch work, not the maths.

What must stay fixed. Shapes are fixed. Another size needs another graph, or padding. The processor can't wait on the GPU, or make ordinary data decisions, inside. Processor work isn't recorded, so a replay skips it. And the memory addresses must stay put.

Memory and start-up time. Graphs keep memory, from the same pool as the model. Servers capture a set of sizes before serving, so starting takes longer. In vLLM, a batch with no graph big enough runs the normal way.

Record, then replay. Part two shows the settings, and how to shrink graphs without guessing.

Slides for this part, at your own pace:

9 steps

  1. Diagram for step 1, Launching has a cost: Every launch costs time
    Diagram: Every launch costs time, for step 1

    How they work

    1. Launching has a cost

    Without a graph, the processor prepares and launches each kernel, every time.

  2. Diagram for step 2, Capture: Record once, replay often
    Diagram: Record once, replay often, for step 2

    How they work

    2. Capture

    Work is recorded into a graph instead of run.

  3. Diagram for step 3, Refill: Record once, replay often
    Diagram: Record once, replay often, for step 3

    How they work

    3. Refill

    Replays use the same memory addresses, so new data goes into the same places.

  4. Diagram for step 4, Replay: Record once, replay often
    Diagram: Record once, replay often, for step 4

    How they work

    4. Replay

    One launch runs the whole graph. The main saving is processor launch work.

    PyTorch on CUDA graphs

  5. Diagram for step 5, Fixed shapes: What must stay fixed
    Diagram: What must stay fixed, for step 5

    How they work

    5. Fixed shapes

    A different size needs another graph, padding, or normal (eager) running.

  6. Diagram for step 6, What is not recorded: What must stay fixed
    Diagram: What must stay fixed, for step 6

    How they work

    6. What is not recorded

    Processor work is skipped on replay, which can give wrong results without an error.

  7. Diagram for step 7, Memory: Memory and start-up time
    Diagram: Memory and start-up time, for step 7

    How they work

    7. Memory

    Graph memory comes from the Spark's shared memory.

  8. Diagram for step 8, Start-up: Memory and start-up time
    Diagram: Memory and start-up time, for step 8

    How they work

    8. Start-up

    Each captured size adds work before the server is ready.

  9. Diagram for step 9, No graph fits: Memory and start-up time
    Diagram: Memory and start-up time, for step 9

    How they work

    9. No graph fits

    In vLLM such a batch runs eager. It does not capture a new graph for it.

Part 2 of 2: Shrink graphs, and measure

Video, part 2: Shrink graphs, and measure. It covers: Write down the baseline; See what you use; One change at a time; A shorter list; Turning graphs off. Chapters and transcript
Read the words of this video

Shrink them, and measure. Part two: making CUDA graphs smaller, one measured change at a time. Work on a copy, when nobody needs the server.

Write down the baseline. Save the exact start command that works, and its versions. Note the time to ready, and the memory lines in the log. Time your own typical requests, quiet and busy.

See what you use. This vLLM option reports which graphs your requests really use. Adding it restarts the server.

One change at a time. First, allow only as many requests at once as you need. The cost: fewer run together. Next, capture fewer sizes. Bigger batches then run the normal way. Last, try a smaller graph mode. Decoding can be slower.

A shorter list. In vLLM 0.34, a decode cap looks like this. In SGLang, this limits the largest decode batch.

Turning graphs off. Turning graphs off only tests whether they're involved. It can cost speed. Never add enforce eager to a tuned recipe that works. Afterwards, go back to your saved command.

Measure, then keep. Keep a change only if your own numbers say it's worth it.

Slides for this part, at your own pace:

9 steps

  1. Diagram for step 1, Keep what works: Write down the baseline
    Diagram: Write down the baseline, for step 1

    Shrink them

    1. Keep what works

    Every test restarts a server and ends service for its users.

    Save the exact start command and versions. Test a copy.

  2. Diagram for step 2, Measure first: Write down the baseline
    Diagram: Write down the baseline, for step 2

    Shrink them

    2. Measure first

    Note time to ready, memory lines, and the speed of your own requests.

  3. Diagram for step 3, See your sizes: See what you use
    Diagram: See what you use, for step 3

    Shrink them

    3. See your sizes

    Adding it needs a restart.

    Add this to a copy of your full command.

    vllm serve MODEL --cudagraph-metrics
  4. Diagram for step 4, Limit requests: One change at a time
    Diagram: One change at a time, for step 4

    Shrink them

    4. Limit requests

    Lower --max-num-seqs only if you do not need that many at once. Cost: fewer run together.

  5. Diagram for step 5, Capture fewer sizes: One change at a time
    Diagram: One change at a time, for step 5

    Shrink them

    5. Capture fewer sizes

    Larger batches can run without a graph, which can be slower.

    The number only shows the form.

    vllm serve MODEL --compilation-config '{"max_decode_cudagraph_capture_requests": 8}'
  6. Diagram for step 6, Try a smaller mode: One change at a time
    Diagram: One change at a time, for step 6

    Shrink them

    6. Try a smaller mode

    Test on a copy.

    Only if still needed. Cost: decoding can be slower.

    vllm serve MODEL --compilation-config '{"cudagraph_mode": "PIECEWISE"}'
  7. Diagram for step 7, SGLang's cap: A shorter list
    Diagram: A shorter list, for step 7

    Shrink them

    7. SGLang's cap

    Test on a copy. This restarts the server.

    The number only shows the form.

    python3 -m sglang.launch_server --model-path MODEL --cuda-graph-max-bs-decode 8
  8. Diagram for step 8, Off is only a test: Turning graphs off
    Diagram: Turning graphs off, for step 8

    Shrink them

    8. Off is only a test

    For troubleshooting only. It can cost speed. Never add --enforce-eager to a tuned recipe that works.

    On a copy, this vLLM mode turns off graphs to see whether they are involved.

    vllm serve MODEL --compilation-config '{"cudagraph_mode": "NONE"}'
  9. Diagram for step 9, Go back: Turning graphs off
    Diagram: Turning graphs off, for step 9

    Shrink them

    9. Go back

    Restarting ends service for a moment.

    Return to your saved command, restart, and compare with the baseline.

The drawings in the videos and slides are our own illustrations, not the makers’ screens.

On this page

Six parts.

Written from NVIDIA, PyTorch, vLLM and SGLang documentation and their public source, read on 26 November 2026, with vLLM 0.34.0 and SGLang 0.5.23 in mind. Your version may differ. We have not run these steps or measured anything on a DGX Spark for this guide.

Part 1

How do CUDA graphs work on a DGX Spark?

Normally the processor prepares and launches GPU work one kernel at a time, and pays that cost for every launch. A CUDA graph describes many operations and the order between them. It is set up once and can then be launched many times with little overhead. NVIDIA’s guide calls the stages definition, instantiation and execution.

Without a graphlaunch 1kernel 1launch 2kernel 2launch 3kernel 3launch 4kernel 4With a graphRecord onceat start-upOne launcheach replaykernel 12, 34Same kernels, same memory addresses, new contents
Our own drawing: a graph is recorded once and replayed, so the processor launches many kernels with one call. The kernels still do their work.

What is recorded, and what is replayed?

PyTorch builds graphs by capture: while a stream is being captured, GPU work is written down instead of run. A replay runs the same kernels with the same arguments, using the same memory addresses. New data goes into those same places before each replay.

The main saving is the processor’s launch work. It does not remove the maths: PyTorch says kernels also run slightly faster in a replay, but skipping processor overhead is the main benefit. How much that is worth depends on how much of your time was overhead.

What can a graph not do?

RuleWhat it means for you
Shapes are fixedA graph captured for one size serves that size. Other sizes need their own graph, padding to fit, or normal running.
No waiting for the GPU insideA call such as .item() is not allowed during capture.
No ordinary Python decisionsA branch chosen from data cannot be replayed as Python. Special graph-aware control flow exists, with limits.
Processor work is not recordedPyTorch warns it is skipped on replay. The result can be wrong without an error.
Memory must stay putThe captured addresses stay reserved. Freed or reused memory can cause illegal access or corrupted values.

Warm the code up before capture. Changing only values or addresses can be done by updating a graph; a changed structure needs a new one (NVIDIA’s guide).

Part 2

Why do CUDA graphs use memory and slow start-up?

Model weightsCUDA graphscaptured sizesKV cacheroom for requestsEverything elsesystem, other appsOne pool of unified memory. Not to scale.
Our own drawing, not to scale: on a DGX Spark, graph memory comes from the same shared memory as the weights, the KV cache and the system.

A DGX Spark’s processor and GPU share one 128 GB pool. A captured graph keeps memory of its own. PyTorch gives captures a private pool, which graphs can share if they never run at the same time; it names vLLM as a server that does this.

Why is capture done at start-up?

Server software captures a set of sizes before it serves, so that requests do not wait for capture. vLLM says all its compiling finishes before it serves any request. The price is a longer start: each size is warmed up and captured.

What do batch sizes have to do with it?

In vLLM 0.34.0 there are two sets of graphs. Decode graphs, for batches where every request adds the same number of tokens, are chosen by the number of requests. Graphs for batches that include reading a prompt are chosen by the number of tokens. A batch uses the smallest suitable graph that is big enough. If none fits, it runs eager, the normal way without a graph. So a batch that falls back is slower to launch, and more or wider graphs take more memory and time (vLLM 0.34.0 settings source). Some attention methods support full graphs only for some batches, and vLLM then lowers the graph mode.

Part 3

How do you read CUDA graph lines in the start-up log?

Before you change anything, keep a copy of the start-up log of the setup that works. These are what we found in the vLLM 0.34.0 source; the wording changes between versions.

Look forWhat it tells you
Progress bars Capturing CUDA graphs (PIECEWISE) and (FULL)Which kinds are captured, how many, and how long it takes.
CUDA graph pool memory:Actual and estimated graph memory. It is printed when an estimate was made, so it may be absent.
The line giving the total start-up seconds, with compile seconds in bracketsHow much of the start is profiling, cache creation and warm-up, and how much is compiling.
A warning that CUDA graph memory profiling is disabledGraph memory is not being counted when the cache is sized. vLLM warns this can run out of memory.
With VLLM_LOGGING_LEVEL=DEBUG, CG Capture: linesEach captured mode and batch size. The log gets very long.

See the capture code and the worker code. For a Docker container, docker logs CONTAINER shows the log.

While serving, --cudagraph-metrics adds figures at each logging interval: padded and unpadded tokens, and which graph modes ran and how often. This shows what your real requests use. Adding it means restarting the server.

Part 4

Which vLLM and SGLang settings control CUDA graphs?

Leave a tuned recipe that works as it is. Try changes on a copy. Every change here needs a server restart, which ends service for its users.

vLLM 0.34.0

vLLM 0.34.0 has one model runner, called V2. The settings go inside --compilation-config.

SettingWhat it controls
cudagraph_modeFULL_AND_PIECEWISE (vLLM’s usual default with piecewise compile; most memory, longest capture), FULL, FULL_DECODE_ONLY, PIECEWISE, NONE.
max_decode_cudagraph_capture_requestsLargest decode graph, counted in requests.
decode_cudagraph_capture_request_sizesYour own list of decode sizes. An empty list captures none from this list.
max_prefill_cudagraph_capture_tokensLargest prompt-side graph, counted in tokens.
prefill_cudagraph_capture_token_sizesYour own list of those token sizes.
cudagraph_capture_sizes, max_cudagraph_capture_sizeThe older names. vLLM marks them deprecated with V2.

Set a list or a cap for each side. The two sides are separate. Draft models for speculative decoding have extra rules; read the setting descriptions. --enforce-eager is different: it turns off CUDA graphs and torch.compile.

Memory sizing. vLLM 0.34.0 turns on an extensible KV cache by default on CUDA, which it says sizes the cache from the memory free after capture and warm-up, and falls back to an estimate where the driver lacks support. We have not checked which a DGX Spark gets. vLLM also has an estimate pass, on by default; VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS=0 turns it off. We do not suggest turning it off.

SGLang 0.5.23

SGLang sets graphs for two phases: decode and prefill (server arguments). Its online pages can be newer than your release, so check python3 -m sglang.launch_server --help.

FlagWhat it controls
--cuda-graph-backend-decodefull, breakable or disabled.
--cuda-graph-backend-prefillfull, breakable (its docs give this as the CUDA default) or disabled.
--cuda-graph-max-bs-decode, --cuda-graph-max-bs-prefillLargest batch captured for each phase.
--cuda-graph-bs-decode, --cuda-graph-bs-prefillExplicit lists of batch sizes.
--cuda-graph-max-seq-len-prefillLongest prompt a prefill graph takes; longer ones run eager.

A breakable graph is split into captured pieces with normal code between them (SGLang’s description). SGLang’s online docs also describe saving graphs to disk with an extra package. We did not find that setting in the 0.5.23 arguments we read, and the page describes its ready-made package as Linux x86_64, while DGX Spark is an Arm system. So we do not suggest it.

How does torch.compile fit in?

Compiling and capturing are two steps. Compiling builds faster code; a graph records launches. PyTorch’s compile mode reduce-overhead uses CUDA graph trees, which share one memory pool across captures. vLLM splits its compiled model around attention for piecewise graphs, and can include attention in full graphs where the attention method supports it. SGLang’s page marks its --enable-torch-compile as no longer maintained.

vLLM keeps compile results under ~/.cache/vllm (VLLM_CACHE_ROOT), which can shorten the next start. A change to the model, settings, related VLLM_* variables, PyTorch or GPU makes it compile again (vLLM optimization page). It stores compiled code; do not expect it to remove capture.

Our advice. With Docker, keep that folder on a mounted volume, or it goes when the container is removed.

In your own PyTorch code

To avoid capturing again and again, or falling back: capture once, after warm-up and outside your request loop; keep shapes fixed, padding to a few set sizes; hold on to the input and output tensors; copy new data into them, then replay. PyTorch calls its graph API beta. Follow its examples, which also show the stream rules.

Part 5

How do you reduce CUDA graph memory and start-up time?

Change one thing, restart, measure, and keep or undo it. The numbers below only show the form of a setting. They are not advice for your model.

Work on a copy, when nobody needs the server. Each test restarts it. Fewer or smaller graphs can make busy periods slower.

  1. Write down the baseline.

    Save the exact start command, versions, the log, the time to ready, any graph memory line, the KV cache size the log reports, and free -h. Time a few of your own typical requests, one at a time and as many together as you really get.

    vllm --version
    free -h
  2. Find the sizes you use.

    Add --cudagraph-metrics to the copy and run your normal load for long enough to see busy and quiet times.

  3. Match request limits to real need.

    --max-num-seqs sizes per-request buffers and graph capture, and vLLM’s memory page says limiting it and the context length saves memory. Cost: fewer requests run at once, or shorter conversations fit.

  4. Capture fewer sizes.

    With vLLM 0.34.0, a cap or a short list on each side:

    vllm serve MODEL --compilation-config '{"max_decode_cudagraph_capture_requests": 8}'
    vllm serve MODEL --compilation-config '{"decode_cudagraph_capture_request_sizes": [1, 2, 4, 8]}'

    Use one of these, not both, and keep your recipe’s other options. On older vLLM the form was:

    vllm serve MODEL --compilation-config '{"cudagraph_capture_sizes": [1, 2, 4, 8]}'

    Cost: a batch between two sizes is padded to the next; one above the largest suitable graph runs eager. vLLM notes that decode graphs no wider than the widest prompt-side graph mostly reuse its memory, so trimming those may save little memory.

    These examples shrink the decode side only. The prompt side has its own settings, listed under Settings.

    SGLang’s matching step is a lower largest batch:

    python3 -m sglang.launch_server --model-path MODEL --cuda-graph-max-bs-decode 8
  5. Only if still needed, try a smaller mode.

    vllm serve MODEL --compilation-config '{"cudagraph_mode": "PIECEWISE"}'

    vLLM says the two-kind default uses the most memory and takes longest to capture. Its -O1 level also uses piecewise graphs, with lighter compiling. Cost: decode can be slower. FULL_DECODE_ONLY saves the piecewise graphs’ memory but runs other batches without graphs. Not every attention method supports every mode.

  6. Compare, then keep or undo.

    Success: the server starts, memory or start-up time improved by an amount that matters to you, and your timed requests are still fast enough at both quiet and busy times. Otherwise go back to the saved command and restart.

If you start models from Server AI Hub

In the code of our Mac app 1.0.59, the Launcher has a CUDA GRAPHS choice for SparkRun recipes. Keep Recipe default for a recipe that works. The other two add vLLM’s deprecated --cudagraph-capture-sizes after --; they are not SGLang settings, and we have not tested them. The command box shows what would be sent. See the SparkRun guide.

Part 6

CUDA graph errors on DGX Spark: what to try

What you seeWhat it may mean, and what to try
Out of memory during capture or just afterCheck what else holds memory. Then try a lower request limit, fewer sizes, or your server software’s memory share, one at a time.
SGLang: Capture cuda graph failedIts 0.5.23 message suggests, in turn, a smaller --mem-fraction-static, a smaller --cuda-graph-max-bs-decode, and last, turning decode graphs off, which it says costs a lot of speed.
Start-up is suddenly much slowerThe compile cache may have missed after an update or settings change, or was inside a removed container. Compare logs.
Slower only when busyBatches may be larger than any graph. Look at the graph metrics.
Wrong output or illegal memory access in your own codeCheck for changed shapes, freed or moved tensors, and processor work inside the captured part.
A hang with SGLang across two machinesSGLang’s arguments page suggests trying both disable flags if you meet a deadlock.

Turning graphs off, for troubleshooting only

Never add --enforce-eager to a tuned recipe that works. It removes CUDA graphs and torch.compile, and vLLM says it costs steady decoding speed. Turning graphs off answers one question: are graphs involved? It is not the fix. Restarting ends service.

On a copy, this vLLM test turns off only the graphs. vLLM calls NONE good for debugging.

vllm serve MODEL --compilation-config '{"cudagraph_mode": "NONE"}'

This one also turns off compiling:

vllm serve MODEL --enforce-eager

In SGLang 0.5.23 the test is --disable-decode-cuda-graph and --disable-prefill-cuda-graph. If the problem stays, graphs were probably not the cause.

Undo

Remove the test setting, or go back to your saved start command, and restart. Then check the log and your timed requests against the baseline. More flags: our flag reference.

Next

Keep going.

About Server AI Hub

Server AI Hub is our app for looking after a DGX Spark. You do not need it to follow this playbook. It is coming soon to the App Store and the Microsoft Store.

See what Server AI Hub does

Sources

Check the makers’ own pages.

General guidance only, in our own words, read on 26 November 2026. You use these steps at your own risk. NVIDIA, CUDA and DGX Spark are trademarks of NVIDIA Corporation. PyTorch, vLLM, SGLang, Docker and other names belong to their owners. 6ixLabs is not affiliated with or endorsed by NVIDIA or these projects.