๐ฏ Primus Auto Benchmarking Tool
December 18, 2025 ยท View on GitHub
An interactive bash script for automated benchmarking of LLMs on AMD GPUs (MI300X/MI355X) using Megatron or TorchTitan backends supported through Primus.
๐ Quick Start
Step 1: Pull and Launch the Container
docker pull YOUR_IMAGE
docker run -it \
--device /dev/dri \
--device /dev/kfd \
--network host \
--ipc host \
--group-add video \
--cap-add SYS_PTRACE \
--security-opt seccomp=unconfined \
--privileged \
-v $HOME/.ssh:/root/.ssh \
--name IMAGE_NAME \
YOUR_IMAGE
Step 2: Navigate to Auto Benchmark Directory
cd /workspace/Primus/tools/auto_benchmark/
Step 3: Run the Benchmarking Tool
bash run_primus_autobenchmark.sh
๐ Features
- โ Interactive Menu System - User-friendly CLI with color-coded outputs and ASCII banner
- โ Multi-Backend Support - Compatible with Megatron and TorchTitan with device-specific configs
- โ Batch Processing - Run multiple model configurations sequentially with flexible selection
- โ Configuration Viewing - Preview YAML configs before execution
- โ Configuration Editing - Edit YAML configs individually or in batch before execution
- โ Parameter Overrides - Override specific parameters without editing files permanently
- โ Auto Device Detection - Automatically detects AMD MI300X/MI355X GPUs with intelligent fallback
- โ Device-Specific Paths - Automatically uses device-specific config directories (MI300X/MI355X)
- โ Comprehensive Logging - Timestamped logs saved in organized backend-specific directories
- โ Environment Management - Custom device-specific environment variable support
- โ Automatic Metrics Generation - Backend-specific metrics tables generated after completion
- โ Smart Config Management - Handles edited/override configs properly with automatic cleanup
๐ Complete Walkthrough
1๏ธโฃ Backend Selection
When you launch the tool, you'll first choose the backend framework:
โ
Choose Backend:
โ 1) megatron
โ 2) torchtitan
โ Enter number or name:
Options:
- Enter
1ormegatronfor Megatron backend - Enter
2ortorchtitanfor TorchTitan backend
The backend selection determines:
- Which config directory to use
- Which metrics script to run after completion
- Where logs are saved
2๏ธโฃ Device Detection
The tool automatically detects your AMD GPU with intelligent fallback:
โ
Detecting Device...
โ Device found: MI300X
โ GPU Device: MI300X
โ Config directory set to: /workspace/Primus/examples/megatron/configs/MI300X
Auto-detection methods (in order):
- Queries
rocminfofor "AMD Instinct" devices (direct model name) - Falls back to architecture detection (gfx942 โ MI300X, gfx950 โ MI355X)
- Manual selection prompt if both methods fail
Manual Selection (if auto-detection fails):
โ Could not detect device automatically
โ
Please select Device manually:
โ 1) MI300X
โ 2) MI355X
โ Enter number or name:
Device-Specific Paths: After detection, the config directory is automatically set to:
- Megatron MI300X:
/workspace/Primus/examples/megatron/configs/MI300X - Megatron MI355X:
/workspace/Primus/examples/megatron/configs/MI355X - TorchTitan MI300X:
/workspace/Primus/examples/torchtitan/configs/MI300X - TorchTitan MI355X:
/workspace/Primus/examples/torchtitan/configs/MI355X
3๏ธโฃ Model Configuration Selection
The tool scans for available YAML configuration files in the device-specific backend directory:
โ
Available Model Configs: (megatron / MI300X)
โ 1) llama3_8b.yaml
โ 2) llama3_70b.yaml
โ 3) qwen2.5_7B-FP8-pretrain.yaml
โ Select config number(s) (comma-separated, range, or 'all'):
(Examples: 1,3,5 or 4-8 or all)
Selection Options:
- Single:
1- Select one config - Multiple:
1,3,5- Select specific configs (comma-separated) - Range:
4-8- Select a range of configs - All:
all- Select all available configs
Note: The tool automatically filters out duplicate configs to prevent redundant processing.
4๏ธโฃ View Configuration Parameters
Option to preview parameters in your selected configurations:
โ
View Configuration Parameters?
โ (y/n):
If you choose y, the tool displays the contents of each selected YAML file (excluding comments and empty lines):
Parameters in llama3_8b.yaml:
-----------------------------------
batch_size: 16
learning_rate: 0.0001
max_steps: 1000
seq_length: 2048
-----------------------------------
5๏ธโฃ Edit Configuration Files
For Multiple Configs:
โ
Edit any configuration files before running?
โ (y/n):
If y, you can select which configs to edit:
Selected models:
โ 1) llama3_8b.yaml
โ 2) llama3_70b.yaml
โ Enter model numbers to edit (comma-separated, or 'all'):
โ
For Single Config:
โ
Edit configuration file before running?
โ (y/n):
The tool creates a temporary working copy in /tmp and opens it in your default editor (tries nano, vim, vi, code, or $EDITOR).
Important:
- Edits are applied to the original config location temporarily during benchmark execution
- Original configs are backed up and restored after each benchmark completes
- Edited configs are preserved in logs directory for reproducibility
6๏ธโฃ Override Parameters
Override specific parameters without editing the entire file:
โ
Override any parameters?
(Format: key=value, e.g., batch_size=32)
โ (y/n):
If y, enter overrides one per line:
โ Override (or press Enter to finish): batch_size=32
โ Will override: batch_size = 32
โ Override (or press Enter to finish): learning_rate=0.001
โ Will override: learning_rate = 0.001
โ Override (or press Enter to finish): [Press Enter]
โ 2 parameter(s) will be overridden
Override Behavior:
- Creates
{MODEL}_{BACKEND}_{DEVICE}_{TIMESTAMP}_override.yamlin logs directory - Applies overrides using sed for precise YAML modification
- Can be combined with edited configs
- Original config is temporarily replaced during execution then restored
7๏ธโฃ Device-Specific Environment Variables
Add custom environment variables for your device:
โ
Add device-specific environment variables for MI300X?
(e.g., HSA_OVERRIDE_GFX_VERSION=11.0.0)
โ (y/n):
If y, enter variables one per line:
โ Variable (or press Enter to finish): HSA_OVERRIDE_GFX_VERSION=11.0.0
โ Will set: HSA_OVERRIDE_GFX_VERSION=11.0.0
โ Variable (or press Enter to finish): ROCR_VISIBLE_DEVICES=0,1,2,3
โ Will set: ROCR_VISIBLE_DEVICES=0,1,2,3
โ Variable (or press Enter to finish): [Press Enter]
โ 2 environment variable(s) will be set
Format: VAR_NAME=value (allows empty values)
8๏ธโฃ Environment Setup
The tool configures the environment:
โ
Setting up environment...
โ Set HSA_NO_SCRATCH_RECLAIM=1
โ Set HSA_OVERRIDE_GFX_VERSION=11.0.0
โ Set ROCR_VISIBLE_DEVICES=0,1,2,3
โ Enter HuggingFace Token: [hidden input]
โ HuggingFace token set
Automatic settings:
HSA_NO_SCRATCH_RECLAIM=1(always set for AMD GPUs)- Any custom environment variables you added
HF_TOKENfor HuggingFace authentication (hidden input for security)
9๏ธโฃ Benchmark Execution
The tool runs benchmarks for all selected configurations sequentially:
โน Total configurations to run: 2
โน Configuration list:
โ 1. llama3_8b.yaml
โ 2. qwen2.5_7B-FP8-pretrain.yaml
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LOOP ITERATION: 1/2
โ CONFIG FILE: llama3_8b.yaml
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Starting Benchmark 1/2...
โ Model: llama3_8b
โ Backend: megatron
โ Device: MI300X
โ Config: /workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45_override.yaml
โ Log: /workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45.log
โ Copied edited/overridden config to: /workspace/Primus/examples/megatron/configs/MI300X/llama3_8b.yaml
โ EXP set to: /workspace/Primus/examples/megatron/configs/MI300X/llama3_8b.yaml
โ Changing to Primus root directory: /workspace/Primus
[Benchmark output streams here...]
โ Restored original config file
==========================================
โ Benchmark 1/2 Completed Successfully!
Log saved at:
/workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45.log
Override config saved at:
/workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45_override.yaml
==========================================
Preparing next benchmark...
โน Next: Config 2/2
[Continues with next benchmark...]
For each benchmark:
- Displays iteration header with model info
- Uses edited config if available, otherwise uses original
- Applies parameter overrides to create timestamped override config in logs
- Temporarily replaces original config with edited/overridden version
- Changes to Primus root directory (
/workspace/Primus) for proper path resolution - Exports
EXPenvironment variable pointing to the device-specific config path - Executes
/workspace/Primus/examples/run_pretrain.sh - Streams output to both terminal and timestamped log file
- Restores original config file after completion
- Shows completion status with log file location
- Adds 2-second delay between benchmarks for system stability
Error Handling:
- Script continues even if a benchmark fails
- Exit codes are captured and displayed
- Warnings shown for non-zero exit codes
๐ Metrics Generation
After all benchmarks complete, backend-specific metrics are automatically generated:
=========================================
All 2 Benchmark(s) Completed!
=========================================
โ
Generating Metrics Table...
โ Running: python metrics_megatron.py
[Metrics table displayed here...]
โ Metrics table generated successfully
Automatic Metrics Scripts:
- Megatron: Runs
metrics_megatron.py - TorchTitan: Runs
metrics_torchtitan.py
The metrics scripts parse the log files and generate formatted summary tables with performance statistics.
๐ Output Files
All output files are organized in the results/ directory within the auto_benchmark tool:
Directory Structure
/workspace/Primus/tools/auto_benchmark/
โโโ run_primus_autobenchmark.sh
โโโ metrics_megatron.py
โโโ metrics_torchtitan.py
โโโ results/
โโโ logs_megatron/
โ โโโ llama3_8b_megatron_MI300X_2025-12-17_10-30-45.log
โ โโโ llama3_8b_megatron_MI300X_2025-12-17_10-30-45_override.yaml
โ โโโ llama3_70b_megatron_MI300X_2025-12-17_11-15-20.log
โโโ logs_torchtitan/
โโโ qwen2.5_7B_torchtitan_MI355X_2025-12-17_14-20-30.log
โโโ qwen2.5_7B_torchtitan_MI355X_2025-12-17_14-20-30_edited.yaml
Log Files
Format: {CONFIG_FILENAME}_{BACKEND}_{DEVICE}_{TIMESTAMP}.log
Examples:
/workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45.log/workspace/Primus/tools/auto_benchmark/results/logs_torchtitan/qwen2.5_7B_torchtitan_MI355X_2025-12-17_14-20-30.log
Benefits:
- Full config filename preserved (not just model name)
- Backend-specific directories for easy organization
- Complete benchmark output with metrics
- Timestamped for version tracking
Override Config Files
Format: {CONFIG_FILENAME}_{BACKEND}_{DEVICE}_{TIMESTAMP}_override.yaml
Example:
/workspace/Primus/tools/auto_benchmark/results/logs_megatron/llama3_8b_megatron_MI300X_2025-12-17_10-30-45_override.yaml
Contents: Copy of original config with parameter overrides applied
Edited Config Files
Format: {CONFIG_FILENAME}_{BACKEND}_{DEVICE}_{TIMESTAMP}_edited.yaml
Example:
/workspace/Primus/tools/auto_benchmark/results/logs_torchtitan/qwen2.5_7B_torchtitan_MI355X_2025-12-17_14-20-30_edited.yaml
Contents: Copy of the manually edited config used for the benchmark
๐ก Tips & Best Practices
- Batch Processing: Use
allor ranges (e.g.,1-5) to benchmark multiple models efficiently - Device-Specific Configs: Ensure configs exist in the correct device subdirectory (MI300X/MI355X)
- Parameter Overrides: Use overrides for quick experiments without modifying config files permanently
- Log Organization: Logs are automatically organized by backend in
results/logs_{backend}/ - Environment Variables: Add device-specific tuning variables (e.g.,
HSA_OVERRIDE_GFX_VERSION) for optimal performance - Config Editing: Edited configs are applied during execution but originals are preserved
- View Before Running: Always preview configs before execution to verify parameters
- Metrics Analysis: Backend-specific metrics scripts automatically parse logs after completion
- Sequential Runs: 2-second delay between benchmarks ensures system stability
- Error Resilience: Script continues running even if individual benchmarks fail
- Path Resolution: Script automatically changes to Primus root directory for proper execution
- Config Backup: Original configs are automatically backed up and restored after each benchmark
๐ ๏ธ Technical Details
Directory Structure
/workspace/Primus/
โโโ examples/
โ โโโ megatron/
โ โ โโโ configs/
โ โ โ โโโ MI300X/ # MI300X-specific Megatron configs
โ โ โ โโโ MI355X/ # MI355X-specific Megatron configs
โ โ โโโ prepare.py
โ โโโ torchtitan/
โ โ โโโ configs/
โ โ โ โโโ MI300X/ # MI300X-specific TorchTitan configs
โ โ โ โโโ MI355X/ # MI355X-specific TorchTitan configs
โ โ โโโ prepare.py
โ โโโ run_pretrain.sh # Main benchmark execution script
โโโ tools/
โโโ auto_benchmark/
โโโ run_primus_autobenchmark.sh
โโโ metrics_megatron.py
โโโ metrics_torchtitan.py
โโโ results/
โโโ logs_megatron/
โโโ logs_torchtitan/
Environment Variables Set
HSA_NO_SCRATCH_RECLAIM=1(always set for AMD GPUs)HF_TOKEN(user-provided for HuggingFace access)- Custom device-specific variables (optional, user-defined)
EXP(config path for each benchmark, format:{BACKEND_BASE_DIR}/{DEVICE}/{config}.yaml)
Execution Flow
- Backend selection โ Sets
BACKEND_BASE_DIR - Device detection โ Sets
DEVICE - Config directory construction โ
CONFIG_DIR = {BACKEND_BASE_DIR}/{DEVICE} - Config selection โ Scans device-specific directory
- Config editing/overrides โ Creates temporary working copies
- Environment setup โ Exports required variables
- For each benchmark:
- Backup original config
- Copy edited/override config to original location
- Change to
/workspace/Primusdirectory - Export
EXPvariable - Execute
run_pretrain.sh - Restore original config
- Save logs to
results/logs_{backend}/
- Generate metrics table using backend-specific script
Supported Editors (Priority Order)
nano- Simple terminal editorvim- Advanced terminal editorvi- Classic Unix editorcode- VS Code with--waitflag$EDITOR- Environment variable fallback
Device Detection Logic
1. Query rocminfo for "AMD Instinct" โ Extract model name (MI300X/MI355X)
2. If empty or invalid โ Query rocminfo for architecture (gfx942 โ MI300X, gfx950 โ MI355X)
3. If still empty โ Prompt for manual selection (1=MI300X, 2=MI355X)
Config Management Strategy
- Original configs: Never permanently modified
- Edited configs: Created in
/tmp, temporarily replace originals during execution - Override configs: Created in logs directory with all changes applied
- Backup mechanism:
.backup_$$files created before replacement, restored after execution - Log preservation: All config versions saved to logs directory for reproducibility
๐ Example Session
# Full example workflow
cd /workspace/Primus/tools/auto_benchmark/
bash run_primus_autobenchmark.sh
# Interactive prompts:
# Backend: megatron (enter '1')
# Device: Auto-detected as MI300X
# Configs: 1,2 (select llama3_8b and qwen2.5_7B)
# View parameters: y (preview configs)
# Edit configs: n (skip editing)
# Override parameters: y
# batch_size=64
# learning_rate=0.0005
# Add env vars: y
# HSA_OVERRIDE_GFX_VERSION=11.0.0
# HF token: hf_xxxxxxxxxxxxx
# Output:
# โ 2 benchmarks run sequentially
# โ Logs saved to results/logs_megatron/
# โ Override configs saved with logs
# โ Metrics table automatically generated
# โ Original configs remain unchanged
๐ง Troubleshooting
Common Issues
Issue: find: 'examples/megatron/configs/MI300X': No such file or directory
- Cause: Config directory doesn't exist for the detected device
- Solution: Ensure configs exist in
/workspace/Primus/examples/{backend}/configs/{device}/
Issue: Backend prepare script not found
- Cause: Script not executing from Primus root directory
- Solution: Script now automatically changes to
/workspace/Primusbefore execution
Issue: Edited config not being used
- Cause: Config not properly copied to original location
- Solution: Script now backs up and replaces original configs during execution
Issue: Log files not found
- Cause: Logs saved in wrong directory
- Solution: Check
results/logs_{backend}/in auto_benchmark directory
๐ Support
For issues or questions:
- Check log files in
/workspace/Primus/tools/auto_benchmark/results/logs_{backend}/ - Verify ROCm installation:
rocminfo - Ensure device-specific configs exist in proper directories
- Verify script is run from
/workspace/Primus/tools/auto_benchmark/ - Check that
run_pretrain.shexists in/workspace/Primus/examples/ - Review this README for proper usage
๐ Backend-Specific Metrics
Megatron Metrics
- TPS (Tokens Per Second) - Throughput metric
- TFLOPS (Tera FLOPs) - Compute performance
- Memory (%) - GPU memory utilization
- Time (ms) - Elapsed execution time
TorchTitan Metrics
- TPS (Tokens Per Second) - Throughput metric
- TFLOPS (Tera FLOPs) - Compute performance
- MFU (Model FLOPs Utilization) - Efficiency metric
- Memory (%) - GPU memory utilization
Note: Metrics are extracted automatically by running metrics_{backend}.py after all benchmarks complete.
Happy Benchmarking! ๐