Repository: huggingface/diffusers
File: tests/pipelines/kandinsky5/test_kandinsky5.py (Python)

Code before:
        pass

    def test_save_load_optional_components(self):
        # Kandinsky5T2VPipeline doesn't have optional components like transformer_2
        # but we can test saving/loading with the current components
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(torch_device)
        pipe.set_progress_bar_config(disable=None)

        inputs = self.get_dummy_inputs(torch_device)
        output = pipe(**inputs).frames

        with tempfile.TemporaryDirectory() as tmpdir:
            pipe.save_pretrained(tmpdir, safe_serialization=False)
            pipe_loaded = self.pipeline_class.from_pretrained(tmpdir)
            pipe_loaded.to(torch_device)
            pipe_loaded.set_progress_bar_config(disable=None)

        inputs = self.get_dummy_inputs(torch_device)
        output_loaded = pipe_loaded(**inputs).frames

        max_diff = np.abs(output.detach().cpu().numpy() - output_loaded.detach().cpu().numpy()).max()
        self.assertLess(max_diff, 1e-4)

    def test_prompt_embeds(self):
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.set_progress_bar_config(disable=None)
        pipe.to(torch_device)

        # Test without prompt (should raise error)
        inputs = self.get_dummy_inputs(torch_device)
        inputs.pop("prompt")
        with self.assertRaises(ValueError):
            pipe(**inputs)

        # Test with prompt embeddings
        inputs = self.get_dummy_inputs(torch_device)
        prompt = inputs.pop("prompt")
        negative_prompt = inputs.pop("negative_prompt")
        
        # Encode prompts to get embeddings
        prompt_embeds_qwen, prompt_embeds_clip, prompt_cu_seqlens = pipe.encode_prompt(
            prompt, device=torch_device, max_sequence_length=inputs["max_sequence_length"]
        )
        negative_prompt_embeds_qwen, negative_prompt_embeds_clip, negative_prompt_cu_seqlens = pipe.encode_prompt(
            negative_prompt, device=torch_device, max_sequence_length=inputs["max_sequence_length"]
        )

        inputs.update({

Review comment (suggestion):
We should be able to test it with:
https://github.com/huggingface/diffusers/blob/dc6bd1511a4948ebca35b22609002bba58e71c83/tests/pipelines/test_pipelines_common.py#L2072

Code after:
            "output_type": "pt",
        }
        return inputs

    def test_inference(self):
        device = "cpu"

        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(device)
        pipe.set_progress_bar_config(disable=None)

        inputs = self.get_dummy_inputs(device)
        video = pipe(**inputs).frames

        # Check video shape: (batch, frames, channel, height, width)
        expected_shape = (1, 5, 3, 32, 32)
        self.assertEqual(video.shape, expected_shape)

        # Check specific values
        expected_slice = torch.tensor(
            [
                0.4330,
                0.4254,
                0.4285,
                0.3835,
                0.4253,
                0.4196,
                0.3704,
                0.3714,
                0.4999,
                0.5346,
                0.4795,
                0.4637,
                0.4930,
                0.5124,
                0.4902,
                0.4570,
            ]
        )

        generated_slice = video.flatten()
        # Take first 8 and last 8 values for comparison
        video_slice = torch.cat([generated_slice[:8], generated_slice[-8:]])
        self.assertTrue(
            torch.allclose(video_slice, expected_slice, atol=1e-3),
            f"video_slice: {video_slice}, expected_slice: {expected_slice}",
        )

    def test_inference_batch_single_identical(self):
        # Override to test batch single identical with video