MFSDP v2: cross-unit checkpoint replay reads sharded child weights

Author: wujingyueCreated Oct 1, 2026Updated Oct 1, 2026
Labelsbug

Minimal repro: add this beside the existing reentrant test. Each inner stays a regular nn.Linear; only its parent and the root become FSDP modules.

python
from megatron.core.tensor_parallel.random import (
    CheckpointWithoutOutput,
    CheckpointWithoutOutputManager,
)


class CheckpointedUnit(nn.Module):
    def __init__(self):
        super().__init__()
        self.inner = nn.Linear(8, 8)

    def forward(self, x, manager):
        return CheckpointWithoutOutput(ckpt_manager=manager).checkpoint(self.inner, x).sin()


class CheckpointedModel(nn.Sequential):
    def forward(self, x):
        manager = CheckpointWithoutOutputManager()
        for unit in self:
            x = unit(x, manager)
        manager.discard_all_outputs_and_register_unified_recompute(x)
        return x


def test_checkpoint_plain_child(distributed_setup):
    device = distributed_setup.device
    mesh = init_device_mesh(device.type, (distributed_setup.world_size,))
    model = CheckpointedModel(CheckpointedUnit(), CheckpointedUnit()).to(device)
    with fully_shard_context(device=device):
        for unit in model:
            fully_shard(unit, mesh=mesh, placements=_default_placements())
        fully_shard(model, mesh=mesh, placements=_default_placements())
    x = torch.randn(2, 8, device=device, requires_grad=True)
    model(x).sum().backward()
bash
CUDA_DEVICE_MAX_CONNECTIONS=32 python -m torch.distributed.run --standalone --nproc-per-node=2 -m pytest -q \
  tests/unit_tests/distributed/mfsdp_v2/test_fully_shard.py -k test_checkpoint_plain_child

On e998be0, backward fails on both GPUs during the first unit's child replay:

RuntimeError: aten.addmm.default got mixed torch.Tensor and DTensor, need to convert all torch.Tensor to DTensor before calling distributed operators!

The shared recompute hook runs before that unit's backward-pre hook gathers its weights. Calling the regular child bypasses the parent's FSDP hooks. Expected: backward completes.

Workaround: add fully_shard(unit.inner, mesh=mesh, placements=_default_placements()) before sharding each unit. This passes on both GPUs.

Simply leaving the children unwrapped in the existing checkpoint(..., use_reentrant=True) test passes; the shared cross-unit recompute hook is needed to reproduce this failure.