Pretraining workflows#
Primus is a YAML-driven training stack for AMD GPUs. You select a backend (Megatron-LM, TorchTitan, JAX MaxText, Megatron Bridge), point train pretrain at a configuration YAML, and launch Primus with the unified CLI (runner/primus-cli) in direct, container, or Slurm mode. See CLI reference and Configuration system.
This section helps you understand concepts related to the Primus workflow: how backends work, YAML structure and inheritance, parallelism vocabulary, the full per-backend configuration inventory, and so on. If you already understand the concepts and just need the specific commands to run your training with Primus, see Backend training recipes.
Overview#
The following table describes the four backend types supported by Primus and their typical uses.
Backend |
Framework |
Typical use |
|---|---|---|
Megatron-LM |
|
Large-scale transformer pretraining with Megatron-style parallelism (TP/PP/EP). |
TorchTitan |
|
PyTorch-native scaled training (FSDP / tensor / pipeline / expert parallelism per config). |
MaxText (JAX) |
|
JAX/MaxText single- and multi-node runs; parallelism via MaxText |
Megatron Bridge |
|
Bridge-oriented workflows (configure like other backends; see parameter reference). |
Several setup steps apply to all backends (mock vs. real data, Hugging Face tokens, scaling to multiple nodes, and HipBLASLt autotuning). After you read the backend section that applies to you, see Common patterns below.
Megatron-LM pretraining#
Quick start (container mode)#
From the root of the clone of the Primus repository, with Docker or Podman available, the following command starts the training in container mode:
./runner/primus-cli container -- train pretrain \
--config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
This uses the default image from runner/.primus.yaml (rocm/primus:v26.4 unless overridden). The project tree is mounted into the container automatically by runner/primus-cli-container.sh.
Example configurations under examples/megatron/configs/MI300X/#
The following files ship in the repository (sorted by name). Parallelism columns are taken from tensor_model_parallel_size / pipeline_model_parallel_size / expert_model_parallel_size in each file (literals or ${PRIMUS_TP:…} defaults).
Config |
TP |
PP |
EP |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sample YAML file (llama2_7B-BF16-pretrain.yaml) explained#
Path: examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
Section |
Role |
|---|---|
|
Run identity and output root (supports |
|
|
|
Module preset under |
|
Model preset under |
|
Run-specific training knobs: iterations, batching, LR, parallelism ( |
The sample sets mock_data: true and train_data_path: null so you can validate the stack without real corpora.
Mock data versus real data#
Mock data: Set
mock_data: trueand leavetrain_data_path/valid_data_pathempty (as inllama2_7B-BF16-pretrain.yaml).Real data: Set
mock_data: falseand populate Megatron-compatible data paths (and tokenizer assets) inoverrides. Use paths visible inside your container mounts.
Multi-node training with Slurm#
./runner/primus-cli slurm srun -N 4 -p <partition> -- train pretrain \
--config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
runner/primus-cli-slurm-entry.sh derives MASTER_ADDR, NNODES, and NODE_RANK from Slurm and forwards them into the container. Align tensor_model_parallel_size, pipeline_model_parallel_size, and expert_model_parallel_size with your cluster width and job size.
TorchTitan pretraining#
Quick start#
./runner/primus-cli container -- train pretrain \
--config examples/torchtitan/configs/MI300X/llama3.1_8B-BF16-pretrain.yaml
Example configurations under examples/torchtitan/configs/MI300X/#
File |
|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sample YAML file (llama3.1_8B-BF16-pretrain.yaml) explained#
Path: examples/torchtitan/configs/MI300X/llama3.1_8B-BF16-pretrain.yaml
Section |
Role |
|---|---|
|
Selects the TorchTitan integration. |
|
Module preset under |
|
Model preset under |
|
Run-specific batching, steps, checkpointing, and Turbo options. |
Some configurations omit an explicit parallelism: block; in that case the default values come from the module and model presets (primus/configs/modules/torchtitan/pre_trainer.yaml and the chosen model YAML). Other examples (for example DeepSeek and Qwen) set parallelism: inline with tensor_parallel_degree, pipeline_parallel_degree, expert_parallel_degree, etc.
MaxText (JAX) pretraining#
Quick start#
./runner/primus-cli container -- train pretrain \
--config examples/maxtext/configs/MI300X/llama2_7B-pretrain.yaml
JAX-specific requirements#
Install JAX/MaxText dependencies from the repository root:
pip install -r requirements-jax.txt
Example configurations under examples/maxtext/configs/MI300X/#
File |
Key parallelism ( |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The llama2_7B-pretrain.yaml example also sets dataset_type: "synthetic" and hf_access_token: ${HF_TOKEN:""} for gated Hugging Face assets when you switch to real data.
Common patterns#
Testing with mock data#
Set mock_data: true (Megatron/TorchTitan) or synthetic dataset settings (MaxText) to validate the configurations and infrastructure without I/O-heavy datasets.
Real training data#
Megatron: Configure
train_data_path/valid_data_pathand tokenizer assets inoverridesoncemock_datais false.For all backends, ensure host paths are mounted in container mode (
--volumeorcontainer.options.volumein YAML).TorchTitan/MaxText: Follow backend-specific dataset fields in the
overridesand presets.
Scaling from single-node to multi-node#
Use Slurm mode for allocation; keep the container entry if you want the same image on every node.
Set environment variables consistently (
NNODES,NODE_RANK,MASTER_ADDR,MASTER_PORT,GPUS_PER_NODE); the Slurm entry script injects them when usingprimus-cli slurm.Increase values in the parallelism fields (Megatron TP/PP/EP; TorchTitan
parallelism; MaxTextici_*/dcn_*) to match topology.
Hugging Face token for gated models#
Export HF_TOKEN on the host before launching container mode; runner/.primus.yaml lists HF_TOKEN under container.options.env so it can be forwarded into the container. MaxText configurations may reference ${HF_TOKEN:""} directly.
hipBLASLt autotuning (three stages)#
Controlled with PRIMUS_HIPBLASLT_TUNING_STAGE (see examples/README.md):
Stage |
Purpose |
|---|---|
1 |
Dump GEMM shapes seen during training (reduce |
2 |
Tune kernels from dumped shapes (offline tooling under |
3 |
Train using tuned kernel artifacts from |
Example (from in-repo docs):
export PRIMUS_HIPBLASLT_TUNING=1 # master switch (required; tuning is skipped without it)
export PRIMUS_HIPBLASLT_TUNING_STAGE=1
./runner/primus-cli direct -- train pretrain \
--config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
Supported models#
The tables above in the Megatron, TorchTitan, and MaxText sections are curated MI300X examples from the Primus repository. Use examples/<backend>/configs/ in the repository as the authoritative inventory, as new presets and hardware-specific examples may be added there before this document is updated to reflect their additions.
Backend |
Example region |
Parallelism vocabulary |
|---|---|---|
Megatron-LM |
|
|
TorchTitan |
|
|
MaxText |
|
|
For scripting patterns that predate primus-cli, the repository still documents examples/run_local_pretrain.sh and examples/run_slurm_pretrain.sh in examples/README.md; equivalent launches are shown above using ./runner/primus-cli.