code: def test_pipeline_interrupt(self):
      components = self.get_dummy_components()
      sd_pipe = StableDiffusionImg2ImgPipeline(**components)
      sd_pipe = sd_pipe.to(torch_device)
      sd_pipe.set_progress_bar_config(disable=None)
  
      inputs = self.get_dummy_inputs(torch_device)
  
      prompt = "hey"
      num_inference_steps = 3
  
      # store intermediate latents from the generation process
      class PipelineState:
          def __init__(self):
              self.state = []
  
          def apply(self, pipe, i, t, callback_kwargs):
              self.state.append(callback_kwargs["latents"])
              return callback_kwargs
  
      pipe_state = PipelineState()
      sd_pipe(
          prompt,
          image=inputs["image"],
          num_inference_steps=num_inference_steps,
          output_type="np",
          generator=torch.Generator("cpu").manual_seed(0),
          callback_on_step_end=pipe_state.apply,
      ).images
  
      # interrupt generation at step index
      interrupt_step_idx = 1
  
      def callback_on_step_end(pipe, i, t, callback_kwargs):
          if i == interrupt_step_idx:
              pipe._interrupt = True
  
          return callback_kwargs
  
      output_interrupted = sd_pipe(
          prompt,
          image=inputs["image"],
          num_inference_steps=num_inference_steps,
          output_type="latent",
          generator=torch.Generator("cpu").manual_seed(0),
          callback_on_step_end=callback_on_step_end,
      ).images
  
      # fetch intermediate latents at the interrupted step
      # from the completed generation process
      intermediate_latent = pipe_state.state[interrupt_step_idx]
  
      # compare the intermediate latent to the output of the interrupted process
      # they should be the same
      assert torch.allclose(
          intermediate_latent, output_interrupted, atol=1e-4
      )
  
imports: import gc
  import random
  import traceback
  import unittest
  import numpy
  import torch
  from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer
  from diffusers import AutoencoderKL, AutoencoderTiny, DDIMScheduler, DPMSolverMultistepScheduler, HeunDiscreteScheduler, LCMScheduler, LMSDiscreteScheduler, PNDMScheduler, StableDiffusionImg2ImgPipeline, UNet2DConditionModel
  from diffusers.utils.testing_utils import enable_full_determinism, floats_tensor, load_image, load_numpy, nightly, require_python39_or_higher, require_torch_2, require_torch_gpu, run_test_in_subprocess, skip_mps, slow, torch_device
  from ..pipeline_params import IMAGE_TO_IMAGE_IMAGE_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS, TEXT_TO_IMAGE_CALLBACK_CFG_PARAMS
  from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin
label_desc: Use image node_id 17 for calling the StableDiffusionImg2ImgPipelineFastTests obj's underlying member method code with example usage: obj.test_pipeline_interrupt() and returns: callback_kwargs, callback_kwargs