FSDP can run an all-gather and a reduce-scatter at once next to a
persistent Mega MoE grid, so both NCCL kernels have to fit in the SMs
Mega MoE leaves free. With NCCL_MAX_CTAS equal to num_reserved_sms (the
documented 16/16), the two kernels overflow the reservation and deadlock
against the Mega MoE grids under full activation checkpointing.
The trainer now sets NCCL_MAX_CTAS to num_reserved_sms // 2 (8 by
default) before initializing torch distributed when it is unset, and
refuses to start when it is set above that. num_reserved_sms must be at
least 2.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes distributed startup env and validation for Mega MoE training;
mis-set NCCL_MAX_CTAS still fails fast, but default behavior shifts from
16 to 8 CTAs (5 under HSDP).
>
> **Overview**
> Fixes Mega MoE deadlocks when FSDP runs **two** NCCL collectives
(all-gather + reduce-scatter) alongside the persistent MoE grids, and
**three** under HSDP (`dp_replicate > 1`).
>
> **`NCCL_MAX_CTAS`** is now derived from how many kernels must fit in
`num_reserved_sms`: the trainer calls `default_nccl_max_ctas` via
`setup_moe_comm_env` **before** `setup_torch_distributed` in RL and SFT
when dispatch is `mega_moe`. If unset, it sets `NCCL_MAX_CTAS` to
`num_reserved_sms // 2` (or `// 3` under HSDP); startup fails if the env
var is above that cap. `reserve_sms_for_comm` and config/docs/benchmark
are aligned with the same concurrent-kernel model; `num_reserved_sms`
must be at least **2**. Manual `NCCL_MAX_CTAS=16` in docs/examples is
dropped in favor of the default.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
29a7a816fc025b3e35a37960d203771e6683b0d6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->