From cb328d3ff988d179d62b012d0c0b91d0964ab7bc Mon Sep 17 00:00:00 2001 From: YiYi Xu Date: Tue, 24 Jun 2025 23:12:26 -1000 Subject: [PATCH] Apply suggestions from code review --- src/diffusers/pipelines/pipeline_utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/diffusers/pipelines/pipeline_utils.py b/src/diffusers/pipelines/pipeline_utils.py index 6431a48dc8..ccc714289d 100644 --- a/src/diffusers/pipelines/pipeline_utils.py +++ b/src/diffusers/pipelines/pipeline_utils.py @@ -466,7 +466,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): module_is_sequentially_offloaded(module) for _, module in self.components.items() ) - is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1 + is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1 if is_pipeline_device_mapped: raise ValueError( "It seems like you have activated a device mapping strategy on the pipeline which doesn't allow explicit device placement using `to()`. You can call `reset_device_map()` to remove the existing device map from the pipeline." @@ -483,7 +483,6 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): "You are trying to call `.to('cuda')` on a pipeline that has models quantized with `bitsandbytes`. Your current `accelerate` installation does not support it. Please upgrade the installation." ) - # Display a warning in this case (the operation succeeds but the benefits are lost) pipeline_is_offloaded = any(module_is_offloaded(module) for _, module in self.components.items()) if pipeline_is_offloaded and device_type in ["cuda", "xpu"]: @@ -1162,11 +1161,9 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will automatically detect the available accelerator and use. """ - self._maybe_raise_error_if_group_offload_active(raise_error=True) - is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1 - + is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1 if is_pipeline_device_mapped: raise ValueError( "It seems like you have activated a device mapping strategy on the pipeline so calling `enable_model_cpu_offload() isn't allowed. You can call `reset_device_map()` first and then call `enable_model_cpu_offload()`." @@ -1288,7 +1285,7 @@ class DiffusionPipeline(ConfigMixin, PushToHubMixin): raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher") self.remove_all_hooks() - is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1 + is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1 if is_pipeline_device_mapped: raise ValueError( "It seems like you have activated a device mapping strategy on the pipeline so calling `enable_sequential_cpu_offload() isn't allowed. You can call `reset_device_map()` first and then call `enable_sequential_cpu_offload()`."