SuperAPI AI 工具集

nemo-mbridge-perf-cuda-graphs

部署与运维

查看项目

更新于 10-16 02:33

技能介绍

用途:在 Megatron Bridge 中验证并使用 CUDA Graph 捕获,减少主机驱动开销。支持两种实现:cuda_graph_impl="local" 用 MCore FullCudaGraphWrapper 包裹整个前向+反向,作用域为 full_iteration;cuda_graph_impl="transformer_engine" 用 TE make_graphed_callables() 逐层捕获,作用域支持 attn、mlp、moe、moe_router、moe_preprocess、mamba。

主要能力与用法:多数训练负载建议先用 TE 作用域图,再在同一 dispatcher、布局和容器下对比 eager 与重放耗时。稠密模型用 attn,可选加 mlp;dropless MoE 用 attn、moe_router、moe_preprocess;VLM 在真实数据路径稳定后再用相同 MoE 作用域。仅当需要全迭代捕获且满足更严格约束时才用 local + full_iteration。启用示例:cfg.model.cuda_graph_impl="transformer_engine",cfg.model.cuda_graph_scope=["attn"],cfg.model.cuda_graph_warmup_steps=3,cfg.model.use_te_rng_tracker=True,cfg.rng.te_rng_tracker=True。性能测试 CLI 用 --cuda_graph_impl 与逗号分隔的 --cuda_graph_scope,合法值见 scripts/performance/argument_parser.py。

限制:必须启用 use_te_rng_tracker;full_iteration 仅配 local 且需关闭 check_for_nan_in_loss;moe 与 moe_router 作用域不可同时使用;张量形状须静态;CPU offloading 不兼容;moe_preprocess 需同时设 moe_router;旧架构配 expandable_segments 时需 NCCL_GRAPH_REGISTER=0;层级 full recompute 仅支持 full_iteration。CUDA 图会固定中间缓冲区,TE 作用域图增加数 GB,全迭代图峰值内存可增 1.5–2 倍。捕获成功不保证加速,需在目标栈上验证。