CLI reference
EngineSurogate EngineSurogate has a small CLI, with one subcommand per workflow.
Synopsis
Section titled “Synopsis”surogate <command> config.yaml [--hub_token <token>]If the YAML config file is missing, the CLI prints help and exits with a non-zero status.
Commands
Section titled “Commands”Supervised fine-tuning. New to it? Start with Quickstart: SFT.
surogate sft examples/sft/qwen3/qwen3-lora-bf16.yamlOptions:
--hub_token <token>: optional, Hugging Face token for private model access
Offline Direct Preference Optimization on {prompt, chosen, rejected} pairs. See Quickstart: DPO and the DPO settings.
surogate dpo path/to/config.yamlOptions:
--hub_token <token>: optional, Hugging Face token for private model access
GRPO RL training with the inference server and the trainer on separate (disjoint) GPU sets. They communicate over the filesystem. The RL Training guide explains the setup.
surogate grpo --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml \ --infer-gpus 0,1 --trainer-gpus 2,3Options:
--train <path>: required, trainer config YAML--infer <path>: required, inference server config YAML--orch <path>: required, orchestrator config YAML--infer-gpus <ids>: required, comma-separated GPU ids for the inference server. Count must equalinfer.dp * infer.tp--trainer-gpus <ids>: required, comma-separated GPU ids for the trainer. Count must equaltrain.gpus, which therefore becomes optional in the YAML--judge-infer <path>: optional, inference config for a RULER judge server. With--judge-gpusandruler.enabled: trueinorch.yaml, a second server subprocess is spawned for the judge--judge-gpus <ids>: optional, GPU ids for the judge. Must be disjoint from--infer-gpusand--trainer-gpus
grpo-colocate
Section titled “grpo-colocate”Same three configs, but serving and training alternate on one GPU with a single resident copy of the base weights, shared between them. See Single-GPU GRPO.
surogate grpo-colocate --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yamlOptions: --train, --infer, --orch (all required). There are no GPU-assignment flags:
the components share the visible GPU.
grpo-infer
Section titled “grpo-infer”Runs only the inference server. Use it for multi-node setups, or whenever you want each
component in its own process. This is surogate serve with the LoRA hot-load admin routes the trainer broadcasts into.
CUDA_VISIBLE_DEVICES=0 surogate grpo-infer infer.yamlgrpo-orch
Section titled “grpo-orch”Runs only the orchestrator. It samples rollouts against the environments, scores them and writes batches to the transport.
surogate grpo-orch orch.yamlgrpo-train
Section titled “grpo-train”Runs only the trainer. It consumes batches, applies GRPO updates and broadcasts weights.
It resumes from the latest checkpoint in checkpoint_dir automatically; see
GRPO (RL) Settings.
CUDA_VISIBLE_DEVICES=1 surogate grpo-train train.yamlPretraining. See Quickstart: Pretraining.
surogate pt examples/pt/qwen3.yamlOptions:
--hub_token <token>: optional, Hugging Face token for private model access
tokenize
Section titled “tokenize”Tokenize datasets for training.
surogate tokenize <path/to/config.yaml>Options:
--debug: print tokens with labels to confirm masking/ignores--hub_token <token>: optional, Hugging Face token for private model access
distill-capture
Section titled “distill-capture”Capture teacher top-K logprobs for offline knowledge distillation. Writes a .kd sidecar next to each tokenized train-*.bin shard; a following surogate sft run with the same config trains against them. See the Knowledge Distillation guide.
surogate distill-capture examples/distillation/qwen3-kd.yamlOptions:
--api-base <url>: OpenAI-compatible base URL of a served teacher, e.g.http://localhost:8000/v1(overridesdistillation.teacher_api_base). Requires a vLLM-compatible server started with--max-logprobs >= distillation.top_k--device <device>: device to run the local teacher model on (defaultcuda:0); ignored with a warning in API mode--hub_token <token>: optional, Hugging Face token for private model access
transplant-tokenizer
Section titled “transplant-tokenizer”Transplant a teacher’s tokenizer onto a student model for cross-tokenizer distillation (wraps mergekit-tokensurgeon as an external subprocess; requires pip install mergekit). The output model uses the teacher’s tokenizer, so the standard KD pipeline runs unchanged against it. See Cross-tokenizer distillation.
surogate transplant-tokenizer --student Qwen/Qwen3-8B --teacher deepseek-ai/DeepSeek-V3 \ --output ./qwen3-8b-dsv3-vocabOptions:
--student <model>: student model directory or HuggingFace ID (the model to be trained). Required unless--restore(where it is the KD-trained model to convert back)--teacher <model>: teacher model directory or HuggingFace ID (tokenizer donor). Required unless--restore--output <dir>: required, output directory for the transplanted model--method <name>: approximation method for new vocabulary rows (defaultomp, recommended)--k <int>: sparsity level / neighbor count for the approximation (default64)--device <device>: device for the approximation solve (e.g.cuda)--trust-remote-code: pass--trust-remote-codetomergekit-tokensurgeon--restore <manifest>: reverse mode, path to atransplant_manifest.json; transplants the distilled model (given via--student) back to the original student tokenizer
Merge a LoRA checkpoint into the base model, producing a ready-to-serve model directory.
surogate merge \ --base-model Qwen/Qwen3.5-0.8B \ --checkpoint-dir ./output_q35/step_00000002 \ --output ./merged_q35Options:
--base-model <path>: required, path to base model directory or HuggingFace model ID--checkpoint-dir <path>: required, path to a LoRA checkpoint directory (e.g.output/step_00000050)--output <path>: required, output directory for the merged model
Every LoRA pair of the adapter must land on a tensor of the base model. Per-expert adapters merge into
checkpoints that store their routed experts fused per layer (experts.gate_up_proj / experts.down_proj,
as Qwen3.5/3.6-MoE and GPT-OSS ship them), and the adapter’s model.layers.* / mlp.shared_experts.*
names are matched to the checkpoint’s own (model.language_model.layers.*, mlp.shared_expert.*). If any
pair has no target, or does not fit the tensor it names, the merge exits non-zero and writes nothing:
the output is assembled next to --output and moved into place only when complete. Tensors no pair
targets keep their exact bytes.
quantize
Section titled “quantize”Quantize a checkpoint into a GGUF the engine can serve. A downloaded GGUF model needs
nothing; this command is for a model you trained here, which has no GGUF yet. Run it after merge. Serving models shows how to serve the result.
surogate quantize \ --model ./merged_q35 \ --output ./merged_q35-Q4_K_M.gguf \ --type q4_k_mThe quantisation arithmetic is llama.cpp’s, in two passes: the checkpoint becomes a BF16 GGUF,
which is then quantised to the requested type. The intermediate is deleted unless you keep it. It
takes two bytes per parameter, so the command first checks there is room beside --output.
Options:
--model <path>: required, a Hugging Face checkpoint directory or an unquantised.gguf--output <path>: required, output.ggufpath--type <name>: quantization type, defaultq4_k_m--threads <int>: quantizer threads, default the CPU count--imatrix <file>: importance matrix passed to the quantizer; the IQ types require one--keep-intermediate: keep the BF16 GGUF the first pass writes--llama-cpp <dir>: llama.cpp checkout to drive (default$SUROGATE_LLAMA_CPP, else vendored)--build: build the quantizer if it is missing, instead of failing with the command to run
- The top-level CLI prints system diagnostics at startup (GPU, CUDA, etc.).
See also
Section titled “See also”- Config reference: every option the YAML configs above accept
- Python API: drive the trainer from Python instead
- Back to docs index