FangSen9000 commited on
Commit
78f9663
·
1 Parent(s): 0ebe26e

This enables some controls to be turned on and off.

Browse files
Files changed (21) hide show
  1. ControlNeXt-SVD-v2/run_controlnext_optimized.py +70 -32
  2. README.md +13 -5
  3. easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc +0 -0
  4. generated_pose_video/{GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 → GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832.mp4} +2 -2
  5. generated_pose_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927.mp4 +0 -3
  6. generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 +0 -3
  7. generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215_combined.mp4 +0 -3
  8. generated_pose_video/HELLO_WORLD_27184_63831_20250803_235543.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832.mp4 +2 -2
  9. generated_pose_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832_combined.mp4 +2 -2
  10. generated_sign_video/HELLO_WORLD_27184_63831_20250803_235543.mp4 +0 -3
  11. generated_sign_video/HELLO_WORLD_27184_63831_20250803_235543_combined.mp4 +0 -3
  12. generated_sign_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750.mp4 +0 -3
  13. generated_sign_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750_combined.mp4 +0 -3
  14. generated_sign_video/NOT_FIND_YET_38868_21853_38946_20250803_235630.mp4 +0 -3
  15. generated_sign_video/NOT_FIND_YET_38868_21853_38946_20250803_235630_combined.mp4 +0 -3
  16. generated_sign_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927.mp4 +0 -3
  17. generated_sign_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927_combined.mp4 +0 -3
  18. generated_pose_video/NOT_FIND_YET_38868_21853_38946_20250803_235630.mp4 → ref_img_dict/01_512.jpeg +2 -2
  19. ref_img_dict/blue_512.jpg +3 -0
  20. ref_img_dict/lis_ref_512.jpg +3 -0
  21. ref_img_dict/pink_512.jpeg +3 -0
ControlNeXt-SVD-v2/run_controlnext_optimized.py CHANGED
@@ -16,19 +16,23 @@ from utils.pre_process import preprocess
16
  from utils.pre_process_direct import preprocess_direct_pose, load_pose_from_images
17
  import gc
18
 
19
- # Patch GEGLU for memory optimization
20
- try:
21
- import diffusers.models.activations
22
- def patch_geglu_inplace():
23
- """Patch GEGLU with inplace multiplication to save GPU memory."""
24
- def forward(self, hidden_states):
25
- hidden_states, gate = self.proj(hidden_states).chunk(2, dim=-1)
26
- return hidden_states.mul_(self.gelu(gate))
27
- diffusers.models.activations.GEGLU.forward = forward
28
- patch_geglu_inplace()
29
- print("✓ GEGLU optimization applied")
30
- except:
31
- pass
 
 
 
 
32
 
33
 
34
  def write_mp4(video_path, samples, fps=14, audio_bitrate="192k"):
@@ -192,8 +196,8 @@ def parse_args():
192
  "--precision",
193
  type=str,
194
  default="fp16",
195
- choices=["fp32", "fp16", "bf16"],
196
- help="Model precision"
197
  )
198
 
199
  parser.add_argument(
@@ -208,6 +212,12 @@ def parse_args():
208
  default=2,
209
  help="Chunk size for VAE decoding"
210
  )
 
 
 
 
 
 
211
 
212
  args = parser.parse_args()
213
  return args
@@ -217,11 +227,18 @@ def parse_args():
217
  if __name__ == "__main__":
218
  args = parse_args()
219
 
 
 
 
 
 
 
220
  # Set precision
221
  dtype_map = {
222
  "fp32": torch.float32,
223
  "fp16": torch.float16,
224
- "bf16": torch.bfloat16
 
225
  }
226
  dtype = dtype_map[args.precision]
227
 
@@ -232,47 +249,68 @@ if __name__ == "__main__":
232
  torch.cuda.empty_cache()
233
  gc.collect()
234
 
235
- # Load models with optimizations
236
  print("📦 Loading UNet...")
 
 
 
 
 
 
 
237
  unet = UNetSpatioTemporalConditionControlNeXtModel.from_pretrained(
238
  args.pretrained_model_name_or_path,
239
- subfolder="unet",
240
- low_cpu_mem_usage=True,
241
- torch_dtype=dtype,
242
  )
243
 
244
  print("📦 Loading ControlNeXt...")
245
  controlnext = ControlNeXtSDVModel()
246
  controlnext.load_state_dict(load_tensor(args.controlnext_path))
247
- controlnext = controlnext.to(dtype)
 
