MFSDP v2: 跨单元检查点重放读取分片子模型权重
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()
CUDA_DEVICE_MAX_CONNECTIONS=32 ZZTERM3ZZ -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_childOn e998be0, backward fails on both GPUs during the first unit's child replay:
内容来源: NVIDIA/Megatron-LM