Skip to content

Restore deleted capabilities, completed and integrated properly - #13

Closed
AshishKumar4 wants to merge 4 commits into
revamp/phase-2-consolidationfrom
revamp/phase-2-restorations
Closed

Restore deleted capabilities, completed and integrated properly#13
AshishKumar4 wants to merge 4 commits into
revamp/phase-2-consolidationfrom
revamp/phase-2-restorations

Conversation

@AshishKumar4

@AshishKumar4 AshishKumar4 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Fourth PR of the series — stacked on #12. Restores the two real capabilities Phase 1/2 deleted, rebuilt properly on the new foundation instead of reviving the broken originals.

Fused / flash attention (was EfficientAttention + --flash_attention)

One helper — scaled_dot_product_attention — now backs every attention module in the library:

  • default (None): flax reference attention, runs everywhere, honors force_fp32_for_softmax
  • 'xla' / 'cudnn': jax.nn.dot_product_attention, which dispatches to the fused cudnn flash kernel on supported GPUs
  • 'tpu': the pallas TPU flash kernel with the 1/sqrt(d) scale passed explicitly — the deleted implementation passed none (pallas defaults sm_scale=1.0), inflating logits 8× at head_dim 64, and used a different param tree so its checkpoints were unusable on the normal path

The projections never change with the implementation, so checkpoints are interchangeable across hardware — train on TPU, sample on GPU, switch kernels freely. attention_impl is exposed on every model (DiT family, MM-DiT joint attention, UViT/UDiT, UNet) and as --attention_impl. A parity test pins reference-vs-fused agreement on identical params (verified to 6e-7 at the kernel level, 1e-4 at model level).

Video modeling (was unet_3d.py)

The old UNet3D was never wired into any registry/training path and subclassed diffusers flax blocks that upstream deleted. The replacement is VideoDiT — factorized spatial-temporal attention built entirely from the shared backbone: per-frame PatchSequenceEmbed (hilbert/zigzag work), spatial + temporal ModulatedBlock per layer, RoPE on the genuine 1D time axis, shared output head. Registered as video_dit and integrated end to end — including a fix for DiffusionInputConfig silently dropping the time axis for video shapes, which would have prevented any video model from initializing through the trainer.

Tests: forward shapes, temporal-mixing behavior check, registry construction, and a 5D end-to-end training run through the real GeneralDiffusionTrainer (the samplers were already made 5D-safe in Phase 1, so the whole video path now works: data → trainer → model → sampler).

UNet3D — restored properly (third commit)

The convolutional video UNet is back, rebuilt from our own UNet blocks instead of the deleted diffusers ones — which is what makes it actually valuable: the spatial module names mirror Unet exactly, so inflate_unet_params drops a trained 2D checkpoint straight into the 3D tree. The temporal attention blocks (RoPE over the frame axis, at every resolution level) are zero-initialized, so an inflated model reproduces the image model frame-by-frame and training only has to learn motion — the AnimateDiff recipe applied to our own pretrained models (e.g. the TRC-trained 128px text-conditional UNet). Verified by test: an inflated UNet3D matches the 2D Unet per-frame to 1e-5.

Registered as unet_3d; both video archs are wired into training.py. Suite: 67 passed.

Not restored, deliberately

favor_fastattn.py (Performer): its role — linear-cost token mixing — is covered by the S5 SSM mixer in ModulatedBlock, which is this repo's own research direction. Reviving 722 lines of gin-dependent vendored code would add a second linear-mixer path with no consumer. If linear attention specifically is ever wanted, the right shape is a third mixer= option in ModulatedBlock, not the old file.

Verification

pytest -m "not network": 65 passed (4 new tests). Suite remains xfail-free.

🤖 Generated with Claude Code

AshishKumar4 and others added 4 commits July 23, 2026 11:28
…mentations

