UGG fine-tunes Wan2.2-TI2V-5B into a mixture-of-transformers with three experts:
RGB, camera rays (Plücker direction and moment) and depth. They share self-attention over the
concatenated sequence [rgb | ray | depth]. Training uses diffusion forcing: any subset of
frames and modalities can be clean (given), and the model generates the rest. One checkpoint
therefore handles:
video → 4D, image (+ cameras) → 4D, first/last frame (+ cameras) → 4D, text → 4D, cameras → 4D and depth → 4D (see the six tasks).
The code layout follows Large Video Planner:
Hydra configs in configurations/, Lightning modules in algorithms/, data in datasets/,
and the training loop in experiments/, all launched by main.py.
UGG/
├── ugg/ inference API: UGG.from_pretrained(), the six tasks, camera + depth coding, video IO, camera-path videos
├── assets/ sample scenes for every task (Bonn, RE10K, DL3DV) + text prompts
├── infer.py command-line inference (Hydra)
├── main.py training entry point (Hydra + Lightning), as in LVP
├── algorithms/wan/ the model (wan_t2v_ray_depth_mot_concat_5b.py) and Wan modules
├── datasets/ the 14 training datasets, the mixture, and a dummy dataset
├── experiments/ Lightning trainer / FSDP setup
├── configurations/
│ ├── algorithm/ugg.yaml release model: weights path, sampling defaults, training recipe
│ ├── algorithm/ugg_toy.yaml 2-block debug model
│ ├── experiment/ugg_train.yaml release training recipe (optimizer, batch, checkpointing)
│ ├── dataset/mixture_parallax14.yaml release training mixture
│ └── inference.yaml inference defaults (mode, seed, cameras, depth decode)
├── scripts/train_release.sbatch multi-node launcher
└── tests/
| path | |
|---|---|
| Release weights (30 GB, bf16) | Hugging Face amanim71/UGG (ugg_release.safetensors), downloaded on first use |
| Wan2.2-TI2V-5B (DiT config, VAE, UMT5-XXL) | Hugging Face Wan-AI/Wan2.2-TI2V-5B, cached under $HF_HOME |
The release path is set in configurations/algorithm/ugg.yaml
(model.tuned_ckpt_path); override it with algorithm.model.tuned_ckpt_path=... (a local
.safetensors/.ckpt file or <user>/<repo>/<file> on the Hub). After installing the environment
below and setting HF_HOME to your data volume, fetch everything ahead of time:
hf download amanim71/UGG ugg_release.safetensors
hf download Wan-AI/Wan2.2-TI2V-5B --include "config.json" --include "Wan2.2_VAE.pth" --include "models_t5_umt5-xxl-enc-bf16.pth" --include "google/*"
python -c 'from transformers import AutoTokenizer; AutoTokenizer.from_pretrained("google/umt5-xxl")'conda create -n ugg python=3.12 && conda activate ugg
pip install torch==2.9.0 torchvision==0.24.0 --index-url https://download.pytorch.org/whl/cu129
pip install -r requirements.txtFlash attention is recommended but not necessary. To install the prebuilt 2.8.3 flash attention wheel:
pip install --no-deps "https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3%2Bcu12torch2.9cxx11abiTRUE-cp312-cp312-linux_x86_64.whl"To install from Flash attention 2.7.4.post1 source, requires torch already installed, a C++ compiler, and Cuda 12.9 nvcc.
pip install ninja packaging psutil setuptools wheel
MAX_JOBS=8 pip install flash-attn==2.7.4.post1 --no-build-isolation --no-deps --no-cache-direxport HF_HOME=/path/to/hf_cache # where the Wan2.2 files are cached
export HF_HUB_OFFLINE=1 # optional: for compute nodes without internetInference needs one 80 GB GPU (about 40 GB peak; add 11 GB for T5 when using prompts).
Every task is the same model with a different set of clean (given) inputs; the rest is generated.
| task | given | generated | Python | trained setting |
|---|---|---|---|---|
| video → 4D | all frames | depth, cameras | model.video_to_4d(video) |
yes |
| image + cameras → 4D | first frame, cameras | frames, depth | model.image_to_4d(img, cameras=...) |
yes |
| first/last + cameras → 4D | first + last frame, cameras | frames, depth | model.first_last_to_4d(a, b, cameras=...) |
yes |
| text → 4D | caption | frames, depth, cameras | model.text_to_4d(prompt) |
approximately* |
| cameras → 4D | cameras (+ caption) | frames, depth | model.camera_to_4d(cameras) |
zero-shot |
| depth → 4D | depth (+ caption) | frames, cameras | model.depth_to_4d(depth) |
zero-shot |
Also available: image_to_4d(img) (image only) and model(video, mode="sparse") (first + last
frame, no cameras: the paper's sparse protocol). Training drew from five settings: first frame;
all frames; first + last frame + cameras; first frame + cameras; first frame + depth. Their history
tokens were themselves partially noised, so *text-only matches a fully-noised first frame. Cameras-
or depth-only without any frame was never trained and is zero-shot.
model.generate(video=... | images=[...], observe="all"|"first"|"first_last", cameras=..., depth=..., prompt=...)
takes any combination directly.
assets/ holds one scene per task, picked because they work well:
| folder | source | contents | use it for |
|---|---|---|---|
bonn_balloon2/ |
Bonn RGB-D Dynamic | frames.mp4 (50 frames) |
video → 4D |
re10k_staircase/ |
RealEstate10K test | first.png, last.png, cameras.npz, frames.mp4 |
image + cameras → 4D |
re10k_bedroom/ |
RealEstate10K test | same | first/last + cameras → 4D |
dl3dv_gallery/ |
DL3DV-10K test | same + caption.txt |
camera → 4D; image / first-last + cameras → 4D |
dl3dv_treatment_room/ |
DL3DV-10K test | same + caption.txt, depth.npz (metric, 0 = invalid) |
depth → 4D |
text_prompts.json |
indoor camera-motion captions | text → 4D |
cameras.npz stores the dataset's ground-truth cameras: c2w (T, 4, 4) is OpenCV
camera-to-world with the first camera at the origin, and intrinsics (T, 3, 3) is in pixels of
the 288×384 model input. frames.mp4 is the real clip, for comparing against what the model
generates. caption.txt is the dataset's caption of the clip.
Captions matter most when little is given. For camera- and depth-conditioned generation the
caption is the only appearance cue: without it, camera → 4D invents an unrelated scene and depth
→ 4D comes out dark and colourless. With frames given, a caption changes little (RE10K bedroom:
27.4 vs 27.2 dB). A caption that does not describe the clip actively hurts. RE10K captions
describe the whole video, so the staircase clip's caption, which describes the house exterior,
turns the indoor shot into a garden. Leave prompt empty unless you have a caption for the
clip itself.
Generation varies with the seed. On the staircase, image + cameras scores 18–25 dB PSNR across seeds 0–2 and 213. Try a few seeds for generation tasks; reconstruction (video → 4D) varies far less.
python scripts/run_examples.py runs every example below with its recommended settings and
writes them to outputs/examples/.
import numpy as np
from ugg import UGG
model = UGG.from_pretrained() # release weights + protocol defaults
cams = lambda s: tuple(np.load(f"assets/{s}/cameras.npz")[k] for k in ("c2w", "intrinsics"))
# video -> 4D
pred = model.video_to_4d("assets/bonn_balloon2/frames.mp4")
# image + cameras -> 4D
pred = model.image_to_4d("assets/re10k_staircase/first.png", cameras=cams("re10k_staircase"),
hist_guidance=1.5, sample_shift=0.9, seed=2)
# first + last image + cameras -> 4D
pred = model.first_last_to_4d("assets/re10k_bedroom/first.png", "assets/re10k_bedroom/last.png",
cameras=cams("re10k_bedroom"), hist_guidance=1.5, sample_shift=0.7,
sample_steps=60, seed=97)
# text -> 4D
pred = model.text_to_4d("The camera glides forward down a long marble corridor, past a colonnade of pale "
"stone arches that recede into soft daylight. Tall windows cast long rectangles of "
"light across the polished floor, and a vaulted ceiling curves overhead.",
num_frames=50, text_guidance=5.0, seed=11)
caption = lambda s: open(f"assets/{s}/caption.txt").read().strip()
# camera trajectory -> 4D (the caption supplies the appearance)
pred = model.camera_to_4d(cams("dl3dv_gallery"), prompt=caption("dl3dv_gallery"), hist_guidance=2.0, seed=29)
# depth -> 4D (anchored on the first and last frame: the trained pattern; drop images= for depth alone)
depth = np.load("assets/dl3dv_treatment_room/depth.npz")["depth"].astype(np.float32)
pred = model.depth_to_4d(depth, images=["assets/dl3dv_treatment_room/first.png", "assets/dl3dv_treatment_room/last.png"],
prompt=caption("dl3dv_treatment_room"), hist_guidance=2.0, seed=59)
pred.rgb # (T, H, W, 3) uint8
pred.depth # (T, H, W) relative depth (up to scale)
pred.depth_norm # (T, H, W) raw output: normalized disparity in [-1, 1]
pred.c2w # (T, 4, 4) camera-to-world (translation up to scale)
pred.intrinsics # (T, 3, 3)
pred.save("out/") # rgb.mp4, depth.mp4, cameras.mp4, *.npy, meta.jsonAny call takes seed, sample_steps, sample_shift, hist_guidance, text_guidance,
prompt, shared_intrinsics, percentile_clip and max_frames; unset arguments take the
config defaults. The values above are the ones that worked best per task. Generation tasks
like more history guidance (1.5–2) than reconstruction (1.0), and text needs strong text
guidance (5). Cameras from one prediction can drive another (cameras=pred). To change
defaults once, pass Hydra overrides:
model = UGG.from_pretrained(overrides=["algorithm.sample_steps=20", "seed=42", "percentile_clip=10"])
model = UGG.from_pretrained(ckpt="/path/to/other.ckpt")Loading reads the 30 GB checkpoint. On a network filesystem, copying it to local disk or
/dev/shm first and passing ckpt= makes loading several times faster.
python infer.py task=video input=assets/bonn_balloon2/frames.mp4 output_dir=out/video
python infer.py task=video input=assets/bonn_balloon2/frames.mp4 mode=sparse seed=1
python infer.py task=image input=assets/re10k_staircase/first.png cameras=assets/re10k_staircase/cameras.npz \
algorithm.hist_guidance=1.5 algorithm.sample_shift=0.9 seed=2
python infer.py task=first_last input=assets/re10k_bedroom/first.png last=assets/re10k_bedroom/last.png \
cameras=assets/re10k_bedroom/cameras.npz algorithm.hist_guidance=1.5 \
algorithm.sample_shift=0.7 algorithm.sample_steps=60 seed=97
python infer.py task=text 'prompt="The camera glides forward down a long marble corridor ..."' \
algorithm.lang_guidance=5 seed=11
python infer.py task=camera cameras=assets/dl3dv_gallery/cameras.npz algorithm.hist_guidance=2 seed=29 \
prompt="'$(cat assets/dl3dv_gallery/caption.txt)'"
python infer.py task=depth depth=assets/dl3dv_treatment_room/depth.npz algorithm.hist_guidance=2 seed=59 \
prompt="'$(cat assets/dl3dv_treatment_room/caption.txt)'" \
input=assets/dl3dv_treatment_room/first.png last=assets/dl3dv_treatment_room/last.png # optional anchors| key | default | |
|---|---|---|
task |
video |
CLI only: which inputs are given (table above). |
mode |
dense |
task=video only. dense: all RGB frames are history. sparse: frames 0 and T-1 only. |
num_frames |
50 | clip length when no video or cameras fix it (text, image alone). |
algorithm.sample_steps |
40 | UniPC steps (shift 3.0). 10 steps costs little on outdoor depth. |
algorithm.hist_guidance |
1.0 | guidance on the clean frames: f·(1+h) − h·f_no_history. 0 skips the extra forward pass. |
algorithm.lang_guidance |
0.0 | text classifier-free guidance; needs prompt. |
prompt |
null | null means an all-zero text embedding, which is what the paper numbers use. |
seed |
0 | the depth/pose protocol seed (the NVS protocol uses 42). |
max_frames, frame_mode |
50, contig_first |
uses the first M frames, where M is the largest value ≤ 50 with M % 4 == 2. uniform spreads them over the video instead. |
dataset.height, dataset.width |
288, 384 | the input is center-cropped to 3:4 and then resized. |
shared_intrinsics |
true | fits one K per clip when recovering cameras from rays (much better rotation). |
percentile_clip |
2.0 | disparity floor for the depth decode; 10 measured better outdoors. |
dit_bf16 |
true | runs the DiT in bf16. |
python -m main +name=smoke experiment=ugg_train algorithm=ugg_toy dataset=dummy \
dataset.n_frames=10 dataset.height=160 dataset.width=192 dataset.raymap_height=20 dataset.raymap_width=24 \
experiment.training.batch_size=1 experiment.training.max_steps=4 wandb.mode=disabledugg_toy is the release model truncated to 2 blocks, and dummy produces random tensors in the
training-sample format. Together they run the full path: VAE encode, diffusion-forcing noise,
loss, FSDP, the optimizer step and checkpointing.
The mixture reads every dataset from one root, data_dir (set in
configurations/config.yaml or on the command line):
<data_dir>/
├── tartanair/ tartanair_v2/ spring/ bedlam/ bedlam2/ vkitti2/ mid_air/ mvs_synth/
├── ase/ scenenet/ scenenet_gt_poses/ matrixcity/ omniworld_game/
├── re10k/ dl3dv_colmap/ dl3dv_colmap_prompt_embeds/
└── captions/<dataset>/ precomputed UMT5 caption embeddings (optional per dataset)
Each loader's docstring in datasets/ describes the layout it expects. Symlinks are fine.
python -m main +name=ugg_finetune experiment=ugg_train algorithm=ugg dataset=mixture_parallax14 \
data_dir=/path/to/data experiment.num_nodes=6
# or on SLURM (6 nodes x 4 GPUs, requeue-safe):
REPO=$PWD HF_HOME=... sbatch scripts/train_release.sbatch data_dir=/path/to/dataTo check that the full model trains on your hardware before a long run (one node with 4 × 80 GB GPUs, random data, about 25 minutes, mostly weight loading):
python -m main +name=full_smoke experiment=ugg_train algorithm=ugg dataset=dummy \
dataset.n_frames=10 dataset.height=160 dataset.width=192 dataset.raymap_height=20 dataset.raymap_width=24 \
experiment.training.batch_size=1 experiment.training.max_steps=2 algorithm.save_startup_checkpoint=false \
wandb.mode=disabled| release fine-tuning | |
|---|---|
| init | weights-only warm start (algorithm.model.tuned_ckpt_path) |
| trainable | RGB + ray experts (8.78 B). The depth expert (3.78 B) is frozen with gf_freeze_depth. |
| objective | flow matching, diffusion forcing ray_depth_prediction_firstlast, clean-token loss masked |
| data | mixture_parallax14: 14 datasets, 288×384, 50 frames |
| batch | 8 per GPU × 24 H200 = 192 |
| optimizer | AdamW (fp32 state), lr 6e-6 constant after 150 warmup steps, betas (0.9, 0.95), wd 0.05, clip 1.0 |
| memory | FSDP hybrid shard within node, use_orig_params, gradient checkpointing 0.93 |
| hardware | at least 4 × 80 GB GPUs per node: 3 × 80 GB runs forward and backward but OOMs at the first AdamW step |
| speed | FA3, compiled VAE encoder, merged FLF chunks: ≈ 8.5 s/step |
| release | step 2250 |
experiment=ugg_train: configurations/experiment/ugg_train.yaml: LR, batch size, max steps, checkpoint cadence, FSDP flags.algorithm=ugg: configurations/algorithm/ugg.yaml: initial weights, expert freeze, LR schedule, diffusion-forcing settings per dataset.dataset=mixture_parallax14: configurations/dataset/mixture_parallax14.yaml: the subsets, their sampling weights andmixture_seed.- Resume:
load=<run>/checkpoints/last.ckptrestores weights, optimizer and step (train_release.sbatchdoes this automatically on requeue). - Logging: set
wandb.entityin configurations/config.yaml, orwandb.mode=disabled.
python tests/test_cpu.py # CPU: imports, configs, video IO, depth decode, cameras
python tests/gpu_smoke.py # GPU: all six tasks on assets/, one model load
python tests/test_flash_attention.py # GPU: optional FA2 forward/backward numerical checks; requires FA2UGG is intended for research on video generation and 4D scene understanding. Outputs may contain inaccurate geometry or synthetic content. Users should disclose generated content and avoid deceptive, privacy-invasive, or safety-critical applications without independent validation.
This repo is forked from Boyuan Chen's research template
repo. By its MIT license, you must keep the
above sentence in README.md and the LICENSE file to credit the author. The model code builds on
Wan2.2 and follows the layout of
Large Video Planner. The sample scenes in
assets/ come from the Bonn RGB-D Dynamic, RealEstate10K and DL3DV-10K datasets.