Skip to content

Scheduler and memory ​

Use this reference to size scheduler work, prefix and graph execution, and snapshot capacity. Review Host allocation and NUMA behavior before choosing pool sizes.

Host memory allocation ​

Pinned-memory registration ​

By default, Host L2 allocation honors PyTorch's original allocator environment variables; TokenSpeed does not temporarily override your registration or thread settings. With no registration option set, NVIDIA uses the original serial path. On ROCm the launcher instead defaults to parallel registration (pinned_use_hip_host_register:True,pinned_num_register_threads:64), which page-locks large buffers faster than serial hipHostMalloc, most of all on cloud VMs behind a virtualizing IOMMU, where serial allocation of a large Host L2 can hold startup for a long time. Setting any registration option, in either the cuda or hip spelling, keeps your choice.

On hosts with kernel NUMA balancing enabled (/proc/sys/kernel/numa_balancing nonzero), ROCm keeps the serial hipHostMalloc default instead. Registered buffers are private anonymous memory that NUMA balancing migrates between NUMA nodes, and each migration makes the GPU driver suspend the process's queues while it revalidates the registered range, which stalls decoding requests; hipHostMalloc memory is a shared mapping that NUMA balancing skips. To keep parallel registration on such a host, disable NUMA balancing (sysctl kernel.numa_balancing=0); setting the registration options explicitly on a host that keeps NUMA balancing brings the stalls back. To opt into parallel page touching and cudaHostRegister on NVIDIA, set before startup:

bash
export PYTORCH_ALLOC_CONF="pinned_use_cuda_host_register:True,pinned_num_register_threads:8"

The legacy name PYTORCH_CUDA_ALLOC_CONF remains supported by PyTorch; older builds that ignore PYTORCH_ALLOC_CONF require this legacy name. Keep any existing allocator options in the same value. pinned_num_register_threads accepts powers of two from 1 to 128; use 1 for serial page touching, or disable registration with pinned_use_cuda_host_register:False.

The parallel task count is not the thread-pool size: PyTorch 2.14 creates a persistent 128-thread pool on the first sufficiently large parallel registration. Choosing 2 or 4 tasks still creates that pool. Leave registration disabled or use one task in environments with tight thread or virtual-memory limits. These options affect all PyTorch pinned allocations, including the snapshot pool. They do not bind CPUs or memory to NUMA nodes.

NUMA binding and buffer alignment ​

On NVIDIA, TokenSpeed binds the Host L2 and snapshot pools to the host NUMA node the GPU reports (CU_DEVICE_ATTRIBUTE_HOST_NUMA_ID; this needs libnuma). Binding reclaims that node's page cache, such as checkpoint files just read, instead of placing pages on another node, where the GPU's write-through stores run several times slower and stall its other kernels meanwhile. Pages that PyTorch's parallel registration threads touch keep those threads' policy.

The L2 buffer uses a 4 KiB-aligned view when the Disk tier requires direct I/O alignment, or on NVIDIA with the native allocator and registration enabled. Its alignment padding is included in the Host memory budget. Both ratio and explicit sizes stay within their original pinned bucket by dropping whole LCM blocks when possible. Other policies keep their original allocation sizes.

Scheduler and memory parameters ​

The following table describes the parameters that control scheduling, prefix reuse, graph execution, and snapshot capacity:

