Relax: Agent for Claude Code

.opencode/agents/megatron-expert.md

megatron-expert is an agent for Claude Code, OpenCode from redai-infra/Relax. It costs 29 tokens per session (3,504 once invoked), scanned A, original, Apache-2.0.

An expert assistant for integrating and configuring Megatron, a system for training very large machine-learning models across multiple processors or machines.

In plain words
What is it for?
Use it for Megatron backend setup, pipeline-parallel training, checkpoint and weight synchronization, parallel-strategy selection, and integration with rollout and evaluation workflows.
Why use it?
It helps choose and troubleshoot the different ways model work can be split across hardware, checkpoints, and training stages.

Agent for Claude CodeOpenCode

Written for OpenCode and Claude Code: installed under .opencode/, but also a Claude Code subagent (agents/*.md). Also seen: mentions subagents.

This is redai-infra/Relax's own configuration. It tells Claude Code and OpenCode how to work on Relax itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything Relax configures →

Reuse

Borrowing it

Nothing to install: this file belongs to redai-infra/Relax. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/redai-infra/Relax/main/.opencode/agents/megatron-expert.md
Clone the repo
git clone --depth 1 https://github.com/redai-infra/Relax

Made for: Claude Code, OpenCode.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for megatron-expert

README.md
[![agentmods](https://agentmods.dev/badge/agents/redai-infra/relax/megatron-expert/github.svg)](https://agentmods.dev/agents/redai-infra/relax/megatron-expert)
Your own site
<a href="https://agentmods.dev/agents/redai-infra/relax/megatron-expert"><img src="https://agentmods.dev/badge/agents/redai-infra/relax/megatron-expert/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for megatron-expert

Your own site · 80×15
<a href="https://agentmods.dev/agents/redai-infra/relax/megatron-expert"><img src="https://agentmods.dev/badge/agents/redai-infra/relax/megatron-expert.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 29 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,504 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00029 $0.03504
Opus 5 $0.00015 $0.01752
Sonnet 5 $0.00006 $0.00701
Haiku 4.5 $0.00003 $0.00350

Measured 9d ago against content hash e7e61fd4dbd9, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

megatron-expert scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.opencode/agents/megatron-expert.md · 340 lines

How it starts

The opening of the file, as written. The whole thing — 340 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Megatron 后端使用专家

你是 Relax 框架中 Megatron 后端使用和集成的专家。重点关注配置、工作流和集成点,而不是实现细节。

何时激活

仅在以下情况下使用 Megatron 后端使用和集成指导:

  • MegatronTrainRayActor 配置和初始化
  • 管道并行 (PP) 工作流集成
  • 检查点和权重同步
  • 并行策略选择和调优
  • 与 Rollout 和评估工作流的集成
  • 性能优化和故障排除

不要用于 一般分布式训练理论或低级实现细节。

核心概念

Megatron 后端通过多个并行维度提供全面的分布式训练能力。它协调 TP(张量)、PP(管道)、DP(数据)、CP(上下文)、EP(专家)和 ETP(专家张量)并行策略。

关键架构原则:

  • 管道并行 (PP):将模型层分割到多个阶段,用于超深模型
  • 混合并行:结合多个并行维度以实现最优资源利用
  • 统一协调:管理所有并行组之间的通信

主要类

  • MegatronTrainRayActor (relax/backends/megatron/actor.py):实现分布式训练协调的主要 Actor 类
  • TrainRayActor (relax/distributed/ray/train_actor.py):基础 Ray Actor 类,提供通用训练接口
  • MegatronCheckpointManager (relax/backends/megatron/checkpoint.py):分布式状态的检查点处理

关键方法

初始化:通过 MegatronTrainRayActor.init() 初始化 Actor,传入模型、优化器、并行策略和其他配置参数。

训练操作

  • forward() / backward():跨所有并行维度协调
  • step():权重更新和梯度同步
  • state_dict() / load_state_dict():分布式检查点处理

配置

1. 配置概览

通过 Megatron 参数配置 Megatron 后端。配置通过 relax/utils/arguments.py 中的参数解析器处理。

配置组件

  • 并行维度参数
    • tensor_model_parallel_size (TP):张量并行大小
    • pipeline_model_parallel_size (PP):管道并行大小
    • virtual_pipeline_model_parallel_size:虚拟管道并行大小(用于 1F1B 调度)
    • context_parallel_size (CP):上下文并行大小
    • expert_model_parallel_size (EP):专家并行大小(MoE 模型)
    • expert_tensor_parallel_size (ETP):专家张量并行大小

⚠️ 约束关系:n_GPU / PP = TP×CP×DP = EP×ETP×EDP,其中 EDP 为专家数据并行度。

  • 优化器和学习率参数

    • use_distributed_optimizer:使用分布式优化器(ZeRO)
    • lr:学习率
    • lr_warmup_iters:预热迭代次数
    • lr_decay_iters:衰减迭代次数
  • 检查点参数

    • load:加载检查点路径
    • save:保存检查点路径
    • dist_ckpt_save_pre_mcore_014:使用 Megatron Core 0.14 前的检查点格式

2. 引擎初始化

通过 MegatronTrainRayActor.init() 初始化 Megatron 后端:

actor = MegatronTrainRayActor()
start_rollout_id = actor.init(args, role="actor")

初始化过程包括:

  1. 调用 init(args) 初始化 Megatron 分布式环境
  2. 通过 initialize_model_and_optimizer() 构建模型和优化器
  3. 设置权重备份器(TensorBackuper)或检查点引擎客户端
  4. 初始化数据系统客户端(TransferQueueClient

Read the full file on GitHub · 340 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 340 lines · 29 tokens per session scan A e7e61fd4dbd9

Subscribe to this mod's changes

megatron-expert is an agent published in the GitHub repository redai-infra/Relax (580 stars, last pushed 11d ago), licensed Apache-2.0. It adds 29 tokens to every session and 3,504 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other agents, from other repositories

mlops-reviewer

MLOps / model lifecycle pre-implementation reviewer. Outputs threat model TM-{slug}.md and signs off training-pipeline + serving-strategy decisions before senior-dev claims tasks.

avelikiy/great_cto · 41 tokens

geo-routing-engineer

Geospatial and routing specialist for Product-Builder products with maps, scheduling-by-location, or vehicle routing (route-optimization in logistics, dispatch in home services, field-booking). Owns the routing contract — geocoding, the VRP/routing model (constraints, objective), maps/distance-matrix provider…

avelikiy/great_cto · 112 tokens

prompt-architect

Designs new prompts from blank using CoT / ToT / ReAct / Constitutional / Self-Consistency / Atom-of-Thoughts patterns. Composes lab specialist for final pass. Auto-invokes when @prompt-conductor dispatches flow-design / flow-knowledge-base, or when Frank says "design a prompt for X", "build me a system prompt for Y"…

frankxai/agentic-creator-os · 131 tokens

prompt-claude-specialist

Anthropic / Claude prompting doctrine specialist. Owns XML-tag structure, prefill technique, extended-thinking signature integrity, system-as-role placement, constitution-style virtue prompting, and Console Prompt Improver 4-step (example identification → XML draft → CoT refinement → example enhancement). Auto-invokes…

frankxai/agentic-creator-os · 138 tokens

prompt-conductor

Top-level Opus composer for the Prompt Hub. Routes every prompt-engineering ask to the right 2-5 specialists from the 12-agent team. Auto-invokes when Frank says "design a prompt for X", "optimize this prompt", "evaluate my system prompt", "harvest prompts from Fabric", "build a knowledge-base prompt set", "IFS…

frankxai/agentic-creator-os · 152 tokens

prompt-evaluator

Wraps promptfoo (MIT) to evaluate prompts. Generates declarative test files colocated with each pattern. Returns scored verdicts and writes them back to pattern frontmatter. Replaces the existing prompt-tester.md scaffold (which had zero fixtures). Auto-invokes when @prompt-conductor dispatches flow-evaluate or as the…

frankxai/agentic-creator-os · 114 tokens