248
 
249
  # Load UNet weights
250
  print("📦 Loading UNet weights...")
251
  unet.load_state_dict(load_tensor(args.unet_path), strict=False)
252
 
253
  print("📦 Loading other components...")
 
 
 
 
 
 
 
254
  image_encoder = CLIPVisionModelWithProjection.from_pretrained(
255
  args.pretrained_model_name_or_path,
256
- subfolder="image_encoder",
257
- torch_dtype=dtype,
258
- low_cpu_mem_usage=True,
259
  )
260
 
 
 
 
 
 
 
 
261
  vae = AutoencoderKLTemporalDecoder.from_pretrained(
262
  args.pretrained_model_name_or_path,
263
- subfolder="vae",
264
- torch_dtype=dtype,
265
- low_cpu_mem_usage=True,
266
  )
267
 
268
  # Create pipeline
 
 
 
 
 
 
 
 
 
269
  pipeline = StableVideoDiffusionPipelineControlNeXt.from_pretrained(
270
  args.pretrained_model_name_or_path,
271
- controlnext=controlnext,
272
- unet=unet,
273
- vae=vae,
274
- image_encoder=image_encoder,
275
- torch_dtype=dtype,
276
  )
277
 
278
  # Enable optimizations
 
16
  from utils.pre_process_direct import preprocess_direct_pose, load_pose_from_images
17
  import gc
18
 
19
+ # GEGLU optimization will be applied based on command line argument
20
+ def apply_geglu_optimization():
21
+ """Apply GEGLU optimization for memory efficiency."""
22
+ try:
23
+ import diffusers.models.activations
24
+ def patch_geglu_inplace():
25
+ """Patch GEGLU with inplace multiplication to save GPU memory."""
26
+ def forward(self, hidden_states):
27
+ hidden_states, gate = self.proj(hidden_states).chunk(2, dim=-1)
28
+ return hidden_states.mul_(self.gelu(gate))
29
+ diffusers.models.activations.GEGLU.forward = forward
30
+ patch_geglu_inplace()
31
+ print("✓ GEGLU optimization applied")
32
+ return True
33
+ except Exception as e:
34
+ print(f"⚠️ Failed to apply GEGLU optimization: {e}")
35
+ return False
36
 
37
 
38
  def write_mp4(video_path, samples, fps=14, audio_bitrate="192k"):
 
196
  "--precision",
197
  type=str,
198
  default="fp16",
199
+ choices=["fp32", "fp16", "bf16", "default"],
200
+ help="Model precision (use 'default' to keep original precision)"
201
  )
202
 
203
  parser.add_argument(
 
212
  default=2,
213
  help="Chunk size for VAE decoding"
214
  )
215
+
216
+ parser.add_argument(
217
+ "--enable_geglu_optimization",
218
+ action="store_true",
219
+ help="Enable GEGLU memory optimization (may affect precision)"
220
+ )
221
 
222
  args = parser.parse_args()
223
  return args
 
227
  if __name__ == "__main__":
228
  args = parse_args()
229
 
230
+ # Apply GEGLU optimization if requested
231
+ if args.enable_geglu_optimization:
232
+ apply_geglu_optimization()
233
+ else:
234
+ print("ℹ️ GEGLU optimization disabled")
235
+
236
  # Set precision
237
  dtype_map = {
238
  "fp32": torch.float32,
239
  "fp16": torch.float16,
240
+ "bf16": torch.bfloat16,
241
+ "default": None
242
  }
243
  dtype = dtype_map[args.precision]
244
 
 
249
  torch.cuda.empty_cache()
250
  gc.collect()
251
 
252
+ # Load models with or without dtype specification
253
  print("📦 Loading UNet...")
254
+ unet_kwargs = {
255
+ "subfolder": "unet",
256
+ "low_cpu_mem_usage": True,
257
+ }
258
+ if dtype is not None:
259
+ unet_kwargs["torch_dtype"] = dtype
260
+
261
  unet = UNetSpatioTemporalConditionControlNeXtModel.from_pretrained(
262
  args.pretrained_model_name_or_path,
263
+ **unet_kwargs
 
 
264
  )
265
 
266
  print("📦 Loading ControlNeXt...")
267
  controlnext = ControlNeXtSDVModel()
268
  controlnext.load_state_dict(load_tensor(args.controlnext_path))
269
+ if dtype is not None:
270
+ controlnext = controlnext.to(dtype)
271
 
272
  # Load UNet weights