Restores the flash-attention capability that Phase 1 deleted, built
properly this time. One helper (scaled_dot_product_attention) backs every
attention module: the flax reference path by default, jax.nn's fused
entrypoint ('xla'/'cudnn', dispatching to the cudnn flash kernel on
supported GPUs), and the pallas TPU flash kernel with the 1/sqrt(d) scale
passed explicitly - the deleted EfficientAttention passed none, inflating
logits 8x at head_dim 64, and used a different param tree so its
checkpoints were unusable on the normal path.

The projections never change with the implementation, so checkpoints are
interchangeable across hardware; attention_impl is exposed on every model
(DiT family, MM-DiT, UViT/UDiT, UNet) and as --attention_impl in
training.py. A parity test pins reference-vs-fused agreement on the same
params.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Restores the video-modeling capability whose old carrier (the
diffusers-derived UNet3D) was deleted: it was never wired into any
registry or training path, and its upstream flax blocks no longer exist.
The replacement is a factorized spatial-temporal DiT built entirely from
the shared machinery - per-frame PatchSequenceEmbed (all scan orders
work), a spatial ModulatedBlock over each frame's tokens and a temporal
ModulatedBlock over the frame axis per layer, RoPE on the genuine 1D
time axis, and the shared modulated output head. Registered as
'video_dit' and wired end to end: DiffusionInputConfig now keeps the
time axis for 4-tuple video shapes (it silently dropped T before, so no
video model could even initialize through the trainer).

Tests: forward shapes, a temporal-mixing check (perturbing frame 0 must
change the prediction for frame 2), registry construction, and a 5D
end-to-end run through the real trainer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ined 2D checkpoints

The old diffusers-derived UNet3D could never have loaded our trained
UNets: different blocks, different param tree, and its upstream flax
modules no longer exist. This one mirrors our Unet exactly - same
blocks, same explicit module names, same auto-name ordering - so the
spatial param paths are identical, and inflate_unet_params drops a
trained 2D checkpoint straight into the 3D tree. The interleaved
temporal attention blocks (RoPE over the frame axis at every resolution
level) are zero-initialized, so an inflated model reproduces the image
model frame by frame and training only has to learn motion - the
AnimateDiff recipe, applied to our own pretrained models.

Verified by tests: an inflated UNet3D matches the 2D Unet per-frame to
1e-5 on the same inputs, temporal mixing activates once the gate moves
off zero, and the registry builds it ('unet_3d', wired in training.py
alongside 'video_dit').

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ss modality

The base ConditioningEncoder was text-shaped: tokenize() hardcoded
max_length/truncation and encode_from_tokens() hardcoded
input_ids/attention_mask, so no other modality could use it. Both are now
abstract and the text specifics live in TextEncoder, leaving a base class
that only knows 'raw data -> tokens -> embeddings'.

Audio arrives as AudioEncoder + HFAudioEncoder, which resolves any HF
audio model through the Auto* classes and forwards whatever keys its
processor emits (input_values for wav2vec2/HuBERT, input_features for
Whisper/AST) straight to the model - so swapping the audio model is a
config change and nothing more. Formats are already general upstream:
audio_utils.read_audio decodes via ffmpeg and resamples to the rate the
processor declares. AutoAudioProcessor is the data-pipeline counterpart
of AutoTextTokenizer, and the voxceleb2 audio-video transform now uses
it instead of calling AutoAudioTokenizer, which never existed - its class
body was commented out, so that path raised NameError and flake8's F821
had been failing CI on main since 2026-06-12.

Also fixes CLIPTextEncoder.from_modelname discarding its own modelname
argument.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AshishKumar4

Copy link
Copy Markdown
Owner Author

Landed on main as part of the full revamp stack (main fast-forwarded to bc9d06b). GitHub reports no new commits between this head and main, so every commit here is merged; closing as superseded by the stack merge rather than leaving it open.

@AshishKumar4
AshishKumar4 deleted the revamp/phase-2-restorations branch July 27, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant