Update app.py
Browse files
app.py
CHANGED
|
@@ -85,12 +85,12 @@ STYLE_ENHANCERS = {
|
|
| 85 |
]
|
| 86 |
}
|
| 87 |
|
| 88 |
-
# 视频参数配置
|
| 89 |
VIDEO_CONFIG = {
|
| 90 |
-
"default_duration":
|
| 91 |
-
"max_duration":
|
| 92 |
-
"default_fps":
|
| 93 |
-
"max_fps":
|
| 94 |
"default_width": 512,
|
| 95 |
"default_height": 512,
|
| 96 |
"max_resolution": 768
|
|
@@ -162,18 +162,20 @@ def initialize_model():
|
|
| 162 |
|
| 163 |
pipeline = pipeline.to(device)
|
| 164 |
|
| 165 |
-
# GPU优化
|
| 166 |
if torch.cuda.is_available():
|
| 167 |
try:
|
| 168 |
-
|
| 169 |
-
pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
try:
|
| 171 |
pipeline.enable_xformers_memory_efficient_attention()
|
| 172 |
except:
|
| 173 |
pass
|
| 174 |
-
|
| 175 |
-
if hasattr(pipeline, 'enable_sequential_cpu_offload'):
|
| 176 |
-
pipeline.enable_sequential_cpu_offload()
|
| 177 |
except Exception as mem_error:
|
| 178 |
print(f"⚠️ Memory optimization warning: {mem_error}")
|
| 179 |
|
|
|
|
| 85 |
]
|
| 86 |
}
|
| 87 |
|
| 88 |
+
# 视频参数配置 - 优化帧率和时长
|
| 89 |
VIDEO_CONFIG = {
|
| 90 |
+
"default_duration": 2.0, # 降低到2秒,更稳定
|
| 91 |
+
"max_duration": 4.0, # 最大4秒
|
| 92 |
+
"default_fps": 12, # 降低到12fps,减少GPU占用和动画速度
|
| 93 |
+
"max_fps": 24, # 最大24fps
|
| 94 |
"default_width": 512,
|
| 95 |
"default_height": 512,
|
| 96 |
"max_resolution": 768
|
|
|
|
| 162 |
|
| 163 |
pipeline = pipeline.to(device)
|
| 164 |
|
| 165 |
+
# GPU优化 - CogVideoX专用
|
| 166 |
if torch.cuda.is_available():
|
| 167 |
try:
|
| 168 |
+
# CogVideoX特有的优化方法
|
| 169 |
+
if hasattr(pipeline, 'enable_vae_tiling'):
|
| 170 |
+
pipeline.enable_vae_tiling()
|
| 171 |
+
if hasattr(pipeline, 'enable_model_cpu_offload'):
|
| 172 |
+
pipeline.enable_model_cpu_offload()
|
| 173 |
+
# 通用内存优化
|
| 174 |
try:
|
| 175 |
pipeline.enable_xformers_memory_efficient_attention()
|
| 176 |
except:
|
| 177 |
pass
|
| 178 |
+
print("✅ CogVideoX memory optimizations applied")
|
|
|
|
|
|
|
| 179 |
except Exception as mem_error:
|
| 180 |
print(f"⚠️ Memory optimization warning: {mem_error}")
|
| 181 |
|