def test_ddp_post_local_sgd_comm_hook(tmp_path):
    """Test for DDP post-localSGD hook."""
    model = BoringModel()
    strategy = TestDDPStrategy(
        expected_ddp_comm_hook_name=post_localSGD.post_localSGD_hook.__qualname__,
        ddp_comm_state=post_localSGD.PostLocalSGDState(
            process_group=None,
            subgroup=None,
            start_localSGD_iter=8,
        ),
        ddp_comm_hook=post_localSGD.post_localSGD_hook,
        model_averaging_period=4,
    )
    trainer = Trainer(
        fast_dev_run=True,
        accelerator="gpu",
        devices=2,
        strategy=strategy,
        default_root_dir=tmp_path,
        sync_batchnorm=True,
        enable_progress_bar=False,
        enable_model_summary=False,
    )
    trainer.fit(model)
    assert trainer.state.finished, f"Training failed with {trainer.state}"
Test for DDP post-localSGD hook.
tests/tests_pytorch/strategies/test_ddp_integration_comm_hook.py