Extensions/MoBack-Turbo
ComfyUI Extension

MoBack-Turbo

End-to-end 4-step video background replacement with text (Task A), background image (Task B), or edited-keyframe (Task C) guidance based on Wan2.2 and Qwen3-VL (Linux/CUDA). Uses native VIDEO ports and supports resident, --offload-dit, and --low-vram (24 GB VRAM) modes.

By Orange-3DV-Team·Created 3 days ago·Updated a day ago· 7
Orange-3DV-Team/MoBack
Nodes—
On cloudLocal install
Stars7
Updateda day ago
Readme
<div align="center"> <img src="assets/MoBack-horizontal.webp" alt="MoBack" width="460"> <h3>End-to-End Video Background Replacement with Versatile Guidance</h3> <p> <a href="https://orange-3dv-team.github.io/MoBack/"><img src="https://img.shields.io/badge/Project%20Page-MoBack-2C78FF?style=flat-square" alt="Project Page"></a> <a href="https://arxiv.org/abs/2612.03507"><img src="https://img.shields.io/badge/arXiv-2612.03507-B31B1B?style=flat-square&logo=arxiv&logoColor=white" alt="arXiv:2612.03507"></a> <a href="https://huggingface.co/ShaoDingBao/MoBack-Turbo"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-MoBack--Turbo-FFD21E?style=flat-square" alt="Hugging Face: MoBack-Turbo"></a> <a href="https://www.modelscope.cn/models/lalaalla/MoBack-Turbo"><img src="https://img.shields.io/badge/%F0%9F%A4%96%20ModelScope-MoBack--Turbo-624AFF?style=flat-square" alt="ModelScope: MoBack-Turbo"></a> <a href="comfyui/README.md"><img src="https://img.shields.io/badge/ComfyUI-Supported-2C78FF?style=flat-square" alt="ComfyUI Supported"></a> <img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python 3.10+"> <img src="https://img.shields.io/badge/PyTorch-2.12+-EE4C2C?style=flat-square&logo=pytorch&logoColor=white" alt="PyTorch 2.12+"> <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-FF8000?style=flat-square" alt="License: Apache 2.0"></a> </p> <p> <a href="#news">News</a> • <a href="#overview">Overview</a> • <a href="#setup--weights">Setup &amp; Weights</a> • <a href="#inference">Inference</a> • <a href="#comfyui">ComfyUI</a> • <a href="#citation">Citation</a> </p> <br> <img src="assets/teaser.webp" alt="MoBack Tasks A, B, and C Overview" width="100%"> </div>

News

  • [2026-12-02] Released the technical report on arXiv (2612.03507)!
  • [2026-12-01] Open-sourced MoBack-Turbo — 4-step background replacement code, pretrained weights on Hugging Face & ModelScope, Project Page, and native ComfyUI nodes.
  • [2026-12-01] Released the Stage-1 Vision-based KD T2V conditioner (stage1_t2v/, 845 MB, VBench 82.61) and standalone T2V pipeline (infer_t2v.py) for native Wan2.2-T2V-A14B.
  • [2026-12-01] Major inference optimizations: fused Triton kernels (TMA block-sparse VSA, fused AdaLN/residual-norm, RMSNorm+RoPE+pack, channels-last 3D VAE), double-buffered async DiT block offloading (--offload-dit / --low-vram), and one-sentence AI agent deployment (AGENTS.md).

Overview

MoBack is a unified, end-to-end video background replacement framework that synthesizes new dynamic backgrounds and harmonizes foreground illumination while preserving subject identity and motion—without external matting or masks. This repository provides MoBack-Turbo (4-step distilled inference with Video Sparse Attention and custom Triton kernels) and the Stage-1 aligned MLLM–DiT T2V pipeline.

| Task | Guidance Mode | Required Inputs | | :---: | :--- | :--- | | A | Text-Guided Replacement | Source video + text instruction | | B | Background Reference | Source video + instruction + 1–3 background images & anchors | | C | Keyframe Propagation | Source video + instruction + 1–3 edited full frames & anchors |

<p align="center"> <img src="assets/moback_method.webp" alt="MoBack Architecture" width="100%"> </p>
  • Stage 1 (MLLM–DiT Alignment): Aligns Qwen3-VL-8B-Instruct (rank-64 LoRA + learnable queries + 2-layer MLP connector) to Wan2.2-T2V-A14B via multi-task pre-training and vision-based knowledge distillation from umT5.
  • Stage 2 (Unified Editing): Concatenates reference, target, and source latents along the frame axis with frame-aligned 3D RoPE, reference type embedding ($E_r$), and subframe anchor embedding ($E_s$), trained on MoBack-100K (105,191 pairs).
  • MoBack-Turbo: Applies 4×4×4 segment-aware VSA and phased distribution-matching distillation across high/low-noise experts (2 + 2 steps, guidance = 1).

Setup & Weights

One-Sentence AI Agent Setup

Let an AI coding agent (Claude Code, Codex, Antigravity, Cursor, Gemini CLI, Windsurf) deploy everything automatically using AGENTS.md and scripts/check_env.py:

