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.
| Command | What it does |
|---|---|
search | Find models on the Hugging Face hub. |
pull | Download a model locally (via curl). |
profile | Compute the VRAM plan — no GPU needed. |
serve | Start the OpenAI-compatible HTTP server. |
bench | Measure prefill and decode speed, loaded as serve would load it. |
pack | Write a copy of a safetensors model with its weights already quantized. |
generate | Run the CPU (or GPU) generation loop, with images for Gemma 3. |
score | Log-probability of each token of a text, and the likely next tokens. |
tokenize | Byte-level BPE encode/decode round-trip. |
doctor | Check the machine + run a self-test. |
completions | Print a shell completion script. |
search
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| Flag | Purpose |
|---|---|
--limit | Maximum results to show (default 20). |
--gguf | List 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-Instructdlm pull Qwen/Qwen2.5-0.5B-Instruct-GGUF --file q4_k_m| Flag | Purpose |
|---|---|
--local-dir | Change where the model lands (default ./models/<model>; ./models/gguf for a --file download). |
--token | Auth for gated/private repos (or set $HF_TOKEN). |
--file | Fetch one .gguf file out of the repo, by its full name or any part of it (--file q4_k_m). |
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)
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.
| Flag | Purpose |
|---|---|
--model-path | Model directory to profile. Omit for the built-in 70B-class sample. |
--context-length | Target context window in tokens (default 8192). |
--quant int4 | int8 | Weight precision to plan against. Defaults to the checkpoint's own dtype. |
--vram-budget-gb | Manual upper VRAM cap. Overrides the live device query. |
--safety-margin-gb | VRAM 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-gb | Host-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| Flag | Purpose |
|---|---|
--model-path | Directory with config.json + *.safetensors, or a .gguf file. |
--quant int4 | int8 | The 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-gb | Manual upper VRAM cap. Overrides the live device query. |
--safety-margin-gb | VRAM 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-gb | Host-RAM layer cache — roughly 2x on the streamed path. On by default with --stream when every layer fits in a quarter of RAM. |
--port | TCP port (default 8000). |
--host | Bind address (default 127.0.0.1). |
--context-length | KV 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 N | Hold 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 N | CPU streaming: prefetch N layers ahead (default 1; 0 disables). Clamped to window − 1. |
--auto-prefetch | CPU streaming: auto-tune the prefetch depth from measured load-vs-compute time. |
--kv-quant auto | f16 | f32 | int8 | int4 | KV cache precision. auto (default) is int8 on the GPU and f32 on the CPU kernels. |
--device gpu | cpu | Compute device. Defaults to gpu on a cuda-kernels build; falls back to CPU with a warning if no GPU is usable. |
--max-batch N | Requests decoded concurrently (default 8). |
--speculative auto | off | ngram | draft | mtp | Speculative 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-path | Speculate with a draft model, or an EAGLE-3 head (a directory whose config.json names an *Eagle3 architecture; resident GPU only). |
--draft-gamma N | Tokens proposed per speculative round, by the draft model or n-gram lookup (default 4). |
--lora DIR | Merge a PEFT LoRA adapter into the weights as they load. |
--api-key | Require a key on every route except the /, /health and /healthz liveness probes — /metrics included. Sent as Authorization: Bearer or x-api-key. |
--cors-origin | Let browsers on this origin (or *) call the API. Off by default. |
--queue-timeout SECS | Turn away a request still queued after this long, with 503 and Retry-After. Off by default. |
--chat-template | auto (default) | plain | chatml | llama3 | llama2 | mistral | gemma | gemma4 | phi3 | deepseek. |
--eos-token | Stop on this token id — overrides the eos_token_id auto-detected from config.json. |
--prefix-cache-size | Cache N prompt prefixes so shared prefixes skip re-prefill (GPU default 64; off on the CPU unless set). |
--prefix-cache-dir DIR | Also keep cached prefixes on disk, so a long system prompt is prefilled once, not once per start. |
--mmproj FILE | The 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 | mean | How /v1/embeddings pools tokens. auto (default) follows a sentence-transformers 1_Pooling/config.json, else the last token. |
--multi-gpu-ids | Pipeline-parallel across local GPUs, e.g. 0,1,2. |
--distributed-mode | master --worker-nodes … coordinates shards; worker serves one shard over TCP. |
--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.jsonFor 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.
| Flag | Purpose |
|---|---|
--prompt-len | Prompt tokens prefilled per sequence (default 512). |
--gen-len | Tokens decoded per sequence (default 128). |
--batch | Concurrent sequences to measure, comma-separated, e.g. 1,4,8 (default 1). |
--runs | Repetitions per batch size; the summary reports the median (default 3). |
--json FILE | Also write the results as JSON. |
--compare FILE | Compare 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 PCT | How far throughput may fall below the baseline before it counts as a regression (default 5). |
--temperature | Sample at this temperature instead of decoding greedily (default 0, greedy). |
--top-p / --top-k | Nucleus and top-k cut-offs, with --temperature (defaults 1.0 and 0: off). |
--breakdown | Split 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-int4dlm serve --model-path models/Qwen3-1.7B-int4 --stream| Flag | Purpose |
|---|---|
--model-path DIR | The safetensors model directory to pack. |
--quant int4 | int8 | Precision to store the weights at. The pack loads only at this precision; omitting --quant when loading picks it. |
--out DIR | Directory to write the pack into (new, or empty). |
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 42dlm generate --model-path models/gemma-3-4b-it-Q4_K_M.gguf --image photo.jpg --text "Describe this image."| Flag | Purpose |
|---|---|
--model-path | Load a real model from this directory (config.json + safetensors). |
--text | Prompt as text, tokenized with the BPE tokenizer. Overrides --prompt. |
--prompt | Prompt as comma-separated token ids (default 1). |
--tokenizer | Tokenizer directory. Defaults to the model directory if it has one, else a raw byte tokenizer. |
--max-new-tokens | Number of new tokens to generate (default 16). |
--image FILE | A 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 FILE | The vision tower for a GGUF model. Defaults to the one mmproj*.gguf beside the model file. |
--eos-token | Stop when this token id is produced. |
--temperature | Sampling temperature. Unset (or 0) decodes greedily. |
--top-p | Nucleus sampling cut-off (default 1.0: off). Needs --temperature. |
--top-k | Keep only the k most likely tokens (default 0: off). Needs --temperature. |
--seed | PRNG seed for the synthetic weights and for sampling (default 0). |
--device gpu | cpu | Compute device. Defaults to gpu on a cuda-kernels build, else cpu. |
generate also prints prefill and decode speed to stderr.
--vocab-size, --hidden-size, --num-layers, --num-heads, --num-kv-heads, --intermediate-size) are ignored when --model-path is set.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"
| Flag | Purpose |
|---|---|
--model-path | Model to score. |
--text | Text to score, tokenized with the model's tokenizer. |
--prompt | Text as comma-separated token ids, for a model whose tokenizer dlm does not read. |
--tokenizer | Tokenizer directory. Defaults to the model directory. |
--top N | How many of the most likely next tokens to report (default 20). |
--json FILE | Write the scores as JSON instead of a table on stdout. |
--quant int4 | int8 | Score the model quantized at load, to measure what that costs in log-likelihood. |
--kv-quant | KV precision to score with. Exact f32 by default, so the scores stay a parity reference. |
--decode | Run the text through one token at a time, as generation does. On the GPU this scores the decode kernels rather than prefill's. |
--lora DIR | Merge a LoRA adapter, as for serve. |
--device gpu | cpu | Compute 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)
| Flag | Purpose |
|---|---|
--tokenizer | Directory 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- Without
--model-pathit checks the machine and runs the self-test only. - With it, dlm also confirms the checkpoint loads and tokenizes.
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