fix: Use full GPU mode for H200 to avoid device mismatch with patched forward
Browse files293 unmodified lines2942952962972982993003013023033043053063074 unmodified lines312313314315316317318293 unmodified linesif self.pulid_ca is not None:print(f"[FLUX-Diffusers] pulid_ca type: {type(self.pulid_ca)}, len: {len(self.pulid_ca)}")# 4. Enable CPU offload BEFORE patching forward# This ensures our patch is not overwritten by offload hooksprint("[FLUX-Diffusers] Enabling CPU offload...")self.pipe.enable_model_cpu_offload()# 5. Patch transformer forward to support ID injection AFTER offload# The patched forward will be preserved even with offload because# we're replacing the method on the instance, not the classif self.pulid_ca is not None:print("[FLUX-Diffusers] Patching transformer forward for PuLID...")patched_forward = create_pulid_forward(self.pulid_ca)4 unmodified linesprint("[FLUX-Diffusers] Warning: pulid_ca not found, PuLID disabled")self._pulid_loaded = Falseself._log_gpu_memory("after_offload_setup")# Clean upgc.collect()293 unmodified lines2942952962972982993003013023033043053063073083093103113123134 unmodified lines318319320321322323324293 unmodified linesif self.pulid_ca is not None:print(f"[FLUX-Diffusers] pulid_ca type: {type(self.pulid_ca)}, len: {len(self.pulid_ca)}")# 4. Determine whether to use CPU offload based on GPU memory# H200 (150GB) doesn't need offload, and offload breaks our patched forwarduse_offload = self.gpu_memory_gb < 80 # Only use offload for smaller GPUsif use_offload:print("[FLUX-Diffusers] GPU < 80GB, enabling CPU offload...")self.pipe.enable_model_cpu_offload()else:print(f"[FLUX-Diffusers] GPU >= 80GB ({self.gpu_memory_gb:.1f}GB), using full GPU mode...")self.pipe.to(self.device)self._log_gpu_memory("after_device_setup")# 5. Patch transformer forward to support ID injectionif self.pulid_ca is not None:print("[FLUX-Diffusers] Patching transformer forward for PuLID...")patched_forward = create_pulid_forward(self.pulid_ca)4 unmodified linesprint("[FLUX-Diffusers] Warning: pulid_ca not found, PuLID disabled")self._pulid_loaded = Falseself._log_gpu_memory("after_patch")# Clean upgc.collect()
handler.py+15-9