Skip to content

CLI reference

One binary, ten subcommands. Run dlm --help for the top-level list, or dlm <command> --help for a command’s full flag set.

CommandWhat it does
searchFind models on the Hugging Face hub.
pullDownload a model locally (via curl).
profileCompute the VRAM plan — no GPU needed.
serveStart the OpenAI-compatible HTTP server.
benchMeasure prefill and decode speed, loaded as serve would load it.
packWrite a copy of a safetensors model with its weights already quantized.
generateRun the CPU (or GPU) generation loop, with images for Gemma 3.
scoreLog-probability of each token of a text, and the likely next tokens.
tokenizeByte-level BPE encode/decode round-trip.
doctorCheck the machine + run a self-test.
completionsPrint a shell completion script.

Search the Hugging Face hub for models — most-downloaded matches first. It lists safetensors repos by default; --gguf lists repos that ship .gguf files instead.

$dlm search llama-3.2
FlagPurpose
--limitMaximum results to show (default 20).
--ggufList repos that ship .gguf files instead of safetensors ones.

pull

Download a model straight to disk — no hf CLI needed. It shells out to curl (built into Linux, macOS, and Windows 10/11) to fetch only the files dlm loads: config.json, *.safetensors, and the tokenizer — or, with --file, one .gguf file.

$dlm pull Qwen/Qwen2.5-0.5B-Instruct
$dlm pull Qwen/Qwen2.5-0.5B-Instruct-GGUF --file q4_k_m
FlagPurpose
--local-dirChange where the model lands (default ./models/<model>; ./models/gguf for a --file download).
--tokenAuth for gated/private repos (or set $HF_TOKEN).
--fileFetch one .gguf file out of the repo, by its full name or any part of it (--file q4_k_m).
A full HF URL works in place of the org/model id. A GGUF repo holds the same model at a dozen quantizations, so dlm will not guess: pulled without --file, it lists the repo’s .gguf files with their sizes. PyTorch-only repos (no safetensors, no GGUF) are rejected with a clear message.

profile

Do the VRAM budget math and report exactly how many layers stay resident — no weights loaded, no GPU required. With no --model-path it profiles a representative Llama-3-70B-class model against a simulated 16 GB card.

$dlm profile --model-path /path/to/models/Llama-3-70B-Instruct
$ dlm profile
  gpu backend  : none (host fallback)
  geometry     : 80 layers, hidden 8192, 64 q / 8 kv heads
  quantization : Fp16 (2 bytes/param), ~70.6 B params
  ── VRAM PLAN ──────────────────────────────
    M_free           :    16384.0 MiB
    M_safety         :     1536.0 MiB
    M_kv_total       :     2560.0 MiB
    pinned_zone      :        0.0 MiB
    M_layer_weight   :     1682.1 MiB
    usable           :    12288.0 MiB
    ▶ layers_to_load :          7 / 80
    ▶ resident       :       8.8%
  ────────────────────────────────────────────
  kv cache     : 512 paged blocks × 16 tok, 5.00 MiB/block → 8192 token capacity
  swap cycle   : 12 streaming pass(es), window of 7 layer(s)
  pipeline     : 4 steps, 2 overlapped (DMA hidden under compute)
Built-in sample, simulated 16 GB card, 16-bit checkpoint dtype (no --quant), 8,192-token context.

The sample assumes 16-bit weights, so a layer is 1.7 GiB and only 7 of 80 fit. --quant int4 quantizes the weights at load, dropping a layer to 420 MiB so the same 16 GiB holds 29 (int8: 841 MiB, 14) — see Quantization.

FlagPurpose
--model-pathModel directory to profile. Omit for the built-in 70B-class sample.
--context-lengthTarget context window in tokens (default 8192).
--quant int4 | int8Weight precision to plan against. Defaults to the checkpoint's own dtype.
--vram-budget-gbManual upper VRAM cap. Overrides the live device query.
--safety-margin-gbVRAM cushion for transient allocations. Default: a tenth of the card's VRAM, between 0.25 and 1.5 GiB (1.5 without a GPU).
--ram-cache-gbHost-RAM layer cache budget for the plan.

