def test_dataloader_distributed_sampler_already_attached(tmp_path):
    """Test DistributedSampler and it's arguments for DDP backend when DistSampler already included on dataloader."""
    seed_everything(123)
    model = ModelWithDataLoaderDistributedSampler()
    trainer = Trainer(
        accelerator="gpu",
        devices=[0, 1],
        num_nodes=1,
        strategy="ddp_spawn",
        default_root_dir=tmp_path,
        max_steps=100,
        callbacks=[DistribSamplerCallback(expected_seeds=(11, 123, 0))],
        use_distributed_sampler=True,
    )
    trainer.fit(model)
    assert trainer.state.finished, "DDP Training failed"
Test DistributedSampler and it's arguments for DDP backend when DistSampler already included on dataloader.
tests/tests_pytorch/trainer/test_dataloaders.py