def check_pipeline_hotswap(self, do_compile, rank0, rank1, target_modules0, target_modules1=None):
        """
        Check that hotswapping works on a pipeline.

        Steps:
        - create 2 LoRA adapters and save them
        - load the first adapter
        - hotswap the second adapter
        - check that the outputs are correct
        - optionally compile the model

        Note: We set rank == alpha here because save_lora_adapter does not save the alpha scalings, thus the test would
        fail if the values are different. Since rank != alpha does not matter for the purpose of this test, this is
        fine.
        """
        # create 2 adapters with different ranks and alphas
        dummy_input = self.get_dummy_input()
        pipeline = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-sd-pipe").to(torch_device)
        alpha0, alpha1 = rank0, rank1
        max_rank = max([rank0, rank1])
        if target_modules1 is None:
            target_modules1 = target_modules0[:]
        lora_config0 = self.get_unet_lora_config(rank0, alpha0, target_modules0)
        lora_config1 = self.get_unet_lora_config(rank1, alpha1, target_modules1)

        torch.manual_seed(0)
        pipeline.unet.add_adapter(lora_config0, adapter_name="adapter0")
        output0_before = pipeline(**dummy_input, generator=torch.manual_seed(0))[0]

        torch.manual_seed(1)
        pipeline.unet.add_adapter(lora_config1, adapter_name="adapter1")
        pipeline.unet.set_adapter("adapter1")
        output1_before = pipeline(**dummy_input, generator=torch.manual_seed(0))[0]

        # sanity check
        tol = 1e-3
        assert not np.allclose(output0_before, output1_before, atol=tol, rtol=tol)
        assert not (output0_before == 0).all()
        assert not (output1_before == 0).all()

        with tempfile.TemporaryDirectory() as tmp_dirname:
            # save the adapter checkpoints
            lora0_state_dicts = self.get_lora_state_dicts({"unet": pipeline.unet}, adapter_name="adapter0")
            StableDiffusionPipeline.save_lora_weights(
                save_directory=os.path.join(tmp_dirname, "adapter0"), safe_serialization=True, **lora0_state_dicts
            )
            lora1_state_dicts = self.get_lora_state_dicts({"unet": pipeline.unet}, adapter_name="adapter1")
            StableDiffusionPipeline.save_lora_weights(
                save_directory=os.path.join(tmp_dirname, "adapter1"), safe_serialization=True, **lora1_state_dicts
            )
            del pipeline

            # load the first adapter
            pipeline = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-sd-pipe").to(torch_device)
            if do_compile or (rank0 != rank1):
                # no need to prepare if the model is not compiled or if the ranks are identical
                pipeline.enable_lora_hotswap(target_rank=max_rank)

            file_name0 = os.path.join(tmp_dirname, "adapter0", "pytorch_lora_weights.safetensors")
            file_name1 = os.path.join(tmp_dirname, "adapter1", "pytorch_lora_weights.safetensors")

            pipeline.load_lora_weights(file_name0)
            if do_compile:
                pipeline.unet = torch.compile(pipeline.unet, mode="reduce-overhead")

            output0_after = pipeline(**dummy_input, generator=torch.manual_seed(0))[0]

            # sanity check: still same result
            assert np.allclose(output0_before, output0_after, atol=tol, rtol=tol)

            # hotswap the 2nd adapter
            pipeline.load_lora_weights(file_name1, hotswap=True, adapter_name="default_0")
            output1_after = pipeline(**dummy_input, generator=torch.manual_seed(0))[0]

            # sanity check: since it's the same LoRA, the results should be identical
            assert np.allclose(output1_before, output1_after, atol=tol, rtol=tol)

        Check that hotswapping works on a pipeline.

        Steps:
        - create 2 LoRA adapters and save them
        - load the first adapter
        - hotswap the second adapter
        - check that the outputs are correct
        - optionally compile the model

        Note: We set rank == alpha here because save_lora_adapter does not save the alpha scalings, thus the test would
        fail if the values are different. Since rank != alpha does not matter for the purpose of this test, this is
        fine.
        
tests/pipelines/test_pipelines.py