Repository: huggingface/diffusers
File: tests/pipelines/glm_image/test_glm_image.py (Python)

Code before:
        device = "cpu"
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(device)
        pipe.set_progress_bar_config(disable=None)

        height, width = 32, 32

        # Step 1: Run with prompt only to get prior_token_ids from AR model
        generator = torch.Generator(device=device).manual_seed(0)
        inputs_prompt_only = {
            "prompt": "A photo of a cat",
            "generator": generator,
            "num_inference_steps": 2,
            "guidance_scale": 1.5,
            "height": height,
            "width": width,
            "max_sequence_length": 16,
            "output_type": "pt",
        }
        prior_token_ids, _, _ = pipe.generate_prior_tokens(
            prompt="A photo of a cat",
            height=height,
            width=width,
            device=torch.device(device),
            generator=torch.Generator(device=device).manual_seed(0),
        )

        # Step 2: Run with both prompt and prior_token_ids — should not raise
        generator = torch.Generator(device=device).manual_seed(0)
        inputs_both = {
            "prompt": "A photo of a cat",
            "prior_token_ids": prior_token_ids,
            "generator": generator,
            "num_inference_steps": 2,
            "guidance_scale": 1.5,
            "height": height,
            "width": width,
            "max_sequence_length": 16,
            "output_type": "pt",
        }
        images = pipe(**inputs_both).images
        self.assertEqual(len(images), 1)
        self.assertEqual(images[0].shape, (3, 32, 32))

    def test_check_inputs_rejects_invalid_combinations(self):
        """Test that check_inputs correctly rejects invalid input combinations."""
        device = "cpu"
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(device)

Review comment (suggestion):
`inputs_prompt_only` (and its `generator`) is created but never used. This makes the test misleading (it implies a full pipeline run in step 1) and adds dead code; consider removing it or actually using it to run `pipe(**inputs_prompt_only)` if that's the intended setup.
```suggestion
        prior_token_ids, _, _ = pipe.generate_prior_tokens(
            prompt="A photo of a cat",
            height=height,
            width=width,
            device=torch.device(device),
            generator=generator,
```

Code after:
        device = "cpu"
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(device)
        pipe.set_progress_bar_config(disable=None)

        height, width = 32, 32

        # Step 1: Run with prompt only to get prior_token_ids from AR model
        generator = torch.Generator(device=device).manual_seed(0)
        prior_token_ids, _, _ = pipe.generate_prior_tokens(
            prompt="A photo of a cat",
            height=height,
            width=width,
            device=torch.device(device),
            generator=torch.Generator(device=device).manual_seed(0),
        )

        # Step 2: Run with both prompt and prior_token_ids — should not raise
        generator = torch.Generator(device=device).manual_seed(0)
        inputs_both = {
            "prompt": "A photo of a cat",
            "prior_token_ids": prior_token_ids,
            "generator": generator,
            "num_inference_steps": 2,
            "guidance_scale": 1.5,
            "height": height,
            "width": width,
            "max_sequence_length": 16,
            "output_type": "pt",
        }
        images = pipe(**inputs_both).images
        self.assertEqual(len(images), 1)
        self.assertEqual(images[0].shape, (3, 32, 32))

    def test_check_inputs_rejects_invalid_combinations(self):
        """Test that check_inputs correctly rejects invalid input combinations."""
        device = "cpu"
        components = self.get_dummy_components()
        pipe = self.pipeline_class(**components)
        pipe.to(device)

        height, width = 32, 32

        # Neither prompt nor prior_token_ids → error
        with self.assertRaises(ValueError):
            pipe.check_inputs(
                prompt=None,
                height=height,
                width=width,
                callback_on_step_end_tensor_inputs=None,