ParameterPurpose
--max-model-lenMaximum sequence length. If omitted, TokenSpeed uses the model config.
--gpu-memory-utilizationFraction of GPU memory used for model weights and KV cache. Lower it to leave headroom.
--max-num-seqsMaximum number of active sequences the scheduler may process concurrently.
--chunked-prefill-sizeToken budget the scheduler may issue in one iteration; it also bounds the multimodal placeholder tokens one encoder call produces (an item larger than that runs alone). Defaults to 8192. Set -1 to disable chunked prefill. On Muse Spark with Iris owned-row prefill (gfx950, attention TP 4 or 8), chunks above 8192 tokens stay on the owned-row layout instead of replicated rows: their attention-output and expert sums are then taken in another order, and the owned-row buffers grow with the chunk size (three per-rank buffers of that many 8192-wide BF16 rows), up to 24576 rows: larger chunks replicate their rows; --numerics rl-bitwise keeps 8192.
--prefill-chunk-yield-tokensPrefill servers: the room, in tokens, a prefill chunk that cannot finish its prompt makes for bootstrapped prompts waiting behind it that fit whole (counted past their prefix hit), so they run complete in the same forward instead of waiting for the long prompt's chunk to pass. The chunk ends on an earlier page and gives up fewer than N plus one page, only while such prompts wait and only what they take, so the long prompt keeps about half of every round or more. 0 (default) is off: no chunk gives way; at most half of --chunked-prefill-size; a decode server ignores it. Whatever N, a prefill server fills the budget a chunk leaves on its own with bootstrapped prompts that fit whole in it; scheduler §1.1 describes both.
--max-prefill-tokensPrefill token budget used when chunked prefill is disabled. Defaults to 8192.
--prefill-scheduling-policySelect local engine prefill admission order: fifo preserves submission order; short-prefill-first ranks remaining work after reusable Device/Host prefixes, including replay work, with stable ties and oldest-request protection after eight successful bypasses. Both policies keep resident chunks first. Unset preserves the default or the legacy short-prefill flag; cannot be combined with --enable-short-prefill-first (scheduler §1.1).
--enable-short-prefill-firstLegacy flag temporarily retained for backward compatibility. Use --prefill-scheduling-policy short-prefill-first for new configurations and migrate existing uses to that option. Selects the same short-prefill-first policy on prefill and aggregated servers. Cannot be combined with --prefill-scheduling-policy. Off by default, preserving submission order (scheduler §1.1).
--prefill-decode-intervalAfter a round that runs a prefill chunk, run this many decode rounds before the next prefill round, unless no decode can run or --prefill-interval-min-decoding waives it. Every chunk starts a new interval, but no prompt is held back more than this many decode rounds in total (per chunk under --max-consecutive-prefill-rounds; below --prefill-interval-min-decoding the count may pass it), so running decodes stall less often and, while that threshold is met or unset, TTFT grows by at most this many decode steps; below it, one decode round follows each run of at most --max-consecutive-prefill-rounds prefill rounds that held decodes back. Aggregated serving only. 0 (default) is off; nonzero values are mutually exclusive with the DP prefill gate (scheduler §3.3).
--prefill-decode-min-intervalAfter every round that runs a prefill chunk, run at least this many decode rounds before the next prefill round, unless no decode can run or --prefill-interval-min-decoding waives it. Unlike --prefill-decode-interval, this floor still applies once a prompt has been held back for its full interval, so a long prompt's chunks alternate with decode rounds instead of stalling running decodes back to back. Aggregated serving only. 0 (default) is off; nonzero values are mutually exclusive with the DP prefill gate.
--max-consecutive-prefill-roundsWith --prefill-decode-interval: the most back-to-back prefill rounds that hold a decode back while an overdue prompt suspends the interval. The round that reaches it owes the decodes the whole interval again, and a prompt's held-back count restarts whenever one of its chunks runs, so the interval's bound applies to each chunk. Rounds with nothing to decode, and in mixed mode rounds that decode beside their prefill, end the run. Aggregated serving only. 0 (default) keeps the unbounded suspension (scheduler §3.3).
--prefill-interval-min-decodingWith --max-consecutive-prefill-rounds (which needs --prefill-decode-interval): the decode rounds of --prefill-decode-interval and --prefill-decode-min-interval are owed only while at least this many requests are ready to decode. With fewer, waiting prompts are prefilled at once instead of waiting out the interval, but once --max-consecutive-prefill-rounds prefill rounds in a row have held a decode back, the next round decodes, so the few running decodes stall at most that many prefill rounds at a time. This trades the running decodes' token latency for first-token latency while few requests decode; at or above the threshold nothing changes. Request slots (--max-num-seqs) still count prefilling and decoding requests alike. Aggregated serving only. 0 (default) always owes them (scheduler §3.3).
--prefill-attempt-intervalALL attempt interval, in scheduling rounds, for the DP prefill gate: every rank with decode work must also have eligible prefill work to open the window. Set together with --prefill-any-attempt-interval, with 1 <= ALL <= ANY; leaving both unset (default) disables the gate. Aggregated (fused) serving only (--disaggregation-mode null); mutually exclusive with nonzero --prefill-decode-interval or --prefill-decode-min-interval.
--prefill-any-attempt-intervalANY attempt interval, in scheduling rounds, for the DP prefill gate: one eligible rank is enough to open the window. Must be set together with --prefill-attempt-interval and be at least its value (1 <= ALL <= ANY). This is an admission opportunity, not a hard TTFT deadline. Aggregated (fused) serving only (--disaggregation-mode null); mutually exclusive with nonzero --prefill-decode-interval or --prefill-decode-min-interval.
--prefill-single-roundOne prefill round per window for the DP prefill gate: the round after a prefill round is not an ALL point while any rank has decode work, so a backlog does not drain in consecutive prefill rounds; the next ALL point is --prefill-attempt-interval rounds later. An idle engine still admits at once, and ANY points are unchanged. Off by default; requires --prefill-attempt-interval and --prefill-any-attempt-interval.
--max-total-tokensOverride the automatically calculated token pool size.
--enable-state-checkpoint-in-forwardHybrid (recurrent-state) models: the prefill forward that spans the last prefix-page boundary before a long prompt's replay tail (normally the final token) also writes the recurrent state there, so a later request that resends the prompt or diverges from it after that boundary resumes there. No extra prefill round; that forward holds one more state block. The recurrent-state checkpoints, and their KV tails, that a next turn re-rendering the end of the previous prompt and its reply cannot resume at are then kept out of the prefix cache. On prefill and fused servers this is the prompt end when it lies inside the page that boundary starts and the request did not resume past it; a prompt end published at the request's finish, as on a prefill server, is kept if the state at the boundary has left the cache by then. On fused servers it is also every finish past the prompt end, including that of a prompt too short to have such a boundary. A next turn that repeats the previous reply verbatim therefore resumes at an earlier checkpoint and recomputes the reply. Requires prefix caching; a decode server ignores it; startup refuses it unless every State group is GDN (FlashInfer prefill, a prefix granularity that is a multiple of its 64-token scan chunk), KDA, or Qwen4-Exp PLE. With prefill graphs, the GDN layers of a forward that writes one stay captured; every captured shape shares one scan scratch of (largest prefill-graph token capacity / prefix granularity) recurrent states in the scan's state dtype. The KDA layers of such a forward run at their eager breaks and scan each checkpointed row's tokens before its checkpoint a second time. When a request publishes an in-forward checkpoint past the one it resumed from, which its own predecessor wrote past an earlier one, that earlier checkpoint -- two turns back on the conversation -- is evicted early from the device and host caches, and no new store or eviction write-back copies it to host, unless another request also resumed from it, or acquired or republished it after the conversation's previous turn resumed there, so multi-turn traffic keeps more live prefixes cached. On a prefill server, a prompt too short for the in-forward checkpoint (by default, one no longer than the chunk budget) whose end lies inside a prefix page also leaves only its full pages in the prefix cache, with no recurrent state and no KV tail at its end; a longer prompt that repeats it whole resumes at an earlier checkpoint instead, a page-aligned prompt end keeps its state, and a fused server keeps short prompt ends. Off by default (scheduler §1.2).
--enable-prefix-caching / --disable-prefix-cachingEnable or disable prefix cache reuse.
--enforce-eagerDisable device-graph execution (CUDA Graph on CUDA, ACL Graph on NPU).
--disable-prefill-graphKeep prefill eager while leaving decode device graphs enabled.
--decode-monokernelRun each decoder layer's small decode steps as one persistent monokernel launch on gfx950 (decode monokernel design). Off by default. Models: Qwen3.8-Flash-Next (Qwen4ExpForCausalLM, Qwen4ExpForConditionalGeneration), Muse Spark (MuseSparkForConditionalGeneration, with its DFlash2 draft), and Inkling 2 (Inkling2ForConditionalGeneration, and Inkling2LoopForConditionalGeneration for looped checkpoints). Startup fails when a layer cannot be packed; larger steps keep the regular path.
--dense-fp8-small-m {none,qkv}Muse Spark on gfx950: qkv runs decode and verify forwards' QKV projection at 33-128 rows as an FP8 GEMM (per-row FP8 activations, a per-channel FP8 weight copy made while the weights load; its memory is logged at startup, and releasing weights releases it (contents restored on resume)). Prefill and extend forwards stay BF16, so prompt K / V stays BF16. Startup refuses what it cannot serve (for example TP8, other GPUs, --weight-memory-policy discard, --model-update-config). A numerics change: refused under --numerics rl-bitwise and --batch-invariant-collectives. none (default) keeps BF16.
--monokernel-stuck-record-dirWith --decode-monokernel: a directory on tmpfs (for example /dev/shm) where each rank keeps its stuck-poll record file; the file is GPU-registered host memory, and a disk filesystem's periodic writeback of it stalls decode. A launch poll that gives up writes what it waited for there before the launch traps, so the record outlives the process. Without it the records stay in pinned memory and are logged when the failure reaches Python.
--inkling2-loop-num-passesLooped Inkling 2 checkpoints with loop_config.is_varloop=true: run the looped core this many times (at least 1) instead of the checkpoint's num_passes. Each pass is 12 more layer visits, each with its own KV cache and convolution state unless --inkling2-loop-share-cache is set. DSpark drafts read hidden states at fixed visits, so with a draft model only the checkpoint's count is accepted; model-free DUMMY drafting serves any count. With --decode-monokernel each visit takes one of a step's 64 launch tags, so the 24-layer checkpoint serves at most 4 passes there. Unset by default; other checkpoints refuse it.
--inkling2-loop-share-cacheLooped Inkling 2 checkpoints with loop_config.is_varloop=true: every pass of a core layer reads and writes that layer's one KV cache, so the KV pool holds one cache layer per decoder layer regardless of the pass count; each visit keeps its own convolution state. Off by default; other checkpoints refuse it.
--disable-kda-prefill-graphDisable KDA prefill CUDA graphs while retaining ordinary prefill and decode graph settings. Enabled by default for supported cutedsl_kda prefill attention when prefill graphs are enabled.
--kda-history-capacityKDA models: how many accepted decode records each request keeps per KDA layer, counting the verify window, before they are folded into the dense recurrent state. Defaults to 16; it must be at least the verify width (--speculative-num-draft-tokens), so a window wider than 16 requires setting it. A smaller capacity shrinks the per-request workspace taken from the KV cache budget but folds more often (at the verify width, every round that accepts a token). Cache checkpoints are the same either way.
--disable-cudagraph-memory-reserveSize the KV cache from free memory instead of reserving what the device graphs will cost and, on CUDA, what startup keeps resident.
--max-cudagraph-capture-sizeLargest decode batch size to capture as a device graph.
--cudagraph-capture-sizesExplicit decode batch sizes to capture as device graphs.
--prefill-graph-capture-token-sizesTotal input-token capacities per forward, summed across the batch. Shorter inputs are padded.
--prefill-graph-decoder-capture-token-sizesCED decoder graph capacities in retained token rows. By default, sizes follow the decoder window. Explicit sizes may exceed the largest encoder bucket within the forward token budget and per-rank request capacity.
--prefill-graph-capture-batch-sizesRequest capacities for inline recurrent prefill capture. Indexed GDN captures one capacity per bucket, capped by the bucket's token count. It uses the largest configured count or defaults to --max-num-seqs per attention-DP rank. Empty slots take zero tokens. Other recurrent scans capture each compatible count and default to 4 within the bucket's valid range. They reserve one token per empty slot. Batches exceeding the captured capacity run their recurrent layers at eager breaks.
--retraction-snapshot-host-gbExplicit size, in gigabytes, of the per-rank pinned Host pool that holds a retraction image's tail (a retracted request's blocks of groups Host L2 never holds, a state group's unpublished input block, and its slot state; the published blocks, the partial last page and the live state block included, go to Host L2 and stay pinned there until the request is restored; with --disable-kvstore the pool holds whole images). Wins over --retraction-snapshot-ratio when set; 0 (the default) means not set, like --kvstore-size against --kvstore-ratio. A request a capacity retraction suspends is imaged here and resumes exactly where it stopped once the image is copied back; nothing is recomputed. When no resident's image fits -- the pool or its rows are exhausted -- the scheduler aborts the newest resident instead (finish err_type 524, see Retraction snapshot pool), so the pool bounds how much can be suspended at once, never how long an admission waits. Fused and decode roles only; the prefill and encode roles never retract and ignore it with a log. Allowed under --kv-parallel-size > 1.
--retraction-snapshot-ratioSize of the retraction snapshot pool as a multiple of this rank's Device KV capacity (the base --kvstore-ratio scales too), used when --retraction-snapshot-host-gb is not set. Unset (the default) derives the pool at device build: 0.1 of the Device KV without the Host KVStore (whole images, kept cheap to pin; 1 uses the Device KV pool's usable LCM-block count, with request rows limited separately), else the image tails of --retraction-snapshot-max-requests requests (see the snapshot sizing table). An explicit 0 is the one way to run without a pool: nothing can be imaged, so every capacity block aborts its victim (the newest resident).
--retraction-snapshot-max-requestsSlot-state image rows of the retraction snapshot pool, that is, the most requests suspended at once, and the request count the derived pool size is multiplied by. 0 (the default) derives to the rank-local resident capacity C: B+E on decode and B on fused, where B is max-num-seqs divided by attention-DP size. An explicit positive cap is preserved. Refused with --retraction-snapshot-ratio 0, which has no rows to size. When no row is free the scheduler aborts a resident rather than waiting.
--debug-force-retraction-intervalTest only. Every N scheduler plans retract the oldest quiescent decoding request (N > 0), or with -N the one prefilling request between its chunks, without capacity pressure, so a test run exercises the suspend/restore path on every request (the bitwise continuation oracle of Numerics). Refused with --retraction-snapshot-ratio 0 (no pool to image into). 0 (the default) is off; never set it in serving.

