yycc commited on
Commit
16e05b9
·
verified ·
1 Parent(s): 38b78b4

Update the model card

Browse files
.gitattributes CHANGED
@@ -63,3 +63,6 @@ examples/media/compare-fastmotion.mp4 filter=lfs diff=lfs merge=lfs -text
63
  examples/media/compare-highkick.mp4 filter=lfs diff=lfs merge=lfs -text
64
  examples/media/pipeline.png filter=lfs diff=lfs merge=lfs -text
65
  examples/media/community-tweet.png filter=lfs diff=lfs merge=lfs -text
 
 
 
 
63
  examples/media/compare-highkick.mp4 filter=lfs diff=lfs merge=lfs -text
64
  examples/media/pipeline.png filter=lfs diff=lfs merge=lfs -text
65
  examples/media/community-tweet.png filter=lfs diff=lfs merge=lfs -text
66
+ examples/media/audio-pin-driving.mp4 filter=lfs diff=lfs merge=lfs -text
67
+ examples/media/audio-pin-out.mp4 filter=lfs diff=lfs merge=lfs -text
68
+ examples/media/audio-pin-ref.png filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -199,8 +199,45 @@ anatomy — the airliner held because the paint tied its wings to real arms.
199
  hold; it is the sync that lags, and we believe that is a training-data limit rather than anything
200
  structural.~~
201
 
202
- **Retracted.** After broader user testing we no longer stand behind this: lip-sync and facial
203
- expression come out better than our own first read of them suggested.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  **Complex scenes are harder than single subjects.** Several characters at once, close interaction
206
  between them, and shots that cut are all cases where quality drops off — enough that we would not
