Profiling and observability#
This guide covers how to capture and analyze performance data in Primus: the PyTorch/Kineto profiler, GPU memory snapshots, AMD’s TraceLens trace analysis, ROCm memory sampling, memory/performance projection, and pipeline-schedule visualization. Parameters are grounded in primus/configs/modules/megatron/, primus/configs/modules/torchtitan/pre_trainer.yaml, and primus/configs/modules/maxtext/pre_trainer.yaml.
1. Torch profiler (Megatron)#
Megatron training integrates the PyTorch profiler. Defaults live in primus/configs/modules/megatron/trainer_base.yaml and primus_megatron_module.yaml.
Parameter |
Default |
Purpose |
|---|---|---|
|
|
Master switch for profiling. |
|
|
Use the PyTorch (Kineto) profiler path. |
|
|
Which global ranks to profile. |
|
|
First step to capture. |
|
|
Last step to capture. |
|
|
Drop CPU-side activity to shrink traces (GPU-only trace). |
|
|
Record tensor shapes per op. |
|
|
Record Python/C++ stacks (larger traces). |
|
|
Gzip the exported trace. |
Enable via CLI overrides on train pretrain:
./runner/primus-cli direct -- train pretrain \
--config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml \
--profile True \
--use_pytorch_profiler True \
--profile_step_start 5 \
--profile_step_end 6 \
--disable_profiler_activity_cpu False
Keep the capture window short (a few steps after warmup)—traces grow quickly, especially with with_stack and CPU activity enabled. Load the resulting trace in Perfetto to inspect CPU/GPU overlap, kernel launch delays, and idle gaps.
2. GPU memory profiling (Megatron)#
Two complementary mechanisms:
Memory history snapshot (trainer_base.yaml):
Parameter |
Default |
Purpose |
|---|---|---|
|
|
Record the CUDA/HIP allocator history for snapshot analysis. |
|
|
Output path for the allocator snapshot. |
Load the pickle with PyTorch’s memory visualizer to find fragmentation and peak allocations.
ROCm memory sampling (primus_megatron_module.yaml):
Parameter |
Default |
Purpose |
|---|---|---|
|
|
When |
|
|
When |
Also relevant: log_memory_to_tensorboard (trainer_base.yaml) writes memory metrics to TensorBoard.
3. TraceLens automated trace analysis (Megatron)#
TraceLens turns raw profiler traces into hierarchical breakdowns (roofline/efficiency, compute-vs-memory bound kernels, communication-vs-sync separation, trace diffing). Primus can generate and optionally upload these reports. Configured in primus/configs/modules/megatron/primus_megatron_module.yaml:
Parameter |
Default |
Purpose |
|---|---|---|
|
|
Generate TraceLens reports locally (auto-enabled when upload is on). |
|
|
Upload reports to MLflow (auto-enables generation, profiling, tensorboard). |
|
|
Ranks to analyze ( |
|
|
|
|
|
Delete local reports after upload to save disk. |
|
|
Auto-install TraceLens if missing (set |
Related profiler/log uploads: mlflow_upload_traces (upload raw trace files) and mlflow_upload_logs (upload training logs). See Logging & experiment tracking for MLflow setup.
4. Performance metrics to MLflow (Megatron)#
mlflow_upload_performance_metrics: false (primus_megatron_module.yaml) enables a comprehensive scaling-test metric set when turned on (implicitly enabling throughput calculation):
perf/throughput_tflops_per_gpu,perf/tps_tokens_per_sec_per_gpu,perf/iteration_time_msperf/{rocm,hip}_current_mem_gb,perf/{rocm,hip}_mem_utilization_pctperf/gpu_utilization_pct_rank{N},perf/gpu_utilization_pct_avg
GPU utilization collection uses an
all_gathereverylog_interval, which synchronizes ranks—keep this in mind for throughput-sensitive runs.
5. Profiling (TorchTitan)#
Configured under profiling: in primus/configs/modules/torchtitan/pre_trainer.yaml:
Parameter |
Default |
Purpose |
|---|---|---|
|
|
Enable the Torch profiler. |
|
|
Capture every N steps. |
|
|
Output folder for traces. |
|
|
Capture GPU memory snapshots. |
|
|
Output folder for snapshots. |
Communication tracing is configured under comm: (trace_buf_size, save_traces_folder: comm_traces).
6. Profiling (MaxText)#
Configured in primus/configs/modules/maxtext/pre_trainer.yaml:
Parameter |
Default |
Purpose |
|---|---|---|
|
|
Profiler backend (XPlane traces). |
|
|
Warmup steps to skip before capture. |
|
|
Number of steps to capture. |
7. Memory and performance projection#
Project resource usage before launching, without consuming a full cluster. Exposed through the Primus CLI projection subcommand (primus/cli/subcommands/projection.py).
# Memory projection from an experiment config
./primus-cli direct -- projection memory --config examples/megatron/configs/MI300X/llama2_7B-BF16-pretrain.yaml
# Performance projection (single-node benchmarking)
./primus-cli direct -- projection performance --config <exp>.yaml
# Performance projection scaled to N nodes (simulation)
./primus-cli direct -- projection performance --config <exp>.yaml --target-nodes 4
Memory projection breaks VRAM down across parameters, gradients, activations, optimizer states, and mixed-precision overhead—invaluable for MoE and ultra-large models where activations dominate. See Projection for the full reference.
8. Pipeline schedule visualization#
Diagnose pipeline bubbles and stage imbalance with the built-in tool tools/visualization/pp_vis/.
Dump per-rank schedule data during training with
--dump_pp_data true(Megatron flagdump_pp_data,primus_megatron_module.yaml). Output lands underoutput/pp_data/(config.json,pp_rank_*.json).Install the tool deps and run the viewer:
pip install -r tools/visualization/pp_vis/requirements.txt
python tools/visualization/pp_vis/vis.py # open http://127.0.0.1:8988
Configure task_list in vis.py to point at your dumped log_path and the iterations to render. The tool can also visualize the PP simulator output (see tools/visualization/pp_vis/README.md).
9. Recommended workflow#
Project first—run
projection memoryto confirm the config fits before booking GPUs.Capture a short trace—a few steps after warmup with
profile+use_pytorch_profiler.Inspect—Perfetto for the timeline; TraceLens for automated hierarchical analysis and trace diffs.
Check memory—
record_memory_history/ ROCm sampling for fragmentation and peaks.Check pipelines—
dump_pp_data+pp_visfor bubbles and stage imbalance.