See Architecture & math for how the plan is computed.

serve

Start the OpenAI-compatible HTTP server for a model. Concurrent requests are continuously batched, and "stream": true streams the reply as Server-Sent Events. Full endpoint details are on the HTTP API page.

$dlm serve --model-path /path/to/model --context-length 8192 --port 8000 --host 127.0.0.1
FlagPurpose
--model-pathDirectory with config.json + *.safetensors, or a .gguf file.
--quant int4 | int8The primary memory lever — 4x/2x smaller layers at load, so more stays resident and streaming shrinks or stops. Defaults to the checkpoint's own dtype.
--vram-budget-gbManual upper VRAM cap. Overrides the live device query.
--safety-margin-gbVRAM cushion for transient allocations. Default: a tenth of the card's VRAM, between 0.25 and 1.5 GiB. Raise it if you hit OOM.
--ram-cache-gbHost-RAM layer cache — roughly 2x on the streamed path. On by default with --stream when every layer fits in a quarter of RAM.
--portTCP port (default 8000).
--hostBind address (default 127.0.0.1).
--context-lengthKV context window in tokens (default 8192).
--stream [--resident-layers N]Layer streaming — hold only a bounded window in memory (VRAM on the GPU, host RAM on the CPU), materialize the rest on demand. On the GPU, a model whose weights don't fit streams without the flag.
--gpu-layers NHold the first N layers in VRAM and run the rest on the CPU (llama.cpp's -ngl). An alternative to --stream; GPU only.
--prefetch-depth NCPU streaming: prefetch N layers ahead (default 1; 0 disables). Clamped to window − 1.
--auto-prefetchCPU streaming: auto-tune the prefetch depth from measured load-vs-compute time.
--kv-quant auto | f16 | f32 | int8 | int4KV cache precision. auto (default) is int8 on the GPU and f32 on the CPU kernels.
--device gpu | cpuCompute device. Defaults to gpu on a cuda-kernels build; falls back to CPU with a warning if no GPU is usable.
--max-batch NRequests decoded concurrently (default 8).
--speculative auto | off | ngram | draft | mtpSpeculative decoding. auto (default) uses the draft model if given, else n-gram lookup where verifying is cheap (the GPU, or a CPU model streamed from disk). mtp drafts with the model's own multi-token-prediction head (Qwen3.5/3.6).
--draft-model-pathSpeculate with a draft model, or an EAGLE-3 head (a directory whose config.json names an *Eagle3 architecture; resident GPU only).
--draft-gamma NTokens proposed per speculative round, by the draft model or n-gram lookup (default 4).
--lora DIRMerge a PEFT LoRA adapter into the weights as they load.
--api-keyRequire a key on every route except the /, /health and /healthz liveness probes — /metrics included. Sent as Authorization: Bearer or x-api-key.
--cors-originLet browsers on this origin (or *) call the API. Off by default.
--queue-timeout SECSTurn away a request still queued after this long, with 503 and Retry-After. Off by default.
--chat-templateauto (default) | plain | chatml | llama3 | llama2 | mistral | gemma | gemma4 | phi3 | deepseek.
--eos-tokenStop on this token id — overrides the eos_token_id auto-detected from config.json.
--prefix-cache-sizeCache N prompt prefixes so shared prefixes skip re-prefill (GPU default 64; off on the CPU unless set).
--prefix-cache-dir DIRAlso keep cached prefixes on disk, so a long system prompt is prefilled once, not once per start.
--mmproj FILEThe vision tower for a Gemma 3 GGUF (llama.cpp's mmproj file). Defaults to the one mmproj*.gguf beside the model.
--embedding-pooling auto | last | meanHow /v1/embeddings pools tokens. auto (default) follows a sentence-transformers 1_Pooling/config.json, else the last token.
--multi-gpu-idsPipeline-parallel across local GPUs, e.g. 0,1,2.
--distributed-modemaster --worker-nodes … coordinates shards; worker serves one shard over TCP.
The rest — --lm-head-int4, --expert-cache-gb, --telemetry, --worker-timeout-secs, --cluster-secret — are on serve configuration, every flag grouped with its default.

bench

Measure a model’s speed. It loads the model exactly as serve would with the same flags (--quant, --stream, --gpu-layers, --device, --kv-quant, …), then runs a fixed workload instead of opening a port. Server-only flags (--port, --api-key, …) are accepted and ignored.

$dlm bench --model-path ./models/Qwen2.5-0.5B-Instruct --quant int4 --context-length 1024 --prompt-len 512 --gen-len 64 --batch 1,4 --json out.json

For each batch size it reports prefill tok/s, time to first token, and decode tok/s and ms per step, plus peak RSS and, on a GPU, VRAM in use.

FlagPurpose
--prompt-lenPrompt tokens prefilled per sequence (default 512).
--gen-lenTokens decoded per sequence (default 128).
--batchConcurrent sequences to measure, comma-separated, e.g. 1,4,8 (default 1).
--runsRepetitions per batch size; the summary reports the median (default 3).
--json FILEAlso write the results as JSON.
--compare FILECompare against a baseline written by --json: print each metric's change, and exit non-zero if prefill or decode tok/s fell by more than --tolerance at any batch size both runs measured.
--tolerance PCTHow far throughput may fall below the baseline before it counts as a regression (default 5).
--temperatureSample at this temperature instead of decoding greedily (default 0, greedy).
--top-p / --top-kNucleus and top-k cut-offs, with --temperature (defaults 1.0 and 0: off).
--breakdownSplit streamed decode time by stage (disk read, RAM cache, pinned staging, H2D, compute). Off by default: timing the stages has a cost of its own.
bench decodes plainly unless you pass --speculative ngram or mtp, or an EAGLE-3 head as --draft-model-path — auto would speculate on the GPU and move the numbers a baseline is compared against. A plain draft model and --distributed-mode are refused.

pack

Quantize a safetensors model once, ahead of time. Streaming a model at --quant int4/int8 otherwise re-quantizes every layer that misses the RAM cache, from 16-bit weights read off disk. A pack is an ordinary model directory (config, tokenizer, templates) whose weights are stored exactly as --quant would produce them, so it scores bit for bit what the original does at that precision, from about half the disk.

$dlm pack --model-path models/Qwen3-1.7B --quant int4 --out models/Qwen3-1.7B-int4
$dlm serve --model-path models/Qwen3-1.7B-int4 --stream
FlagPurpose
--model-path DIRThe safetensors model directory to pack.
--quant int4 | int8Precision to store the weights at. The pack loads only at this precision; omitting --quant when loading picks it.
--out DIRDirectory to write the pack into (new, or empty).
On a GTX 1650, streaming Qwen3-1.7B at int4 with four layers resident and no RAM cache, decode went from 0.06–0.07 to 1.0–1.1 tok/s and prefill from 4–5 to 48–65 tok/s. GGUF and GPTQ checkpoints need no pack (already quantized), and weights the loader slices by rows (Phi-3’s fused QKV, Qwen3.5’s stacked experts) stay 16-bit in one.

generate

Drive the full generation loop (embedding → transformer stack → LM head → sampling) end to end. Point it at a real checkpoint to run on CPU, or pass raw ids / text against a synthetic model.

$dlm generate --model-path /path/to/small-model --text "Hello"
$dlm generate --prompt 1,2,3 --max-new-tokens 8 --seed 42
$dlm generate --model-path models/gemma-3-4b-it-Q4_K_M.gguf --image photo.jpg --text "Describe this image."
FlagPurpose
--model-pathLoad a real model from this directory (config.json + safetensors).
--textPrompt as text, tokenized with the BPE tokenizer. Overrides --prompt.
--promptPrompt as comma-separated token ids (default 1).
--tokenizerTokenizer directory. Defaults to the model directory if it has one, else a raw byte tokenizer.
--max-new-tokensNumber of new tokens to generate (default 16).
--image FILEA PNG or JPEG for a model with a vision tower (Gemma 3 4B+); repeat for several. --text is then the user's message, rendered with Gemma's chat template.
--mmproj FILEThe vision tower for a GGUF model. Defaults to the one mmproj*.gguf beside the model file.
--eos-tokenStop when this token id is produced.
--temperatureSampling temperature. Unset (or 0) decodes greedily.
--top-pNucleus sampling cut-off (default 1.0: off). Needs --temperature.
--top-kKeep only the k most likely tokens (default 0: off). Needs --temperature.
--seedPRNG seed for the synthetic weights and for sampling (default 0).
--device gpu | cpuCompute device. Defaults to gpu on a cuda-kernels build, else cpu.

generate also prints prefill and decode speed to stderr.

The synthetic-model geometry flags (--vocab-size, --hidden-size, --num-layers, --num-heads, --num-kv-heads, --intermediate-size) are ignored when --model-path is set.
On a cuda-kernels build, generation runs on the GPU by default; --device cpu forces the CPU kernel. A CPU-only build defaults to CPU, and an explicit --device gpu there errors clearly.

score

Score a text against a model: the log-probability it gives each token, the mean negative log-likelihood, and what it would generate next. Log-probabilities catch a model that is subtly wrong long before its greedy output stops reading well; tools/hf_parity.py in the engine repo compares the JSON against Hugging Face transformers.

$dlm score --model-path models/qwen2.5-0.5b --text "The capital of France is Paris." --top 3
$ dlm score --model-path models/qwen2.5-0.5b --text "The capital of France is Paris." --top 3
mean nll     : 2.8240
     token     logprob  piece
      6722    -10.1571  " capital"
       315     -0.3176  " of"
      …
next token, most likely first:
      1084     -1.7398  " It"
       576     -2.0015  " The"
     12095     -2.2036  " Paris"
FlagPurpose
--model-pathModel to score.
--textText to score, tokenized with the model's tokenizer.
--promptText as comma-separated token ids, for a model whose tokenizer dlm does not read.
--tokenizerTokenizer directory. Defaults to the model directory.
--top NHow many of the most likely next tokens to report (default 20).
--json FILEWrite the scores as JSON instead of a table on stdout.
--quant int4 | int8Score the model quantized at load, to measure what that costs in log-likelihood.
--kv-quantKV precision to score with. Exact f32 by default, so the scores stay a parity reference.
--decodeRun the text through one token at a time, as generation does. On the GPU this scores the decode kernels rather than prefill's.
--lora DIRMerge a LoRA adapter, as for serve.
--device gpu | cpuCompute device. Defaults to gpu on a cuda-kernels build, else cpu.

tokenize

Show the byte-level BPE encoder round-trip — encode text to ids and decode back.

$dlm tokenize --text "Hello, world!"
$ dlm tokenize --text "Hello, world!"
  ids        : [72, 101, 108, 108, 111, 44, 32, ...]
  round-trip : "Hello, world!" (ok)
FlagPurpose
--tokenizerDirectory with vocab.json + merges.txt. Defaults to a raw byte tokenizer (256 tokens, no merges).

doctor

Report the GPU backend and free VRAM, run a CPU inference self-check, and — on a cuda-kernels build with a GPU present — run a live CPU-vs-GPU parity probe.

$dlm doctor --model-path /path/to/model

completions

Print a shell completion script to stdout for bash, zsh, fish, elvish, or powershell. Redirect it into your shell’s completions directory — see Installation.

$dlm completions bash > ~/.local/share/bash-completion/completions/dlm