Spaces:
Runtime error
Runtime error
Update generator.py
Browse files- generator.py +5 -6
generator.py
CHANGED
|
@@ -751,18 +751,18 @@ class RetroArtConverter:
|
|
| 751 |
|
| 752 |
pipe_kwargs["generator"] = generator
|
| 753 |
|
| 754 |
-
# --- START FIX: Handle CPU Offload for Compel ---
|
| 755 |
# Use Compel for prompt encoding if available
|
| 756 |
if self.use_compel and self.compel is not None:
|
| 757 |
try:
|
| 758 |
print("Encoding prompts with Compel...")
|
| 759 |
|
| 760 |
-
# Move
|
| 761 |
self.pipe.text_encoder.to(self.device)
|
| 762 |
self.pipe.text_encoder_2.to(self.device)
|
| 763 |
|
| 764 |
-
|
| 765 |
-
|
|
|
|
| 766 |
|
| 767 |
pipe_kwargs["prompt_embeds"] = conditioning[0]
|
| 768 |
pipe_kwargs["pooled_prompt_embeds"] = conditioning[1]
|
|
@@ -775,7 +775,7 @@ class RetroArtConverter:
|
|
| 775 |
pipe_kwargs["prompt"] = prompt
|
| 776 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 777 |
finally:
|
| 778 |
-
# Move
|
| 779 |
try:
|
| 780 |
self.pipe.text_encoder.to("cpu")
|
| 781 |
self.pipe.text_encoder_2.to("cpu")
|
|
@@ -784,7 +784,6 @@ class RetroArtConverter:
|
|
| 784 |
else:
|
| 785 |
pipe_kwargs["prompt"] = prompt
|
| 786 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 787 |
-
# --- END FIX ---
|
| 788 |
|
| 789 |
# Add CLIP skip
|
| 790 |
if hasattr(self.pipe, 'text_encoder'):
|
|
|
|
| 751 |
|
| 752 |
pipe_kwargs["generator"] = generator
|
| 753 |
|
|
|
|
| 754 |
# Use Compel for prompt encoding if available
|
| 755 |
if self.use_compel and self.compel is not None:
|
| 756 |
try:
|
| 757 |
print("Encoding prompts with Compel...")
|
| 758 |
|
| 759 |
+
# --- FIX 1: Move encoders to GPU ---
|
| 760 |
self.pipe.text_encoder.to(self.device)
|
| 761 |
self.pipe.text_encoder_2.to(self.device)
|
| 762 |
|
| 763 |
+
# --- FIX 2: Tell Compel to use the GPU for its tensors ---
|
| 764 |
+
conditioning = self.compel(prompt, device=self.device)
|
| 765 |
+
negative_conditioning = self.compel(negative_prompt, device=self.device)
|
| 766 |
|
| 767 |
pipe_kwargs["prompt_embeds"] = conditioning[0]
|
| 768 |
pipe_kwargs["pooled_prompt_embeds"] = conditioning[1]
|
|
|
|
| 775 |
pipe_kwargs["prompt"] = prompt
|
| 776 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
| 777 |
finally:
|
| 778 |
+
# --- FIX 3: Move encoders back to CPU ---
|
| 779 |
try:
|
| 780 |
self.pipe.text_encoder.to("cpu")
|
| 781 |
self.pipe.text_encoder_2.to("cpu")
|
|
|
|
| 784 |
else:
|
| 785 |
pipe_kwargs["prompt"] = prompt
|
| 786 |
pipe_kwargs["negative_prompt"] = negative_prompt
|
|
|
|
| 787 |
|
| 788 |
# Add CLIP skip
|
| 789 |
if hasattr(self.pipe, 'text_encoder'):
|