CLI reference#
This section describes the unified Primus launcher (runner/primus-cli) and how it invokes the Python CLI (primus/cli/main.py). For deeper background, see CLI architecture.
Command structure#
primus-cli [global-options] <mode> [mode-args] -- [command]
Global options go before the mode name and they affect configuration loading and logging for the whole run.
Mode is one of
direct,container, orslurm.--(required) separates launcher options from the Primus Python CLI. Everything after the first--is passed toprimus/cli/main.py(or another script if you override it in direct mode).
From the repository root, invoke the launcher as ./runner/primus-cli (or install or link it as primus-cli on your PATH).
Global options#
These flags are parsed in runner/primus-cli before the mode name is read and passed on to runner/primus-cli-<mode>.sh.
Option |
Description |
|---|---|
|
Load a YAML file for launcher defaults (see Configuration precedence). |
|
Verbose logging; sets |
|
Print the command that would run and exit without executing the mode script. |
|
Print the CLI version and exit. |
|
Show top-level usage and exit. |
Mode-specific help:
./runner/primus-cli direct --help
./runner/primus-cli container --help
./runner/primus-cli slurm --help
Primus Python CLI help (after --):
./runner/primus-cli direct -- --help
./runner/primus-cli direct -- train --help
./runner/primus-cli direct -- benchmark --help
Direct mode#
Run training, benchmarks, or diagnostics on the current host (or inside an environment you already prepared). GPU-specific tuning is applied via runner/helpers/envs/<GPU_MODEL>.sh when present.
Syntax#
primus-cli direct [options] -- <command>
Options#
Option |
Description |
|---|---|
|
Launcher YAML (same resolution as global |
|
Debug logging for the direct launcher. |
|
Show the resolved command that would be launched without running training. |
|
Run with |
|
Python entry script (default: |
|
Set an environment variable before launch (repeatable). A path without |
|
Run a shell snippet before the main script (repeatable). |
|
Redirect logs to a file. |
|
Force NUMA binding on. |
|
Force NUMA binding off. |
Distributed environment variables#
For multi-node or multi-process runs, set these via export or --env:
Variable |
Role |
Typical default |
|---|---|---|
|
Number of nodes |
|
|
Rank of this node |
|
|
GPUs per node |
|
|
Hostname or IP of rank 0 |
|
|
TCP port for the process group |
|
Container mode#
Run the same Python CLI inside Docker or Podman with ROCm-oriented defaults from runner/.primus.yaml.
Syntax#
primus-cli container [options] -- <command>
Common options#
Option |
Description |
|---|---|
|
Image tag (default from config: |
|
Bind mount (repeatable). |
|
Pass into the inner |
|
Extra device nodes (repeatable; defaults include GPU/RDMA devices). |
|
Standard container runtime options. |
|
Remove all containers before launch. |
|
CPU limit. |
|
Memory limit (e.g. |
|
Shared memory size. |
|
GPU limit (when using a runtime that supports this flag). |
Auto-mounted devices#
When using runner/.primus.yaml, the default container section includes:
/dev/kfd—ROCm kernel fusion driver/dev/dri—GPU render nodes/dev/infiniband—InfiniBand character devices (when present)
Environment forwarding#
container.options.env in runner/.primus.yaml lists names that are forwarded into the container as inner --env arguments when the variable is set in the host environment (for example MASTER_ADDR, HF_TOKEN, NCCL_SOCKET_IFNAME). The container script also auto-forwards host variables whose names start with PRIMUS_, NCCL_, RCCL_, GLOO_, IONIC_, or HIPBLASLT_ when not already listed.
Slurm mode#
Launch distributed jobs with srun or sbatch. The Slurm launcher builds srun or sbatch flags, merges them with slurm.* entries from the loaded YAML, then runs runner/primus-cli-slurm-entry.sh on allocated nodes.
Syntax#
primus-cli slurm [--config FILE] [--debug] [--dry-run] [srun|sbatch] [SLURM_FLAGS...] -- <command>
Part |
Meaning |
|---|---|
First |
Separates Slurm launcher flags from the Primus Python CLI command (for example |
Default launcher |
If you omit |
Examples#
# Interactive multi-node training
./runner/primus-cli slurm srun -N 4 -p gpu -- train pretrain --config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
# Batch job
./runner/primus-cli slurm sbatch -N 8 -t 8:00:00 -o train.log -- train pretrain --config exp.yaml
On each node, primus-cli-slurm-entry.sh sets NNODES, NODE_RANK, GPUS_PER_NODE, MASTER_ADDR, and MASTER_PORT from Slurm and invokes primus-cli-container.sh with matching --env injections (see runner/primus-cli-slurm-entry.sh). Container options such as --image should come from runner/.primus.yaml or the launcher config file rather than appearing as an inner container command after the Slurm separator.
Python subcommands (after --)#
These run under primus/cli/main.py unless you change --script in direct mode.
Subcommand |
Purpose |
|---|---|
|
Pretraining (Megatron-LM, TorchTitan, MaxText, Megatron Bridge, etc., per configuration YAML). |
|
Post-training (SFT or LoRA-style workflows; same top-level flags as pretrain in the parser). |
|
Performance microbenchmarks (see table below). |
|
Cluster and node diagnostics. |
|
Memory estimation from a merged config. |
|
Performance projection from a merged config. |
|
Single benchmark → both performance and memory projections (cluster sizing). |
Benchmark suites#
Implemented in primus/cli/subcommands/benchmark.py:
Suite |
Notes |
|---|---|
|
General GEMM microbenchmark. |
|
Dense GEMM variant. |
|
DeepSeek-style dense GEMM. |
|
Communication microbenchmark. |
|
RCCL collective microbenchmark. |
The same file also registers an attention suite for attention microbenchmarks.
Configuration precedence (launcher YAML)#
Resolution is implemented in runner/lib/config.sh (functions resolve_config_file and load_config_auto):
--config FILEon the command line (if given).~/.primus.yamlif it exists.runner/.primus.yaml(system default).
Within a chosen file, nested keys follow normal YAML structure. Slurm and container scripts merge CLI flags with their sections so that explicit CLI arguments override file values where applicable.
Note: This precedence applies to the shell launcher YAML. Training YAML merge order for configurations is documented in Configuration system.
Common examples#
Goal |
Example |
|---|---|
Direct pretrain |
|
Direct GEMM |
|
Container pretrain |
|
Slurm training |
|
Preflight (fast) |
|
Inspect launch command |
|
Dry-run Slurm |
|
Exit codes#
From runner/primus-cli:
Code |
Meaning |
|---|---|
0 |
Success |
1 |
Library or dependency failure |
2 |
Invalid arguments or configuration |
3 |
Runtime execution failure |