def test_no_call_to_apply(monkeypatch):
    """Regression test to ensure we're not calling `FSDP.apply()` indirectly (see #19755)."""
    monkeypatch.setattr(torch.distributed.fsdp.FullyShardedDataParallel, "apply", Mock())

    fabric = Fabric(
        accelerator="cuda",
        strategy=FSDPStrategy(auto_wrap_policy=always_wrap_policy),
        devices=2,
    )
    fabric.launch()

    for setup_method in ("setup", "setup_module"):
        model = BoringModel()
        setup = getattr(fabric, setup_method)
        model = setup(model)
        model._forward_module.apply.assert_not_called()
Regression test to ensure we're not calling `FSDP.apply()` indirectly (see #19755).
tests/tests_fabric/strategies/test_fsdp_integration.py