@@ -258,9 +295,10 @@ Defaults are the evaluated configuration: `--steps 4 --flow-shift 3 --num-frames
258
  24 fps) `--seed 42`. Output geometry follows the driving clip and must be a multiple of 32 on both
259
  axes. Weights load in ~21 s, once per process. **Four steps is the operating point, not a shortcut**
260
  — the distilled model already renders sharper than its teacher, and raising the step count tips that
261
- into over-sharpening. `--steps 4` is four sigma boundaries and therefore three forward passes. The
262
- driving clip's audio is dropped at input; the model emits its own track, and the fixed prompt asks
263
- for silence.
 
264
 
265
  Pull a frame with `ffmpeg -ss 1.5 -i driving.mp4 -frames:v 1 ref.png` and edit it at the same
266
  resolution. **It does not have to be the first frame.** The still is passed to the model with no
 
199
  hold; it is the sync that lags, and we believe that is a training-data limit rather than anything
200
  structural.~~
201
 
202
+ **Retracted — and since improved.** Broader user testing already put lip-sync and facial
203
+ expression ahead of our own first read of them. The rest turned out not to be a training-data limit
204
+ either. The model animates the mouth to *its own* audio track, and the fixed prompt asks that track
205
+ to be silence — so in the shipped configuration there is nothing for the mouth to sync to. Give it a
206
+ real soundtrack instead: encode the driving clip's audio with the audio VAE and hold it in the
207
+ target audio rows as a **clean** latent for the whole denoise (H3's flow convention is reversed, so
208
+ clean is `t = 1`). The audio rows stop being something the model predicts and become something it
209
+ conditions on, and the mouth tracks that speech. This is an inference-time change only — no
210
+ retraining, no new weights — and the pairing of noisy video rows with clean audio rows is not a
211
+ state the model was trained on, but it holds up across the clips we have run.
212
+ Pass `--audio` to do it here; the [hosted demo](https://huggingface.co/spaces/Viggle/viggle-animate)
213
+ does it automatically whenever the clip you upload carries sound.
214
+
215
+ **Turn the sound on for these two.** The driving clip, then the same shot with a different actor in
216
+ it, speaking her lines:
217
+
218
+ <video controls playsinline width="100%" src="https://huggingface.co/Viggle/Viggle-Animate/resolve/main/examples/media/audio-pin-driving.mp4"></video>
219
+
220
+ <video controls playsinline width="100%" src="https://huggingface.co/Viggle/Viggle-Animate/resolve/main/examples/media/audio-pin-out.mp4"></video>
221
+
222
+ All three files ship with the weights — the driving clip, the repainted still it is animated from
223
+ ([`audio-pin-ref.png`](examples/media/audio-pin-ref.png)), and the take above — so the second clip
224
+ is a command rather than a claim. The same file is passed twice, once for the motion and once for
225
+ the soundtrack:
226
+
227
+ ```bash
228
+ python inference/sample.py --model-dir ./MiniMax-H3 \
229
+ --cond examples/media/audio-pin-driving.mp4 \
230
+ --ref examples/media/audio-pin-ref.png \
231
+ --audio examples/media/audio-pin-driving.mp4 \
232
+ --out audio-pin-out.mp4
233
+ ```
234
+
235
+ Everything else is the shipped default: 124 frames at 832x480, four steps, `--seed 42`; 51 s of
236
+ render on a B200 after the weights load, and it comes back at 46 dB against the file above. The
237
+ track you get back is the driving clip's own audio put through the audio VAE and decoded again —
238
+ same level, peaks rounded off (0.95 to 0.76 here); that round trip is the evidence the rows really
239
+ were pinned. Drop `--audio` and the same command writes a file whose audio track is digital silence,
240
+ sample for sample, and a mouth that moves without saying anything.
241
 
242
  **Complex scenes are harder than single subjects.** Several characters at once, close interaction
243
  between them, and shots that cut are all cases where quality drops off — enough that we would not
 
295
  24 fps) `--seed 42`. Output geometry follows the driving clip and must be a multiple of 32 on both
296
  axes. Weights load in ~21 s, once per process. **Four steps is the operating point, not a shortcut**
297
  — the distilled model already renders sharper than its teacher, and raising the step count tips that
298
+ into over-sharpening. `--steps 4` is four sigma boundaries and therefore three forward passes.
299
+ `sample.py` drops the driving clip's audio at input and the model emits its own track, which the
300
+ fixed prompt asks to be silence. `--audio <file>` overrides that and pins a real soundtrack instead,
301
+ which is what makes the mouth track speech — see [Limitations](#limitations).
302
 
303
  Pull a frame with `ffmpeg -ss 1.5 -i driving.mp4 -frames:v 1 ref.png` and edit it at the same
304
  resolution. **It does not have to be the first frame.** The still is passed to the model with no
examples/media/audio-pin-driving.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc3dd85a5be2e6246fb40afe46e337cb75d6c3558105fd81fa02f1ff286a5e92
3
+ size 4223283
examples/media/audio-pin-out.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25fc5938c25a4dc48d93f388833358ed50cbb8876753ba75ae4e89045c63cf8e
3
+ size 389192
examples/media/audio-pin-ref.png ADDED

Git LFS Details

  • SHA256: 6bf55661c6e0b3ba9a0b14999462deab9d6de8333d35b6cbd360c3b3cbf855e7
  • Pointer size: 131 Bytes
  • Size of remote file: 442 kB
inference/sample.py CHANGED
@@ -1,3 +1,4 @@
 
1
  """Viggle-Animate: replace the performers in a video with the person in a still.
2
 
3
  python inference/sample.py --cond driving.mp4 --ref character.png --out swapped.mp4
@@ -5,6 +6,16 @@
5
  `--cond` supplies the motion, camera framing, background and lighting; `--ref` supplies
6
  who is in it. Everything about the render except the people is copied from `--cond`.
7
 
 
 
 
 
 
 
 
 
 
 
8
  The text encoder is never loaded. Conditioning comes from `assets/fixed_embed_fwd_anyframe.pt`,
9
  a frozen 362 x 5120 tensor computed once from the fixed prompt in `assets/fixed_prompt.txt`,
10
  so Qwen3-VL (63 GB of the base repo) stays on disk and the text block of the packed sequence
@@ -21,8 +32,12 @@ import time
21
 
22
  import torch
23
  from diffusers import MiniMaxH3Transformer3DModel, ModularPipeline
24
- from diffusers.modular_pipelines.minimax_h3 import MiniMaxH3ImageReference, MiniMaxH3VideoReference
 
 
25
  from diffusers.modular_pipelines.minimax_h3.encoders import MiniMaxH3Ref2VATextEncoderStep
 
 
26
  from diffusers.utils.export_utils import encode_video
27
 
28
  HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -49,6 +64,10 @@ parser.add_argument("--short-edge", type=int, default=None,
49
  "short edge, which is what this model was evaluated at")
50
  parser.add_argument("--offload", action="store_true",
51
  help="stream the transformer from CPU in groups of 5 blocks: ~12 GB resident instead of 62")
 
 
 
 
52
  parser.add_argument("--seed", type=int, default=42)
53
  args = parser.parse_args()
54
 
@@ -65,9 +84,37 @@ def use_fixed_embeds(self, components, state):
65
 
66
  MiniMaxH3Ref2VATextEncoderStep.__call__ = use_fixed_embeds
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  # The reference order is frozen: the presentation names `<Video 1>` then `<Picture 1>`, and that order
69
  # advances the shared rotary clock, so it is part of the layout rather than a detail of the prompt. The
70
- # driving clip's own soundtrack is dropped, as it is in training.
 
71
  video = MiniMaxH3VideoReference.from_file(args.cond)
72
  video.audio, video.sample_rate = None, None
73
 
@@ -97,6 +144,11 @@ pipe.transformer_ref = MiniMaxH3Transformer3DModel.from_pretrained(args.transfor
97
  pipe.transformer_ref.load_lora_adapter(args.lora, weight_name="pytorch_lora_weights.safetensors", prefix=None)
98
  pipe.scheduler.set_shift(args.flow_shift)
99
 
 
 
 
 
 
100
  if args.offload:
101
  pipe.transformer_ref.enable_group_offload(
102
  onload_device=torch.device("cuda"), offload_type="block_level", num_blocks_per_group=5,
@@ -107,14 +159,44 @@ else:
107
  pipe.to("cuda")
108
  print(f"loaded in {time.time() - t0:.0f}s; canvas {height}x{width}, references on short edge {short_edge}")
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  t0 = time.time()
111
  result = pipe(
112
  prompt=fixed["presentation"],
113
  references=[video, MiniMaxH3ImageReference.from_file(args.ref)],
114
- num_frames=args.num_frames,
115
  height=height,
116
  width=width,
117
  num_inference_steps=args.steps,
 
118
  generator=torch.Generator().manual_seed(args.seed),
119
  output=["videos", "audio", "sampling_rate"],
120
  )
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
  """Viggle-Animate: replace the performers in a video with the person in a still.
3
 
4
  python inference/sample.py --cond driving.mp4 --ref character.png --out swapped.mp4
 
6
  `--cond` supplies the motion, camera framing, background and lighting; `--ref` supplies
7
  who is in it. Everything about the render except the people is copied from `--cond`.
8
 
9
+ By default the model generates its own soundtrack, and the fixed prompt asks for silence --
10
+ so there is nothing for the mouth to sync to. `--audio` pins a real one instead:
11
+
12
+ python inference/sample.py --cond driving.mp4 --ref character.png \
13
+ --audio driving.mp4 --out swapped.mp4
14
+
15
+ The soundtrack is encoded once and held in the target audio rows as a *clean* latent for the
16
+ whole denoise, so the model conditions on it rather than predicting it, and the mouth tracks
17
+ that speech. The track written to `--out` is then that same audio, back through the audio VAE.
18
+
19
  The text encoder is never loaded. Conditioning comes from `assets/fixed_embed_fwd_anyframe.pt`,
20
  a frozen 362 x 5120 tensor computed once from the fixed prompt in `assets/fixed_prompt.txt`,
21
  so Qwen3-VL (63 GB of the base repo) stays on disk and the text block of the packed sequence
 
32
 
33
  import torch
34
  from diffusers import MiniMaxH3Transformer3DModel, ModularPipeline
35
+ from diffusers.modular_pipelines.minimax_h3 import (MiniMaxH3AudioReference, MiniMaxH3ImageReference,
36
+ MiniMaxH3VideoReference)
37
+ from diffusers.modular_pipelines.minimax_h3.before_encoder import MiniMaxH3Ref2VASetupStep
38
  from diffusers.modular_pipelines.minimax_h3.encoders import MiniMaxH3Ref2VATextEncoderStep
39
+ from diffusers.modular_pipelines.minimax_h3.modular_pipeline import (align_num_frames,
40
+ audio_latent_num_frames)
41
  from diffusers.utils.export_utils import encode_video
42
 
43
  HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
64
  "short edge, which is what this model was evaluated at")
65
  parser.add_argument("--offload", action="store_true",
66
  help="stream the transformer from CPU in groups of 5 blocks: ~12 GB resident instead of 62")
67
+ parser.add_argument("--audio", default=None,
68
+ help="pin the generated soundtrack to this file's audio -- usually the driving clip "
69
+ "itself -- so the mouth tracks real speech instead of the silence the fixed "
70
+ "prompt asks for. Any file PyAV can decode; a video's soundtrack is taken")
71
  parser.add_argument("--seed", type=int, default=42)
72
  args = parser.parse_args()
73
 
 
84
 
85
  MiniMaxH3Ref2VATextEncoderStep.__call__ = use_fixed_embeds
86
 
87
+ # `--audio` holds the *target* audio rows at a real soundtrack, clean, for the whole denoise, rather
88
+ # than letting the model generate them. Two of the three things that takes have no argument on the
89
+ # pipeline, so they are patched here; the third is the `audio_latents=` passed to the call below.
90
+ if args.audio:
91
+ from diffusers.modular_pipelines.minimax_h3.before_denoise import MiniMaxH3SetTimestepsStep
92
+ from diffusers.modular_pipelines.minimax_h3.denoise import MiniMaxH3LoopSchedulerStep
93
+
94
+ # (1) Those rows carry finished audio, so they have to be told they are clean. H3's flow
95
+ # convention is reversed -- t = 1 is clean, not 0 -- and the library itself passes a literal 1.0
96
+ # for a *reference* soundtrack. `audio_timestep` is positional argument 6.
97
+ _build_row_timesteps = MiniMaxH3SetTimestepsStep.build_row_timesteps
98
+ MiniMaxH3SetTimestepsStep.build_row_timesteps = staticmethod(
99
+ lambda *a: _build_row_timesteps(*a[:6], 1.0, *a[7:]))
100
+
101
+ # (2) ...and the scheduler must never write them, or the first step would walk them off the
102
+ # soundtrack. Only the video rows are stepped. `num_condition_audio_rows` deliberately stays 0:
103
+ # raising it empties the decoder's `audio_latents[num_condition_audio_rows:]` slice and trips the
104
+ # reference-count check, and these rows are a pinned target, not a reference.
105
+ @torch.no_grad()
106
+ def video_only_step(self, components, block_state, i, t):
107
+ n = block_state.num_condition_video_rows
108
+ block_state.latents[n:] = components.scheduler.step(
109
+ block_state.noise_pred[0, n:].float(), t, block_state.latents[n:], return_dict=False)[0]
110
+ return components, block_state
111
+
112
+ MiniMaxH3LoopSchedulerStep.__call__ = video_only_step
113
+
114
  # The reference order is frozen: the presentation names `<Video 1>` then `<Picture 1>`, and that order
115
  # advances the shared rotary clock, so it is part of the layout rather than a detail of the prompt. The
116
+ # driving clip's own soundtrack is dropped here, as it is in training: `--audio` puts one back, but as
117
+ # the *target* to be matched rather than as a reference to be imitated.
118
  video = MiniMaxH3VideoReference.from_file(args.cond)
119
  video.audio, video.sample_rate = None, None
120
 
 
144
  pipe.transformer_ref.load_lora_adapter(args.lora, weight_name="pytorch_lora_weights.safetensors", prefix=None)
145
  pipe.scheduler.set_shift(args.flow_shift)
146
 
147
+ # The pipeline snaps `num_frames` up to the next `17 * n + 5` the video VAE can encode. Doing it here
148
+ # too means the pinned audio is cut to the length that is really rendered rather than the one asked
149
+ # for -- off by one grid step and the rows no longer line up with the video.
150
+ num_frames = align_num_frames(args.num_frames, pipe.vae_frames_per_chunk, pipe.vae_latents_per_chunk)
151
+
152
  if args.offload:
153
  pipe.transformer_ref.enable_group_offload(
154
  onload_device=torch.device("cuda"), offload_type="block_level", num_blocks_per_group=5,
 
159
  pipe.to("cuda")
160
  print(f"loaded in {time.time() - t0:.0f}s; canvas {height}x{width}, references on short edge {short_edge}")
161
 
162
+ # The soundtrack becomes target rows the same way the pipeline turns a *reference* soundtrack into
163
+ # reference rows: truncate at the source rate, resample once, take the posterior mean, normalize.
164
+ # Reusing its own helper is what keeps the two paths from drifting apart.
165
+ audio_latents = None
166
+ if args.audio:
167
+ # One video frame more than the render needs, so the encoder cannot come up short. A source
168
+ # shorter than the grid it renders on is padded, and that tail is real silence.
169
+ n_samp = round((num_frames + 1) / pipe.fps * pipe.audio_sampling_rate)
170
+ track = MiniMaxH3AudioReference.from_file(args.audio)
171
+ wav = MiniMaxH3Ref2VASetupStep._normalize_audio_condition(
172
+ track.audio, track.sample_rate or pipe.audio_sampling_rate, pipe.audio_sampling_rate,
173
+ max_duration=(num_frames + 1) / pipe.fps)
174
+ have = wav.shape[1]
175
+ wav = torch.nn.functional.pad(wav, (0, max(0, n_samp - have)))[:, :n_samp]
176
+ with torch.no_grad():
177
+ # `encode` casts to the encoder's own dtype, so a float32 waveform is fine against a bf16 VAE.
178
+ posterior = pipe.audio_vae.encode(wav[:, None].to(pipe.audio_vae.device), return_dict=False)[0]
179
+ mean = torch.tensor(pipe.audio_vae.config.latents_mean).view(1, 1, -1)
180
+ std = torch.tensor(pipe.audio_vae.config.latents_std).view(1, 1, -1)
181
+ n_lat = audio_latent_num_frames(num_frames, pipe.fps)
182
+ # Channel-major rows: the two stereo channels are two batch items of the mono audio VAE.
183
+ rows = (posterior.mode().float().cpu().transpose(1, 2)[:, :n_lat] - mean) / std
184
+ if rows.shape[1] != n_lat:
185
+ raise RuntimeError(f"the soundtrack encoded to {rows.shape[1]} latents, short of the {n_lat} "
186
+ f"that {num_frames} frames need")
187
+ audio_latents = rows.permute(0, 2, 1).contiguous()
188
+ print(f"pinned {min(have, n_samp) / pipe.audio_sampling_rate:.2f}s of audio -> "
189
+ f"{tuple(audio_latents.shape)}, over {n_samp / pipe.audio_sampling_rate:.2f}s of video")
190
+
191
  t0 = time.time()
192
  result = pipe(
193
  prompt=fixed["presentation"],
194
  references=[video, MiniMaxH3ImageReference.from_file(args.ref)],
195
+ num_frames=num_frames,
196
  height=height,
197
  width=width,
198
  num_inference_steps=args.steps,
199
+ audio_latents=audio_latents,
200
  generator=torch.Generator().manual_seed(args.seed),
201
  output=["videos", "audio", "sampling_rate"],
202
  )