Clone https://github.com/Orange-3DV-Team/MoBack (or use this checkout), read AGENTS.md, run python3 scripts/check_env.py --weights weights --check-mirrors --json, install the matching CUDA PyTorch environment, download the required weights from the fastest reachable hub (Hugging Face / HF-Mirror / ModelScope), pick the right VRAM flags for my GPU, and run a verification smoke test.
<details> <summary><b>中文一句话部署提示词(直接发给 AI Agent)</b></summary>
克隆 https://github.com/Orange-3DV-Team/MoBack(或直接使用当前目录),阅读 AGENTS.md 并运行 python3 scripts/check_env.py --weights weights --check-mirrors --json,按本机 GPU 显存和 CUDA 版本自动配置 .venv 环境,自动选择最快的镜像源(ModelScope / HF-Mirror / Hugging Face)下载所需权重,匹配合适的显存优化参数并跑通冒烟测试。
</details>

<a id="installation"></a>

Manual Installation

Requires Linux with a CUDA/BF16-capable GPU, Triton, and Python 3.10+ (reference: Python 3.10.13, PyTorch 2.12.1 / CUDA 13.0):

git clone https://github.com/Orange-3DV-Team/MoBack.git && cd MoBack
python -m venv .venv && source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cu130  # match your CUDA
python -m pip install -r requirements.txt
python infer.py --help

Model Weights

| CLI Flag | Component | Hugging Face | ModelScope | Expected Contents | | :--- | :--- | :---: | :---: | :--- | | <code>-⁠-⁠model</code> | MoBack-Turbo bundle | 🤗 Download | 🤖 Download | high_noise_model/, low_noise_model/, query_contract.json, query_ema.safetensors | | <code>-⁠-⁠lora</code> | Paired Turbo LoRAs | 🤗 Download | 🤖 Download | adapters/high_noise_model.safetensors, adapters/low_noise_model.safetensors (in bundle) | | <code>-⁠-⁠conditioner</code> | Stage-1 KD T2V conditioner | 🤗 Download | 🤖 Download | stage1_t2v/query_conditioner.safetensors (845 MB), query_contract.json (in bundle) | | <code>-⁠-⁠qwen</code> | Qwen3-VL-8B-Instruct | 🤗 Download | 🤖 Download | Complete local directory (weights, tokenizer, video processor, chat template) | | <code>-⁠-⁠vae</code> / <code>-⁠-⁠wan</code> | Wan2.2-T2V-A14B & VAE | 🤗 Download | 🤖 Download | Wan2.1_VAE.pth (plus high_noise_model/ & low_noise_model/ for Stage-1 T2V) |

# Hugging Face (full bundle, or add --include "stage1_t2v/*" for the 845 MB T2V conditioner only)
hf download ShaoDingBao/MoBack-Turbo --local-dir weights/MoBack-Turbo

# ModelScope
pip install modelscope && modelscope download --model lalaalla/MoBack-Turbo --local_dir weights/MoBack-Turbo
<details> <summary><b>Expected directory layout &amp; precision protocol</b></summary>
weights/
├── MoBack-Turbo/                 # --model (adapters/ -> --lora, stage1_t2v/ -> --conditioner)
├── Qwen3-VL-8B-Instruct/         # --qwen
├── Wan2.2-T2V-A14B/              # --wan (for infer_t2v.py)
└── Wan2.1_VAE.pth                # --vae
  • Paired DiT LoRAs merge in FP32 (strength = 1.0); experts run in BF16 while initial noise and flow updates stay in FP32.
  • MoBack-Turbo samples deterministically in 4 steps (LightX2VFourStep, shift = 5, guidance = 1, 2 + 2 high/low-noise steps).
</details>

Inference

1. Background Replacement (infer.py)

Edit examples/jobs.jsonl (one JSON object per line, zero-based frame indices) and run:

{"id": "task_a", "task": "A", "source_video": "/path/to/source.mp4", "prompt": "Replace the background with a sunlit garden.", "num_frames": 49}
{"id": "task_b", "task": "B", "source_video": "/path/to/source.mp4", "prompt": "Replace the background using Picture 1. Preserve the subject and motion.", "reference_images": ["/path/to/background.png"], "anchor_frame_indices": [0], "num_frames": 49}
{"id": "task_c", "task": "C", "source_video": "/path/to/source.mp4", "prompt": "Propagate the edit from Picture 1 at frame 24, preserving motion.", "reference_images": ["/path/to/edited_frame.png"], "anchor_frame_indices": [24], "num_frames": 49}
CUDA_VISIBLE_DEVICES=0 python infer.py \
  --model weights/MoBack-Turbo --lora weights/MoBack-Turbo/adapters \
  --qwen weights/Qwen3-VL-8B-Instruct --vae weights/Wan2.1_VAE.pth \
  --manifest examples/jobs.jsonl --output results
