mrfakename commited on
Commit
3f2fcae
·
1 Parent(s): 6204063

Revert "Decode video and audio concurrently"

Browse files

This reverts commit 620406325c27beedc4f9760acb0d661e0f999700.

Files changed (1) hide show
  1. h3_split_blocks.py +2 -48
h3_split_blocks.py CHANGED
@@ -12,8 +12,6 @@ Two things the blocks leave to the caller: a keyframe reaches them EXIF-transpos
12
  frame count is aligned to `17 * n + 5` before the call, since that arithmetic lives on the denoising side of the cut.
13
  """
14
 
15
- import torch
16
-
17
  from diffusers.modular_pipelines.minimax_h3.before_encoder import MiniMaxH3Ref2VASetupStep
18
  from diffusers.modular_pipelines.minimax_h3.decoders import MiniMaxH3AfterDenoiseStep
19
  from diffusers.modular_pipelines.minimax_h3.encoders import (
@@ -33,50 +31,6 @@ from diffusers.modular_pipelines.modular_pipeline import SequentialPipelineBlock
33
  from diffusers.modular_pipelines.modular_pipeline_utils import OutputParam
34
 
35
 
36
- class MiniMaxH3ParallelDecodeStep(MiniMaxH3DecodeStep):
37
- """Decode independent video and audio latents concurrently without changing either decoder's precision."""
38
-
39
- @torch.no_grad()
40
- def __call__(self, components, state):
41
- device = components._execution_device
42
- if device.type != "cuda":
43
- return super().__call__(components, state)
44
-
45
- block_state = self.get_block_state(state)
46
- current_stream = torch.cuda.current_stream(device)
47
- video_stream = torch.cuda.Stream(device=device)
48
- audio_stream = torch.cuda.Stream(device=device)
49
- video_stream.wait_stream(current_stream)
50
- audio_stream.wait_stream(current_stream)
51
-
52
- with torch.cuda.stream(video_stream):
53
- video_mean = torch.as_tensor(components.vae.config.latents_mean, device=device).view(1, -1, 1, 1, 1)
54
- video_std = torch.as_tensor(components.vae.config.latents_std, device=device).view(1, -1, 1, 1, 1)
55
- video_latents = block_state.latents * video_std + video_mean
56
- with torch.autocast(device_type="cuda", dtype=torch.float16):
57
- decoded_video = components.vae.decode(video_latents, return_dict=False)[0]
58
- pixel_mean = torch.as_tensor(components.pixel_mean, device=device).view(1, -1, 1, 1, 1)
59
- pixel_std = torch.as_tensor(components.pixel_std, device=device).view(1, -1, 1, 1, 1)
60
- decoded_video = (decoded_video.float() * pixel_std + pixel_mean).clamp(0, 1)
61
-
62
- with torch.cuda.stream(audio_stream):
63
- audio_mean = torch.as_tensor(components.audio_vae.config.latents_mean, device=device).view(1, -1, 1)
64
- audio_std = torch.as_tensor(components.audio_vae.config.latents_std, device=device).view(1, -1, 1)
65
- audio_latents = block_state.audio_latents * audio_std + audio_mean
66
- decoded_audio = components.audio_vae.decode(audio_latents, return_dict=False)[0]
67
- decoded_audio = decoded_audio.float().permute(1, 0, 2)
68
-
69
- current_stream.wait_stream(video_stream)
70
- current_stream.wait_stream(audio_stream)
71
- block_state.videos = components.video_processor.postprocess_video(
72
- decoded_video, output_type=block_state.output_type
73
- )
74
- block_state.audio = decoded_audio
75
- block_state.sampling_rate = components.audio_sampling_rate
76
- self.set_block_state(state, block_state)
77
- return components, state
78
-
79
-
80
  def _wire_outputs(num_frames: bool = True) -> list[OutputParam]:
81
  """The wire format of the split. `num_frames` is declared by the `ref2va` half alone, whose setup resolves one."""
82
  return [
@@ -121,7 +75,7 @@ class MiniMaxH3GeneratorBlocks(SequentialPipelineBlocks):
121
  MiniMaxH3AutoKeyframeVaeEncoderStep,
122
  MiniMaxH3CoreDenoiseStep,
123
  MiniMaxH3AfterDenoiseStep,
124
- MiniMaxH3ParallelDecodeStep,
125
  ]
126
  block_names = ["resize", "vae_encoder", "denoise", "after_denoise", "decode"]
127
 
@@ -176,7 +130,7 @@ class MiniMaxH3Ref2VAGeneratorBlocks(SequentialPipelineBlocks):
176
  MiniMaxH3Ref2VAReferenceEncoderStep,
177
  MiniMaxH3Ref2VACoreDenoiseStep,
178
  MiniMaxH3AfterDenoiseStep,
179
- MiniMaxH3ParallelDecodeStep,
180
  ]
181
  block_names = ["setup", "reference_encoder", "denoise", "after_denoise", "decode"]
182
 
 
12
  frame count is aligned to `17 * n + 5` before the call, since that arithmetic lives on the denoising side of the cut.
13
  """
14
 
 
 
15
  from diffusers.modular_pipelines.minimax_h3.before_encoder import MiniMaxH3Ref2VASetupStep
16
  from diffusers.modular_pipelines.minimax_h3.decoders import MiniMaxH3AfterDenoiseStep
17
  from diffusers.modular_pipelines.minimax_h3.encoders import (
 
31
  from diffusers.modular_pipelines.modular_pipeline_utils import OutputParam
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def _wire_outputs(num_frames: bool = True) -> list[OutputParam]:
35
  """The wire format of the split. `num_frames` is declared by the `ref2va` half alone, whose setup resolves one."""
36
  return [
 
75
  MiniMaxH3AutoKeyframeVaeEncoderStep,
76
  MiniMaxH3CoreDenoiseStep,
77
  MiniMaxH3AfterDenoiseStep,
78
+ MiniMaxH3DecodeStep,
79
  ]
80
  block_names = ["resize", "vae_encoder", "denoise", "after_denoise", "decode"]
81
 
 
130
  MiniMaxH3Ref2VAReferenceEncoderStep,
131
  MiniMaxH3Ref2VACoreDenoiseStep,
132
  MiniMaxH3AfterDenoiseStep,
133
+ MiniMaxH3DecodeStep,
134
  ]
135
  block_names = ["setup", "reference_encoder", "denoise", "after_denoise", "decode"]
136