Upload 2 files
Browse files- FlowFacade.py +5 -5
- VideoEngine.py +4 -4
FlowFacade.py
CHANGED
|
@@ -29,7 +29,7 @@ class FlowFacade:
|
|
| 29 |
def _calculate_gpu_duration(self, image: Image.Image, duration_seconds: float,
|
| 30 |
num_inference_steps: int, enable_prompt_expansion: bool, **kwargs) -> int:
|
| 31 |
BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
|
| 32 |
-
BASE_STEP_DURATION =
|
| 33 |
|
| 34 |
resized_image = self.video_engine.resize_image(image)
|
| 35 |
width, height = resized_image.width, resized_image.height
|
|
@@ -37,13 +37,13 @@ class FlowFacade:
|
|
| 37 |
|
| 38 |
factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTH
|
| 39 |
step_duration = BASE_STEP_DURATION * factor ** 1.5
|
| 40 |
-
total_duration =
|
| 41 |
|
| 42 |
if enable_prompt_expansion:
|
| 43 |
-
total_duration +=
|
| 44 |
|
| 45 |
-
# Minimum
|
| 46 |
-
return max(int(total_duration),
|
| 47 |
|
| 48 |
@spaces.GPU(duration=_calculate_gpu_duration)
|
| 49 |
def generate_video_from_image(self, image: Image.Image, user_instruction: str,
|
|
|
|
| 29 |
def _calculate_gpu_duration(self, image: Image.Image, duration_seconds: float,
|
| 30 |
num_inference_steps: int, enable_prompt_expansion: bool, **kwargs) -> int:
|
| 31 |
BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
|
| 32 |
+
BASE_STEP_DURATION = 12 # Optimized for sequential CPU offload
|
| 33 |
|
| 34 |
resized_image = self.video_engine.resize_image(image)
|
| 35 |
width, height = resized_image.width, resized_image.height
|
|
|
|
| 37 |
|
| 38 |
factor = frames * width * height / BASE_FRAMES_HEIGHT_WIDTH
|
| 39 |
step_duration = BASE_STEP_DURATION * factor ** 1.5
|
| 40 |
+
total_duration = 40 + int(num_inference_steps) * step_duration
|
| 41 |
|
| 42 |
if enable_prompt_expansion:
|
| 43 |
+
total_duration += 35
|
| 44 |
|
| 45 |
+
# Minimum 120 seconds (2 minutes) for sequential offload
|
| 46 |
+
return max(int(total_duration), 120)
|
| 47 |
|
| 48 |
@spaces.GPU(duration=_calculate_gpu_duration)
|
| 49 |
def generate_video_from_image(self, image: Image.Image, user_instruction: str,
|
VideoEngine.py
CHANGED
|
@@ -252,13 +252,13 @@ class VideoEngine:
|
|
| 252 |
except Exception as e:
|
| 253 |
print(f"⚠ VAE optimization warning: {e}")
|
| 254 |
|
| 255 |
-
# Stage 4: Enable
|
| 256 |
-
print("→ [4/8] Enabling
|
| 257 |
-
self.pipeline.
|
| 258 |
gc.collect()
|
| 259 |
if torch.cuda.is_available():
|
| 260 |
torch.cuda.empty_cache()
|
| 261 |
-
print("✓
|
| 262 |
|
| 263 |
# Stage 5: Enable TF32 acceleration
|
| 264 |
self._enable_tf32()
|
|
|
|
| 252 |
except Exception as e:
|
| 253 |
print(f"⚠ VAE optimization warning: {e}")
|
| 254 |
|
| 255 |
+
# Stage 4: Enable sequential CPU offload (faster than model offload)
|
| 256 |
+
print("→ [4/8] Enabling sequential CPU offload...")
|
| 257 |
+
self.pipeline.enable_sequential_cpu_offload()
|
| 258 |
gc.collect()
|
| 259 |
if torch.cuda.is_available():
|
| 260 |
torch.cuda.empty_cache()
|
| 261 |
+
print("✓ Sequential CPU offload enabled (only active component on GPU)")
|
| 262 |
|
| 263 |
# Stage 5: Enable TF32 acceleration
|
| 264 |
self._enable_tf32()
|