<details> <summary><b>Manifest schema &amp; Task C multi-turn keyframe helper (<code>edit_keyframes.py</code>)</b></summary>
  • Manifest fields: id, task ("A"/"B"/"C"), source_video, prompt, reference_images (1–3 images matching source dimensions for B/C), anchor_frame_indices (1–3 zero-based sampled frame indices), clip_start_frame (0), num_frames (49, must be 4k + 1), frame_stride (1), seed (42), resolution_mode ("original", "max_side" + resolution_max_side, or "fixed" + height/width divisible by 16). Existing <output>/<id>.mp4 files are never overwritten.
  • Task C Keyframe Editing: Inspired by AVE, edit_keyframes.py edits anchor keyframes sequentially inside a shot-local Gemini-compatible conversation (x-goog-api-key) for cross-frame consistency and outputs a ready-to-run task_c.jsonl:
export GEMINI_BASE_URL='https://YOUR-API-HOST/v1beta' GEMINI_MODEL='YOUR-IMAGE-EDITING-MODEL'
read -rsp 'Gemini API key: ' GEMINI_API_KEY && export GEMINI_API_KEY
python edit_keyframes.py --config examples/keyframes.json --output results/keyframes
</details>

2. Stage-1 Text-to-Video (infer_t2v.py)

Run pure T2V with our Stage-1 KD conditioner (stage1_t2v/, VBench 82.61) + frozen native Wan2.2-T2V-A14B (skips the vision tower and requires no umT5):

# Single prompt (or replace --prompt/--id with --manifest examples/t2v.jsonl)
CUDA_VISIBLE_DEVICES=0 python infer_t2v.py \
  --wan weights/Wan2.2-T2V-A14B --conditioner weights/MoBack-Turbo/stage1_t2v \
  --qwen weights/Qwen3-VL-8B-Instruct \
  --prompt "A cute corgi running along a sunlit sandy beach as gentle ocean waves roll onto the shore." \
  --id corgi --height 512 --width 512 --num-frames 49 --seed 2027 \
  --output results/t2v

Defaults match the paper VBench protocol (--sampler unipc --steps 20 --shift 12.0 --guidance-scale 5.0 --boundary 0.875). Also supports --sampler euler and optional 4-step Wan2.2-Lightning --lora (auto-switches to lightx2v, 4 steps, guidance = 1.0).

<a id="lower-gpu-memory-use"></a>

3. Memory Optimization

Both infer.py and infer_t2v.py support composable offloading flags with identical numerical semantics (set PYTORCH_ALLOC_CONF=expandable_segments:True on tight GPUs):

| CLI Flags | Active GPU Footprint | Recommended GPU | | :--- | :--- | :--- | | (Default) | Resident Qwen3-VL, then one resident DiT expert | >= 80 GB (H100 / H200 / RTX PRO 6000) | | --offload-dit | Resident Qwen3-VL, then double-buffered 1 DiT block at a time | 48–79 GB (A6000 / L40S) | | --low-vram | 1 Qwen decoder layer at a time + 1 DiT block at a time | 24–47 GB (RTX 4090 / 5090 / 3090) | | --low-vram --offload-vae-cache | Same as above + offloads VAE causal frame cache to CPU RAM | < 24 GB |


ComfyUI

Native ComfyUI nodes (tested on ComfyUI 0.23.0) using ComfyUI's built-in VIDEO type. Install directly into ComfyUI/custom_nodes/ (or via ComfyUI-Manager once listed), or link with an isolated .venv:

# Direct install into ComfyUI/custom_nodes/
git clone https://github.com/Orange-3DV-Team/MoBack.git /path/to/ComfyUI/custom_nodes/MoBack
pip install -r /path/to/ComfyUI/custom_nodes/MoBack/requirements.txt

# Or keep an isolated Turbo environment
ln -s /path/to/MoBack/comfyui /path/to/ComfyUI/custom_nodes/MoBack-Turbo
cd /path/to/ComfyUI && MOBACK_TURBO_PYTHON=/path/to/MoBack/.venv/bin/python python main.py

See comfyui/README.md for weight placement and example workflows (text_edit.json, keyframe_edit.json).


Citation

If you find MoBack useful in your research or applications, please consider citing:

@article{shao2026moback,
  title         = {MoBack: End-to-End Video Background Replacement with Versatile Guidance},
  author        = {Dingbao Shao and Bojun Xiong and Shuai Huang and Jiawei Lu and Jun Liang and Ying Tai and Yunlong Feng and Zili Yi and Jing Li},
  journal       = {arXiv preprint arXiv:2612.03507},
  year          = {2026},
  eprint        = {2612.03507},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CV},
  url           = {https://arxiv.org/abs/2612.03507}
}

Acknowledgements & License

  • Wan & VideoX-Fun — Wan DiT backbone and causal 3D VAE
  • LightX2V — Four-step distillation schedule and LoRA conventions
  • FastVideo — Forward Triton block-sparse attention kernels (adapted from commit 10bdf5e; see ops/fastvideo/LICENSE)
  • FlowPortal — Residual-corrected flow framework used in synthetic training pair construction for MoBack-100K
  • AVE (paper) — Multi-turn in-context keyframe editing paradigm (Transforming Image Editors into Video Editors) that inspired our Task C keyframe helper (edit_keyframes.py)

Pretrained model weights are subject to their respective licenses. This codebase is released under the Apache License 2.0.