Add Kandinsky S2V 1.0 (speech-to-video) as a modular pipeline (#15164)
* add kandinsky-s2v
* Address review: reuse PiflowScheduler, keep RoPE tables fp32, validate inputs
- Drop KandinskyS2VPiflowScheduler; the distilled blocks use PiflowScheduler.
- PiflowScheduler: on the final step, pass the nominal segment to the policy
and clamp only the rollout end to eps, as the native K6 and S2V samplers do.
- Keep the S2V RoPE tables as plain attributes so `.to(torch.bfloat16)` leaves
them in fp32.
- Raise when only one of negative_prompt_embeds / negative_pooled_prompt_embeds
is passed, and when the Euler path gets num_inference_steps < 2.
* Address review: quantization-safe modulation, drop duration, guard optional deps
- KandinskyS2VModulation calls its layer instead of reading the weight, and
keeps the modulation layers in fp32 via _keep_in_fp32_modules (as in K6).
- Remove the transformer's `duration` argument; it can only be the frame count.
- Import librosa, soundfile and torchvision behind is_*_available().
- PiflowScheduler: walk raw time one segment at a time and give the policy the
nominal segment on every step, as the native samplers do.
- Update the Pro offload peak in the docs (about 50 GiB).
* Address review: fold helpers, accept waveform audio, offload by margin
- Fold the one-line helpers into their callers, inline the memory embedding,
name the projection layers explicitly and spell out the block arguments.
- Accept `audio` as a mono 16 kHz float waveform (tensor or array) besides a path.
- Run the fp16 test with the pipeline loaded in fp16; drop the variant test.
- Docs: offload Pro with memory_reserve_margin="40GiB" and show a full run.
* Address review: no file inputs, standalone top-level blocks
- Take `image` as a PIL image and `audio` as a 16 kHz waveform; the docs load them.
- Pass components to the encode helpers explicitly.
- Drop the guider from the text encoder: standalone it encodes a negative
prompt only when passed; in the pipeline it follows the guider.
- Remove the input step: the text encoder plans the chunks, the VAE encoder
picks the resolution.
- Group prepare and the chunk loop into one `denoise` step.
- Distilled blocks: no guider and no negative prompt.
* Docs: save the video with the original speech track
* Address review: validation-only checks, no latent output, video_processor
- Inline the grouped attention into the processor.
- `prompt` defaults to DEFAULT_PROMPT in its signature; check_inputs only validates.
- Add auto docstrings to the distilled text encoder and prepare steps.
- Drop `output_type="latent"`; the latents are in the state as `latent_chunks`.
- Preprocess the reference frame with the video processor.
- Remove three tests the review asked to drop.
* Address review: explicit arguments for the helpers
- encode_prompt_and_speech and shared_transformer_kwargs take their components
and values explicitly and return their results.
- The negative prompt gets its own prepare block in the base pipeline; the
distilled pipeline uses the shared prepare step.
- check_inputs of the prepare steps take explicit values.
* Tests: declare the canonical latent form
main checks that the denoise group leaves latents in one canonical form
(test_latents_output_in_canonical_form). Point it at latent_chunks: one
chunk per entry, channels last.
* Address self-review: compile-friendly speech attention, full model testers
- Speech cross-attention keeps static shapes: the per-frame audio groups
are computed from shapes as Python ints and gathered into a padded,
masked batch, so the transformer compiles with fullgraph=True. One
forward is bit-identical to the original model on all four checkpoints.
- Drop FromOriginalModelMixin: single-file loading is not wired up.
- Model tests compose the testers generate_model_tests.py emits (memory,
compile incl. dynamic shapes, training, attention); skips name their
reason.
- Modular tests pin expected_workflow_defaults for base and distilled and
add the guider tester for base.
- Remove dead code: unread attributes, the batched visual-embedding
branch, unused helper parameters.
* Encode speech with get_audio_features instead of a hook
The speech features now come from the Thinker's public
get_audio_features rather than a forward hook on its audio tower. The
tower runs twice per call, once inside the Thinker forward for the text
hidden states and once for the features: +20 ms on a 12 s track (bf16,
H100). The features and the text embeddings are bit-identical to before.
* Apply batched suggestions from code review
Co-authored-by: YiYi Xu <yixu310@gmail.com>
---------
Co-authored-by: YiYi Xu <yixu310@gmail.com>