From f5a423038f65b4058ef93ef6b3daa37340af785f Mon Sep 17 00:00:00 2001 From: li-lizhe <147392333@qq.com> Date: Wed, 16 Sep 2026 09:22:14 +0800 Subject: [PATCH] fix(modular_pipeline): include Ascend NPU in device-type offload guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sequential offload conflict check and model offload warning in `Pipeline.to()` only applied to CUDA and Intel XPU devices. Ascend NPU is also an accelerator where moving a pipeline to the device conflicts with offloading — users calling `.to("npu")` should get the same clear error/warning instead of silently broken behavior. 5 changes, 2 insertions(+), 2 deletions(-) — adds "npu" to the device_type lists at lines 2691 and 2704 (previously ["cuda", "xpu"]). --- src/diffusers/modular_pipelines/modular_pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/modular_pipelines/modular_pipeline.py b/src/diffusers/modular_pipelines/modular_pipeline.py index e9e5463c1e72..0f058fbb40ee 100644 --- a/src/diffusers/modular_pipelines/modular_pipeline.py +++ b/src/diffusers/modular_pipelines/modular_pipeline.py @@ -2689,7 +2689,7 @@ def module_is_offloaded(module): "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." ) - if device_type in ["cuda", "xpu"]: + if device_type in ["cuda", "xpu", "npu"]: if pipeline_is_sequentially_offloaded and not pipeline_has_bnb: raise ValueError( "It seems like you have activated sequential model offloading by calling `enable_sequential_cpu_offload`, but are now attempting to move the pipeline to GPU. This is not compatible with offloading. Please, move your pipeline `.to('cpu')` or consider removing the move altogether if you use sequential offloading." @@ -2702,7 +2702,7 @@ def module_is_offloaded(module): # 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"]: + if pipeline_is_offloaded and device_type in ["cuda", "xpu", "npu"]: logger.warning( f"It seems like you have activated model offloading by calling `enable_model_cpu_offload`, but are now manually moving the pipeline to GPU. It is strongly recommended against doing so as memory gains from offloading are likely to be lost. Offloading automatically takes care of moving the individual components {', '.join(self.components.keys())} to GPU when needed. To make sure offloading works as expected, you should consider moving the pipeline back to CPU: `pipeline.to('cpu')` or removing the move altogether if you use offloading." )