Skip to content

Commit cb328d3

Browse files
authored
Apply suggestions from code review
1 parent 8c038f0 commit cb328d3

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def module_is_offloaded(module):
466466
module_is_sequentially_offloaded(module) for _, module in self.components.items()
467467
)
468468

469-
is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1
469+
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
470470
if is_pipeline_device_mapped:
471471
raise ValueError(
472472
"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 @@ def module_is_offloaded(module):
483483
"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."
484484
)
485485

486-
487486
# Display a warning in this case (the operation succeeds but the benefits are lost)
488487
pipeline_is_offloaded = any(module_is_offloaded(module) for _, module in self.components.items())
489488
if pipeline_is_offloaded and device_type in ["cuda", "xpu"]:
@@ -1162,11 +1161,9 @@ def enable_model_cpu_offload(self, gpu_id: Optional[int] = None, device: Union[t
11621161
The PyTorch device type of the accelerator that shall be used in inference. If not specified, it will
11631162
automatically detect the available accelerator and use.
11641163
"""
1165-
11661164
self._maybe_raise_error_if_group_offload_active(raise_error=True)
11671165

1168-
is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1
1169-
1166+
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
11701167
if is_pipeline_device_mapped:
11711168
raise ValueError(
11721169
"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 @@ def enable_sequential_cpu_offload(self, gpu_id: Optional[int] = None, device: Un
12881285
raise ImportError("`enable_sequential_cpu_offload` requires `accelerate v0.14.0` or higher")
12891286
self.remove_all_hooks()
12901287

1291-
is_pipeline_device_mapped = hasattr(self, "hf_device_map") and self.hf_device_map is not None and len(self.hf_device_map) > 1
1288+
is_pipeline_device_mapped = self.hf_device_map is not None and len(self.hf_device_map) > 1
12921289
if is_pipeline_device_mapped:
12931290
raise ValueError(
12941291
"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()`."

0 commit comments

Comments
 (0)