Prefill graph capacity and compatibility ​

For pure prefill, token capacities count newly computed tokens, not cached prefixes or each request's full sequence length. Two requests extending by 868 and 869 tokens use the 2048-token bucket and request capacity 2 when configured. A smaller batch can reuse that capture if there is room for its dummy request slots. These settings do not replace the scheduler's --max-num-seqs limit.

--prefill-graph-capture-sizes remains a compatibility alias for --prefill-graph-capture-token-sizes. Specify only one spelling per command. Both populate the existing prefill_graph_capture_sizes Python field. Unset token sizes use the existing default ladder. Unset batch sizes capture 4 requests per token bucket, capped by --max-num-seqs per data-parallel rank and the bucket, and at least the request count that fits each token bucket within the model context.

--chunked-prefill-size is intentionally separate from --max-num-batched-tokens: in TokenSpeed it is the scheduler's per-iteration issue budget, while --max-total-tokens controls the global token pool.

Host L2 registration chunks ​

For NVIDIA L2 buffers, --kvstore-host-register-chunk-size 1 opts into a continuous, OS-page-aligned mapping registered in sequential chunks of at most 1 GiB. Fractional GiB values are accepted if they specify whole OS pages. The default 0 retains the PyTorch allocator. This controls registration chunk size, not KV cache pages or OS page size. Different ranks register concurrently; add --kvstore-host-register-serialize to serialize their registrations with a node-local, per-user lock. Serialization requires a positive chunk size. Workers must share the same XDG_RUNTIME_DIR, or the same /tmp when it is unset. The lock directory must belong to the current user with mode 0700; without XDG_RUNTIME_DIR, TokenSpeed creates /tmp/tokenspeed-host-register-<uid>. Lock files use mode 0600. Symlinks, hard-linked files, and unsafe ownership or permissions are rejected. The lock file remains in place after release so workers keep using one inode. Use an umask that preserves owner access, such as 0077. Permission validation errors also identify the process umask as a possible cause.

This path bypasses the PyTorch pinned allocator, including its registration thread setting and power-of-two reservation buckets. It pins the L2 payload rounded up to OS pages. Snapshot and slot-state pools keep the original PyTorch allocation policy. Failed registration releases completed chunks; Tensor views retain the mapping. Final release waits for the allocating worker's CUDA device, unregisters every chunk, then unmaps it. Chunking reduces individual registration size, not total pinned memory or host budget checks.

Registration chunks are rounded down to multiples of both the Host LCM block and the OS page size; the requested limit must fit at least one such unit. CUDA DMA may not span separate registrations. Keeping each LCM block within one registration preserves the existing per-field DMA and mapped-host kernel transfer paths without splitting their cache geometry.

TokenSpeed documentation