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.
curl -O https://raw.githubusercontent.com/redai-infra/Relax/main/.opencode/agents/megatron-expert.mdgit clone --depth 1 https://github.com/redai-infra/RelaxWrote 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.
[](https://agentmods.dev/agents/redai-infra/relax/megatron-expert)<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.
<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>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.
| Model | Per session | Once 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 |
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.
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")
初始化过程包括:
- 调用
init(args)初始化 Megatron 分布式环境 - 通过
initialize_model_and_optimizer()构建模型和优化器 - 设置权重备份器(
TensorBackuper)或检查点引擎客户端 - 初始化数据系统客户端(
TransferQueueClient)
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.
- 9d ago First seen · 340 lines · 29 tokens per session scan A e7e61fd4dbd9
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.
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.
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…
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"…
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…
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…
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…