|  | 
| 28 | 28 |     DiffusionPipeline, | 
| 29 | 29 |     FluxControlPipeline, | 
| 30 | 30 |     FluxTransformer2DModel, | 
| 31 |  | -    PipelineQuantizationConfig, | 
| 32 | 31 |     SD3Transformer2DModel, | 
| 33 | 32 | ) | 
|  | 33 | +from diffusers.quantizers import PipelineQuantizationConfig | 
| 34 | 34 | from diffusers.utils import is_accelerate_version, logging | 
| 35 | 35 | from diffusers.utils.testing_utils import ( | 
| 36 | 36 |     CaptureLogger, | 
|  | 
| 46 | 46 |     require_torch, | 
| 47 | 47 |     require_torch_accelerator, | 
| 48 | 48 |     require_torch_gpu, | 
| 49 |  | -    require_torch_version_greater_equal, | 
|  | 49 | +    require_torch_version_greater, | 
| 50 | 50 |     require_transformers_version_greater, | 
| 51 | 51 |     slow, | 
| 52 | 52 |     torch_device, | 
| @@ -875,17 +875,26 @@ def tearDown(self): | 
| 875 | 875 |         backend_empty_cache(torch_device) | 
| 876 | 876 |         torch.compiler.reset() | 
| 877 | 877 | 
 | 
| 878 |  | -    @require_torch_version_greater_equal("2.8") | 
|  | 878 | +    @require_torch_version_greater("2.7.1") | 
| 879 | 879 |     def test_torch_compile_4bit(self): | 
|  | 880 | +        torch._dynamo.config.capture_dynamic_output_shape_ops = True | 
|  | 881 | + | 
| 880 | 882 |         quantization_config = PipelineQuantizationConfig( | 
| 881 | 883 |             quant_backend="bitsandbytes_4bit", | 
| 882 |  | -            quant_kwargs={"load_in_4bit": True}, | 
|  | 884 | +            quant_kwargs={ | 
|  | 885 | +                "load_in_4bit": True, | 
|  | 886 | +                "bnb_4bit_quant_type": "nf4", | 
|  | 887 | +                "bnb_4bit_compute_dtype": torch.bfloat16, | 
|  | 888 | +            }, | 
| 883 | 889 |             components_to_quantize=["transformer"], | 
| 884 | 890 |         ) | 
| 885 | 891 |         pipe = DiffusionPipeline.from_pretrained( | 
| 886 |  | -            "hf-internal-testing/tiny-flux-pipe", quantization_config=quantization_config, torch_dtype=torch.bfloat16 | 
|  | 892 | +            "stabilityai/stable-diffusion-3-medium-diffusers", | 
|  | 893 | +            quantization_config=quantization_config, | 
|  | 894 | +            torch_dtype=torch.bfloat16, | 
| 887 | 895 |         ).to("cuda") | 
| 888 | 896 |         pipe.transformer.compile(fullgraph=True) | 
| 889 | 897 | 
 | 
| 890 | 898 |         for _ in range(2): | 
| 891 |  | -            pipe("a dog", num_inference_steps=4, max_sequence_length=16) | 
|  | 899 | +            # with torch._dynamo.config.patch(error_on_recompile=True): | 
|  | 900 | +            pipe("a dog", num_inference_steps=4, max_sequence_length=16, height=256, width=256) | 
0 commit comments