273
  print("📦 Loading UNet weights...")
274
  unet.load_state_dict(load_tensor(args.unet_path), strict=False)
275
 
276
  print("📦 Loading other components...")
277
+ encoder_kwargs = {
278
+ "subfolder": "image_encoder",
279
+ "low_cpu_mem_usage": True,
280
+ }
281
+ if dtype is not None:
282
+ encoder_kwargs["torch_dtype"] = dtype
283
+
284
  image_encoder = CLIPVisionModelWithProjection.from_pretrained(
285
  args.pretrained_model_name_or_path,
286
+ **encoder_kwargs
 
 
287
  )
288
 
289
+ vae_kwargs = {
290
+ "subfolder": "vae",
291
+ "low_cpu_mem_usage": True,
292
+ }
293
+ if dtype is not None:
294
+ vae_kwargs["torch_dtype"] = dtype
295
+
296
  vae = AutoencoderKLTemporalDecoder.from_pretrained(
297
  args.pretrained_model_name_or_path,
298
+ **vae_kwargs
 
 
299
  )
300
 
301
  # Create pipeline
302
+ pipeline_kwargs = {
303
+ "controlnext": controlnext,
304
+ "unet": unet,
305
+ "vae": vae,
306
+ "image_encoder": image_encoder,
307
+ }
308
+ if dtype is not None:
309
+ pipeline_kwargs["torch_dtype"] = dtype
310
+
311
  pipeline = StableVideoDiffusionPipelineControlNeXt.from_pretrained(
312
  args.pretrained_model_name_or_path,
313
+ **pipeline_kwargs
 
 
 
 
314
  )
315
 
316
  # Enable optimizations
README.md CHANGED
@@ -8,8 +8,6 @@ The entire project is divided into two parts: `text_or_gloss2pose` and `pose2vid
8
 
9
  # For Users
10
 
11
- **Note:** It seems that the first time using pose2vid will result in poor quality and speed, and some kind of warm-up is necessary.
12
-
13
  1. cd StableSigner
14
  2. conda env create -f env/environment02_controlnext.yml
15
  3. run `conda activate controlnext`
@@ -36,13 +34,23 @@ CUDA_VISIBLE_DEVICES=0 python ControlNeXt-SVD-v2/run_controlnext_optimized.py \
36
  --width 512 \
37
  --controlnext_path ControlNeXt-SVD-v2/pretrained/controlnet.bin \
38
  --unet_path ControlNeXt-SVD-v2/pretrained/unet.bin \
39
- --pose_video_path generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 \
40
  --ref_image_path ref_img_dict/03.jpeg \
41
  --precision fp16 \
42
- --enable_xformers \
43
- --decode_chunk_size 2
 
44
  ```
45
 
 
 
 
 
 
 
 
 
 
46
  ## Demo Gallery
47
 
48
  <details>
 
8
 
9
  # For Users
10
 
 
 
11
  1. cd StableSigner
12
  2. conda env create -f env/environment02_controlnext.yml
13
  3. run `conda activate controlnext`
 
34
  --width 512 \
35
  --controlnext_path ControlNeXt-SVD-v2/pretrained/controlnet.bin \
36
  --unet_path ControlNeXt-SVD-v2/pretrained/unet.bin \
37
+ --pose_video_path generated_pose_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832.mp4 \
38
  --ref_image_path ref_img_dict/03.jpeg \
39
  --precision fp16 \
