← 开源

A high-performance acceleration library dedicated to large-scale model training on AMD GPUs

InfrastructureKernelsOrchestrationPython
增长势头
+024 小时新增 Star0.0%
71
Star
36
Fork
+0
本周
39
贡献者
创建于 2025-06-03 · 更新于 2026-11-28 · 今日第 28293 名
主要开发者
xiaobochen-amdRuibinCheungkyle-256
README

Primus-Turbo

What's Primus-Turbo? | What's New | Quick Start | Example | Performance | Roadmap | Primus Ecosystem | Acknowledgements | License

🔍 What's Primus-Turbo?

Primus-Turbo is a high-performance acceleration library dedicated to large-scale model training on AMD GPUs. Built and optimized for the AMD ROCm platform, it covers the full training stack — including core compute operators (GEMM, Attention, GroupedGEMM), communication primitives (DeepEP), fused MoE layers (MegaMoE), low-precision computation (FP8, MXFP4), and compute–communication overlap kernels.

With High Performance, Full-Featured, and Developer-Friendly as its guiding principles, Primus-Turbo is designed to fully unleash the potential of AMD GPUs for large-scale training workloads, offering a robust and complete acceleration foundation for next-generation AI systems.

Note: JAX support is under active development. Optim support is planned but not yet available.

👉 Scope and Supported Operators — the full list of operators, modules, precisions, and kernel backends.

Category Operators
GEMM gemm (BF16/FP16), gemm_fp8 (tensorwise / rowwise / blockwise / MXFP8), gemm_fp4 (MXFP4), mlp_fp4
Grouped GEMM grouped_gemm, grouped_gemm_fp8, grouped_gemm_fp4, grouped_mlp_fp8, grouped_mlp_fp4
Attention flash_attn_func, flash_attn_varlen_func, flash_attn_fp8_func, flash_attn_*_usp_func (context parallel), flash_attn_agkv_func (all-gather-KV context parallel), ulysses_mega_attn (Ulysses all-to-all + attention in one kernel), sparse_mla_func
MoE fused_group_topk_routing_with_aux_score, moe_permute / moe_unpermute, moe_dispatch / moe_combine, MegaMoE (BF16 / MXFP8)
Norm / Act / RoPE / Loss rmsnorm, rmsnorm_residual, rmsnorm_residual_fp4, swiglu_with_probs, geglu_with_probs, fused_qkv_rope, fused_qkv_rmsnorm_rope, dit_qk_norm_rope, adaln_modulate, gated_residual_adaln, linear_gelu, cross_entropy
Quantization quantize_fp8 / quantize_fp4 (+ _with_trans, grouped, dequantize), weight_deosc_*
Communication fused_all_gather_matmul, fused_matmul_reduce_scatter, fused collective GEMM (GemmA2A / A2AGemm / AgGemm / GemmRS), FP8AllToAll, DeepEP Buffer

Part of the Primus Ecosystem: Primus-Turbo is the high-performance operator layer of the Primus ecosystem, working together with Primus-LM (training framework) and Primus-SaFE (stability & platform).

