def test_model_torch_save_ddp_cpu(tmp_path):
    """Test to ensure torch save does not fail for model and trainer using cpu ddp."""
    model = BoringModel()
    num_epochs = 1
    trainer = Trainer(
        default_root_dir=tmp_path,
        max_epochs=num_epochs,
        strategy="ddp_spawn",
        accelerator="cpu",
        devices=2,
        logger=False,
    )
    temp_path = tmp_path / "temp.pt"
    trainer.fit(model)

    # Ensure these do not fail
    torch.save(trainer.model, temp_path)
    torch.save(trainer, temp_path)
Test to ensure torch save does not fail for model and trainer using cpu ddp.
tests/tests_pytorch/checkpointing/test_torch_saving.py