Skip to content
SurogateSurogateDocs
↑↓ to move↵ to openesc to close

CLI reference

Surogate has a small CLI, with one subcommand per workflow.

bash
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.

Supervised fine-tuning. New to it? Start with Quickstart: SFT.

bash
surogate sft examples/sft/qwen3/qwen3-lora-bf16.yaml

Options:

  • --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.

bash
surogate dpo path/to/config.yaml

Options:

  • --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.

bash
surogate grpo --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml \
--infer-gpus 0,1 --trainer-gpus 2,3

Options:

  • --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 equal infer.dp * infer.tp
  • --trainer-gpus <ids>: required, comma-separated GPU ids for the trainer. Count must equal train.gpus, which therefore becomes optional in the YAML
  • --judge-infer <path>: optional, inference config for a RULER judge server. With --judge-gpus and ruler.enabled: true in orch.yaml, a second server subprocess is spawned for the judge
  • --judge-gpus <ids>: optional, GPU ids for the judge. Must be disjoint from --infer-gpus and --trainer-gpus

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.

bash
surogate grpo-colocate --train examples/grpo/train.yaml --infer examples/grpo/infer.yaml --orch examples/grpo/orch.yaml

Options: --train, --infer, --orch (all required). There are no GPU-assignment flags: the components share the visible GPU.

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.

bash
CUDA_VISIBLE_DEVICES=0 surogate grpo-infer infer.yaml

Runs only the orchestrator. It samples rollouts against the environments, scores them and writes batches to the transport.

bash
surogate grpo-orch orch.yaml

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.

bash
CUDA_VISIBLE_DEVICES=1 surogate grpo-train train.yaml

Pretraining. See Quickstart: Pretraining.

bash
surogate pt examples/pt/qwen3.yaml

Options:

  • --hub_token <token>: optional, Hugging Face token for private model access

Tokenize datasets for training.

bash
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

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.

bash
surogate distill-capture examples/distillation/qwen3-kd.yaml

Options:

  • --api-base <url>: OpenAI-compatible base URL of a served teacher, e.g. http://localhost:8000/v1 (overrides distillation.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 (default cuda:0); ignored with a warning in API mode
  • --hub_token <token>: optional, Hugging Face token for private model access

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.

bash
surogate transplant-tokenizer --student Qwen/Qwen3-8B --teacher deepseek-ai/DeepSeek-V3 \
--output ./qwen3-8b-dsv3-vocab

Options:

  • --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 (default omp, recommended)
  • --k <int>: sparsity level / neighbor count for the approximation (default 64)
  • --device <device>: device for the approximation solve (e.g. cuda)
  • --trust-remote-code: pass --trust-remote-code to mergekit-tokensurgeon
  • --restore <manifest>: reverse mode, path to a transplant_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.

bash
surogate merge \
--base-model Qwen/Qwen3.5-0.8B \
--checkpoint-dir ./output_q35/step_00000002 \
--output ./merged_q35

Options:

  • --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 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.

bash
surogate quantize \
--model ./merged_q35 \
--output ./merged_q35-Q4_K_M.gguf \
--type q4_k_m

The 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 .gguf path
  • --type <name>: quantization type, default q4_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.).