🚀 What's New

  • [2026/12/01] 🔥 Muse Spark attention on MI455X (gfx1250) — flash_attn_func runs head dim 64 and the causal sliding window window_size=(left, 0) on the FlyDSL kernels on gfx1250, forward and backward, and fused_qkv_rmsnorm_rope gets a Triton backend that takes a gate block, weightless norms and layers without RoPE. The Muse Spark BF16 proxy on one MI455X goes from 25,188 tokens/s/GPU on Transformer Engine attention to 35,857 (+42.4%) (#738, Supported Operators).
  • [2026/12/01] 🔥 MXFP8 training on MI455X (gfx1250) — gemm_fp8, grouped_gemm_fp8, grouped_mlp_fp8 and the staged MXFP8 MegaMoE run on FlyDSL MXFP8 kernels on gfx1250 (E4M3, BF16 activations), with the weight gradients added straight into a bf16 or fp32 main_grad. A DeepSeek-V3 proxy on 4× MI455X goes from 77,160 tokens/s/GPU in BF16 to 103,008 (+33.5%) (#738, Supported Operators, MegaMoE).
  • [2026/11/28] 🔥 Ulysses all-to-all fused into attention on MI355X (gfx950) — ulysses_mega_attn runs the q / k / v all-to-all, causal attention and the output all-to-all of Ulysses context parallelism as one kernel, forward and backward, for GQA (head dim 128) and MLA (q / k 192, v 128): attention tiles start as soon as the rows they read have landed, and each output tile goes straight to the rank that owns its tokens. On 4× MI355X at 32K–64K tokens (Qwen3-30B-A3B, Qwen3-235B-A22B, Llama3.1-8B head shapes) it is 1.15–1.36× faster forward and 1.10–1.21× forward + backward than RCCL all-to-alls around the same attention kernels (#708).
  • [2026/11/28] 🔥 MLA attention on MI355X (gfx950) — flash_attn_func runs the DeepSeek-V3 / Kimi-K2 MLA head dims (q / k 192, v 128) on FlyDSL kernels on gfx950, forward and backward, causal BF16 with an optional softmax_scale (YaRN); the stock and MLA kernels share one forward job body, launcher and backward (#707).
  • [2026/11/26] 🔥 All-gather-KV context parallelism fused into attention on MI355X (gfx950) — flash_attn_agkv_func is Llama-3-style context parallelism for causal GQA attention (zigzag split, every rank keeps all heads): the K / V all-gather of the forward and the gradient reduce-scatter of the backward run inside one persistent attention kernel each. On 8× MI355X it is 1.09–1.34× faster than the same attention with RCCL collectives around it, and a Primus step is 1.01–1.18× faster than Transformer Engine's all_gather context parallelism at 16K–64K tokens (#696).
  • [2026/11/19–11/26] 🔥 FP8 GEMM groundwork for diffusion transformers — tensorwise gemm_fp8 is traced by torch.compile instead of breaking the graph at every Float8Linear (#662); Float8QuantConfig(default_backend=...) picks the backend of one model's FP8 GEMMs without process-wide settings (#663); and the tensorwise cast reports its input's amax in the same pass (quantize_fp8(..., amax_out=)), the first piece of delayed scaling (#698).
  • [2026/11/19–11/21] 🔥 Fused collective GEMM on MI355X (gfx950) — four kernels that run their own collective in the GEMM launch through a symmetric-memory heap: GemmA2A, A2AGemm, AgGemm and GemmRS (#669, #671, #673, #674), 1.41–1.80× faster than hipBLASLt + RCCL. The Ulysses ops run on them: QKV / o_proj for GQA (#677), and MLA through an all-gather of the latents, ulysses_mla_latent_up_proj (#678). Guide: Fused collective GEMM.
  • [2026/11/18] 🔥 Release v0.7.0 — MoE training on MI455X (gfx1250): BF16 MegaMoE, DeepEP V1 / V2, MLA / flash / sparse-MLA attention and gradient accumulation into main_grad; GPT-OSS in MegaMoE; Ulysses GEMM + all-to-all fusion on MI355X; backend choice report and strict dispatch (CHANGELOG, changes since v0.6.0).

👉 Full history — every update, grouped by the release it shipped in; CHANGELOG — every change in each release.

📦 Quick Start

Requirements

Software

  • ROCm >= 7.0
  • Python >= 3.10
  • PyTorch >= 2.6.0 (with ROCm support)
  • AITER (required for some operators, e.g. FlashAttention / FP8): pip3 install "amd-aiter @ git+https://github.com/ROCm/aiter.git@v0.1.24.post1"
  • FlyDSL (required; provides the FlyDSL kernel backend for GEMM / GroupedGEMM / Attention / MoE)
  • rocSHMEM (optional, required for internode DeepEP). See Install rocSHMEM.

Hardware

Architecture Supported GPUs
GFX942 ✅MI300X, ✅MI325X
GFX950 ✅MI350X, ✅MI355X
GFX1250 ✅MI455X

See AMD GPU Architecture to find the architecture for your GPU.

1. Installation

Docker (Recommended)

Use the pre-built AMD ROCm image from Docker Hub:

# PyTorch Ecosystem
docker pull rocm/primus:v26.8

# JAX Ecosystem
docker pull rocm/jax-training:maxtext-v26.8

You can also use the official ROCm PyTorch image from Docker Hub.

Install from Prebuilt Index

Prerequisite: install inside an environment that already has ROCm PyTorch — e.g. the rocm/primus image above, or the official rocm/pytorch image. Primus-Turbo builds against your existing torch and does not install torch for you; in a bare environment pip would otherwise pull a non-ROCm torch.

# PyTorch backend (latest)
pip3 install --no-build-isolation "primus-turbo[pytorch]" \
    --extra-index-url https://amd-agi.github.io/Primus-Turbo/simple/

# Pin a specific version
pip3 install --no-build-isolation "primus-turbo[pytorch]==0.7.0" \
    --extra-index-url https://amd-agi.github.io/Primus-Turbo/simple/

The index currently serves source distributions (sdist), so install compiles HIP kernels locally (needs the ROCm toolchain; supports gfx942 / gfx950). Prebuilt wheels are planned. Keep --no-build-isolation so the build uses your preinstalled torch.

Install from Source

git clone https://github.com/AMD-AGI/Primus-Turbo.git
cd Primus-Turbo

# Install build/runtime dependencies first
pip3 install -r requirements.txt

# Default backend: PyTorch
pip3 install --no-build-isolation ".[pytorch]"

# JAX backend
PRIMUS_TURBO_FRAMEWORK="JAX" pip3 install --no-build-isolation ".[jax]"

Install from GitHub URL (without cloning)

# Install from default branch
pip3 install --no-build-isolation "git+https://github.com/AMD-AGI/Primus-Turbo.git"

# Install from a specific branch
pip3 install --no-build-isolation "git+https://github.com/AMD-AGI/Primus-Turbo.git@main"

Note:

  • ".[pytorch]" / ".[jax]" means install from current local repo with extras.
  • Extras select Python dependencies. Source compilation target is controlled by PRIMUS_TURBO_FRAMEWORK.

2. Development

For contributors, use editable mode (-e) so that code changes take effect immediately without reinstalling.

git clone https://github.com/AMD-AGI/Primus-Turbo.git
cd Primus-Turbo

pip3 install -r requirements.txt
pip3 install --no-build-isolation -e ".[pytorch]" -v

# (Optional) Set GPU_ARCHS environment variable to specify target AMD GPU architectures.
GPU_ARCHS="gfx942;gfx950" pip3 install --no-build-isolation -e ".[pytorch]" -v

# (Optional) Set PRIMUS_TURBO_FRAMEWORK to compile for a specific framework.
# Supported values: PYTORCH (default), JAX.
# For example, to compile for JAX:
PRIMUS_TURBO_FRAMEWORK="JAX" pip3 install --no-build-isolation -e ".[jax]" -v

# (Optional) ccache/sccache are auto-detected on PATH to speed up incremental rebuilds.
# Just install ccache or sccache and the build will use it automatically.

See Environment variables for every build-time and runtime variable Primus-Turbo reads.

3. Testing

Option 1: Single-process mode (slow but simple)

pytest tests/pytorch/    # run all PyTorch tests
pytest tests/jax/        # run all JAX tests

Option 2: Multi-process mode (faster)

# PyTorch tests
## single-GPU tests (parallel)
pytest tests/pytorch/ -n 8
## deterministic tests (parallel)
pytest tests/pytorch/ -n 8 --deterministic-only
## multi-GPU tests
pytest tests/pytorch/ --dist-only

# JAX tests
## single-GPU tests (parallel)
pytest tests/jax/ -n 8
## multi-GPU tests
pytest tests/jax/ --dist-only

4. Packaging

pip installation behavior:

  1. Use a compatible wheel (.whl) if available.
  2. Fall back to source distribution (sdist, .tar.gz) when no wheel matches.

Artifact roles:

  • wheel: prebuilt binary package, fast install, no local C++/HIP build.
  • sdist: source package, slower install, requires local toolchain, fallback path.

Build artifacts

# Build wheel (binary distribution)
python3 -m build --wheel --no-isolation

# Build sdist (source distribution)
python3 -m build --sdist --no-isolation

Verify wheel install

pip3 install --no-build-isolation ./dist/primus_turbo-XXX.whl

Verify source fallback install

pip3 install --no-build-isolation ./dist/primus_turbo-XXX.tar.gz

Tip: Run import checks outside the source tree (for example under /tmp) to avoid importing local source files by accident.

5. Minimal Example

import torch
import primus_turbo.pytorch as turbo

dtype = torch.bfloat16
device = "cuda:0"

a = torch.randn((128, 256), dtype=dtype, device=device)
b = torch.randn((256, 512), dtype=dtype, device=device)
c = turbo.ops.gemm(a, b)

print(c)
print(c.shape)

💡 Example

See Examples for usage examples.

📊 Performance

See Benchmarks for detailed performance results and comparisons.

📍 Roadmap

Roadmap: Primus-Turbo Roadmap H1 2027 · past: H1 2026, H2 2025


🌐 Primus Ecosystem

Primus-Turbo is part of a comprehensive stack for large-model training on AMD GPUs:

🏗️ Architecture Overview

┌─────────────────────────────────────────────────────┐
│                   Primus-SaFE                       │
│         (Stability & Platform Layer)                │
│   Cluster Management | Fault Tolerance | Scheduling │
└────────────────────────┬────────────────────────────┘
                         │
┌────────────────────────▼────────────────────────────┐
│                   Primus-LM                         │
│              (Training Framework)                   │
│    Megatron | TorchTitan | Unified CLI | Workflows  │
└────────────────────────┬────────────────────────────┘
                         │
┌────────────────────────▼────────────────────────────┐
│                  Primus-Turbo                       │
│           (High-Performance Operators)              │
│  Attention | GEMM | GroupedGEMM | MoE | DeepEP      │
│  MegaMoE | FP8/MXFP8/MXFP4 | AITER | CK | FlyDSL    │
└─────────────────────────────────────────────────────┘

📦 Component Details

Component Role Key Features Repository
Primus (Primus-LM) Training framework Multi-backend training (Megatron, TorchTitan, MaxText), unified CLI, projection and tuning agent, MegaMoE integration in Megatron recipes Primus
Primus-Turbo Performance layer FlashAttention-class kernels, GEMM / GroupedGEMM (BF16, FP8, MXFP8, MXFP4), MegaMoE (BF16 + MXFP8, GPT-OSS shapes/biases), DeepEP, fused GroupedMLP; backends CK, hipBLASLt, AITER, Triton, FlyDSL This repo
Primus-SaFE Platform layer Cluster sanity checks, topology-aware scheduling, fault tolerance Primus-SaFE

🔗 How They Work Together

  1. Primus-LM provides the training framework and workflow orchestration.
  2. Primus-Turbo supplies the optimized compute kernels (for example MegaMoE, grouped GEMM, attention, and low-precision GEMMs) that Primus recipes call into.
  3. Primus-SaFE ensures stability and efficient resource utilization at scale.

This separation of concerns allows each component to evolve independently while staying integrated through pinned versions in Primus training images.

🙏 Acknowledgements

Primus-Turbo builds on excellent open-source work from the wider community. We especially thank:

  • FlyDSL — a Flexible Layout Python DSL and MLIR compiler stack for authoring high-performance AMD GPU kernels. Many of our kernels (GEMM, GroupedGEMM, Attention, MoE) are built with FlyDSL; those files carry FlyDSL attribution and remain under Apache-2.0 — see LICENSE and LICENSE-APACHE. We thank the FlyDSL team for their close collaboration and support.
  • AITER — AI Tensor Engine for ROCm, providing high-performance operator backends (e.g. FlashAttention, FP8) that Primus-Turbo integrates.
  • tritonBLAS — high-quality Triton GEMM kernels for AMD GPUs. Our persistent BF16/FP16 and FP8 GEMM kernels are adapted from it.
  • Triton — our Triton attention kernel is adapted from the AMD performance kernels in python/perf-kernels/flash-attention.py, which implement the FlashAttention v2 algorithm by Tri Dao.
  • Triton-distributed — a distributed compiler for computation-communication overlapping. Our MegaMoE comm-compute fused kernels reference its overlapping-kernel design.
  • DeepGEMM — a clean and efficient FP8/BF16 GEMM library. Our MegaMoE barrier and symmetric-heap layout designs reference it.
  • NVIDIA TransformerEngine — our Triton MoE permute/unpermute kernels are adapted from TransformerEngine. That file remains under Apache-2.0 and carries NVIDIA attribution — see LICENSE and LICENSE-APACHE.
  • NVIDIA Megatron-LM — parts of our MoE token permutation and dispatch layer are adapted from Megatron-LM. Those files carry NVIDIA attribution and remain under the 3-clause BSD license — see LICENSE.

📜 License

Primus-Turbo is licensed under the MIT License.

© 2025 Advanced Micro Devices, Inc. All rights reserved.

排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载