40
+ --decode_chunk_size 2 \
41
+ --enable_geglu_optimization \
42
+ --enable_xformers
43
  ```
44
 
45
+ **Note:** In fact, I haven't installed xformer and haven't conducted a comprehensive test of it. If not installed, it will not affect the normal operation.
46
+
47
+ **Note:** It seems that the first time using pose2vid will result in poor quality and speed, and some kind of warm-up is necessary.
48
+
49
+ **Note:** I have tried running two stages with a resolution of `512*512`, but it seems that it causes instability in the background.
50
+
51
+ **Note:** In some cases, `512w*768h` can cause abnormalities in the torso. In rare instances, the torso may be mistaken for a hand. This issue should be able to be resolved by hiding the torso. However, this has not been implemented yet.
52
+
53
+
54
  ## Demo Gallery
55
 
56
  <details>
easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc CHANGED
Binary files a/easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc and b/easy_dwpose/draw/__pycache__/controlnext.cpython-310.pyc differ
 
generated_pose_video/{GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 → GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832.mp4} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0fe3c60fcfffa5c18867d43d23c0c72ee4dfa7abe59b4e80d79de87ba2cffce5
3
- size 1685778
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:761d087c399b83e83d0246c6eb84d5cefe7290a01ceb59f1bbab2a29e7a4bf26
3
+ size 1688288
generated_pose_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:85c5f6d2002e4bc2f495c05a5bd5f47442b3e4fd02cec76e28e05c4a8b1e09ed
3
- size 3186550
 
 
 
 
generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c63044ffcffb6d3b4882da43bffe6f61ff3b521c5ba5a1b9cc446a910f574e07
3
- size 1029963
 
 
 
 
generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250803_233215_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:668ed7a6757f8b029cb1c66745e0d580ddceb1547d639dd21bdf5809433f6c7e
3
- size 1401238
 
 
 
 
generated_pose_video/HELLO_WORLD_27184_63831_20250803_235543.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832.mp4 RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:653eaa3cb9d77210c52f44041e3c691dcf790ac91ab3c2e021d5b105ca048bc4
3
- size 2054014
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ffbd69305da539b27e681a13954a6b9976ba7602ae2ecea257650ba5857010c
3
+ size 1044299
generated_pose_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750.mp4 → generated_sign_video/GOOD_MORNING_AFTERNOON_25073_36863_01435_20250804_160832_combined.mp4 RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f4b5847ee1c412ed6908732736db1960fbbf93fbc13e1cf223a66bfac235226d
3
- size 4383086
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:022648fc732f606d65c53f97ab8aa0a6cb738116e20790fac96b8cd2d2577337
3
+ size 1421229
generated_sign_video/HELLO_WORLD_27184_63831_20250803_235543.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad825761d1b15f4b22ab36c3fdff617b2a65141a9f10fc3d8603811ce52a4868
3
- size 1333936
 
 
 
 
generated_sign_video/HELLO_WORLD_27184_63831_20250803_235543_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9a44757adab0f12e339fe2f11c65fe2a018e6573193619bfec944ee121a977f3
3
- size 1773622
 
 
 
 
generated_sign_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:3868939e530760666e17ce8d57f899a08e2c52b045bf8c078d222f8864599af0
3
- size 2387083
 
 
 
 
generated_sign_video/I_WILL_ATTEND_THIS_DINNER_PARTY_28794_63364_04007_66628_16327_41325_20250803_235750_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:95f7ad4716cc667a0b66fddd45605c6b27f2e5bacc0e9c8380621d1869fc4abb
3
- size 3168754
 
 
 
 
generated_sign_video/NOT_FIND_YET_38868_21853_38946_20250803_235630.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ffe57314a6c0dac56f8e8094533e885ba392e080b136ac832bc8f0117125f458
3
- size 1601408
 
 
 
 
generated_sign_video/NOT_FIND_YET_38868_21853_38946_20250803_235630_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:814269dc74751c20f1b68d8c8d17ef9336b7ffc3c0c350a1e3986c690be07f25
3
- size 2107461
 
 
 
 
generated_sign_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:20ae3d6c65f86393cab08e32f9380f37af5a8a26a46129df6569787ae92dcb26
3
- size 2015616
 
 
 
 
generated_sign_video/WHERE_IS_MY_CAT_63084_58616_37469_65313_20250803_235927_combined.mp4 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:071749297784b453bda19fd6bb5cd5c679056a2e5dbcedcd24997f0c525d64de
3
- size 2693309
 
 
 
 
generated_pose_video/NOT_FIND_YET_38868_21853_38946_20250803_235630.mp4 → ref_img_dict/01_512.jpeg RENAMED
File without changes
ref_img_dict/blue_512.jpg ADDED

Git LFS Details

  • SHA256: 2a01f2c1089f6efc689d0f6ca1cfd815bf8908b343cfb02536aa75c9bb02abbd
  • Pointer size: 131 Bytes
  • Size of remote file: 194 kB
ref_img_dict/lis_ref_512.jpg ADDED

Git LFS Details

  • SHA256: f82f1294c24c7d8c7a4b2f65904efd290bc21899894fac3d888d91f45dad5a9e
  • Pointer size: 131 Bytes
  • Size of remote file: 247 kB
ref_img_dict/pink_512.jpeg ADDED

Git LFS Details

  • SHA256: 19ba595e9bc9ae6ce1af4aed1a22e1e86c943569cb2c29ae2ca91442da9b07f3
  • Pointer size: 131 Bytes
  • Size of remote file: 257 kB