Skip to content
Projetos

Zihan-Su/Self_Gradient_Forcing_Plus

Ver no GitHub

Sobre

Autoregressive video generation with decoupled context-writing and denoising parameters, enabling up to 24-hour generation from 5s training windows.

Design e mídia

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
+1
em 15 dias
+4
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

SGF+ logo Self Gradient Forcing Plus

Decoupling Gradient Flows for Autoregressive Video Generation

Project Page   arXiv: 2610.10429   Hugging Face   Blog Read

Zihan Su1,2*, Junhao Zhuang2*†, Yaowei Li2, Siwen Lu1, Haoran Li2, Lingen Li3, Haoyu Wu2
Weiyang Jin2, Songchun Zhang2, Haoyang Huang2, Chun Yuan1†, Zeyue Xue2, Nan Duan2

1Tsinghua University   2Joy Future Academy, JD   3The Chinese University of Hong Kong

*Equal contribution.   †Corresponding authors.

⭐ If Self Gradient Forcing Plus is useful for your research, please consider starring this repository.

SGF+ paper teaser: comparisons with SGF and SF over 240 seconds, and a 24-hour SGF+ rollout

🔥 News

  • 2026-12-02: Native Autoregressive Video puts two directions outlined in our SGF+ into practice: separating context-writing and denoising parameters during teacher-forcing pretraining to avoid gradient conflict on shared weights, and using a lightweight KV-cache writer to limit parameter overhead.

  • 2026-11-26: BoschDreams-7V reproduces the writer–denoiser gradient conflict identified in our SGF+ in its seven-camera driving world model, and adapts SGF+’s role-decoupling design with separate writer and denoiser LoRA adapters to mitigate gradient conflict and improve long-horizon consistency.

  • 2026-11-23: SparkStreamer adopts our SGF+ in its training pipeline, using separate cache-writing and denoising LoRA/RoLA parameters for streaming audio-video generation.

  • 2026-10-20: We release our blog Streaming Video Generation: Past and Future, tracing the evolution of autoregressive video generation. We hope it offers useful insights to the community.

  • 2026-10-9: We release the code for reproducing the gradient-conflict phenomena observed at the SGF and teacher-forcing initialization checkpoints. See the reproduction guide. In fact, beyond Wan2.1-1.3B, we have also observed this phenomenon in LTX-2.5.

  • 2026-10-7: Paper, model checkpoints, inference scripts, and training code are publicly released.

🎬 Video Comparisons

Left to right: Self Forcing · Self Gradient Forcing · Self Gradient Forcing Plus. More videos are available on our project page.

By the train window

https://github.com/user-attachments/assets/1fd94100-b832-4202-80ad-de5c8158f86d

A tiny monster, a candle

https://github.com/user-attachments/assets/af3fb848-2927-4b46-b9f6-8d62bd1dd31f

🧠 Method Overview

We uncover conflicting gradients between context writing and denoising in SGF. These gradients partially cancel on shared parameters, motivating separate optimization.

Gradient conflict between context writing and denoising: gradient distributions, mean directions, and paired cosine similarities

SGF+ separates context-writing and denoising parameters to resolve conflicting gradient updates, improving autoregressive video generation and enabling rollouts of up to 24 hours from only 5s training windows.

SGF and SGF+ training pipelines: no-gradient rollout followed by shared or role-specific gradient updates

🛠️ Installation

The environment follows the SGF setup.

git clone https://github.com/Zihan-Su/Self_Gradient_Forcing_Plus.git
cd Self_Gradient_Forcing_Plus

conda create -n sgf_plus python=3.10 -y
conda activate sgf_plus
pip install -r requirements.txt
pip install flash-attn --no-build-isolation
python setup.py develop

Run the following commands from the repository root.

⬇️ Download Weights

bash scripts/download_weights.sh

The script uses the Hugging Face CLI command hf by default. Set HF_CLI=huggingface-cli if your environment still uses the older command name.

It downloads:

  • Wan base models to wan_models/Wan2.1-T2V-1.3B and wan_models/Wan2.1-T2V-14B.
  • Causal-Forcing AR initialization checkpoints to checkpoints/init/chunkwise/ar_diffusion.pt and checkpoints/init/framewise/ar_diffusion.pt.
  • Released SGF+ inference checkpoints to hf_weights/chunkwise/model.pt and hf_weights/framewise/model.pt.
  • The training prompt list to prompts/vidprom_filtered_extended.txt.

Run hf auth login first if authentication is required.

🚀 Inference

The default prompt file is prompts/test_prompt.txt with 8 prompts. The launcher uses 8 GPUs when at least 8 GPUs are visible; otherwise it falls back to single-GPU serial inference. By default it generates 963 latent frames, which decode to about 240 seconds of video at 16 fps.

The inference script takes the release setting name (chunkwise or framewise) and a checkpoint path, and selects the matching config automatically:

  • chunkwise config: configs/sgf_plus_chunkwise.yaml
  • framewise config: configs/sgf_plus_framewise.yaml

The long-video KV-cache geometry is set in scripts/infer_self_gradient_forcing.sh, which is called by the SGF+ launcher. Chunkwise defaults to KV_CACHE_SINK=3, KV_CACHE_FIFO_FRAMES=6, and KV_CACHE_CURRENT_FRAMES=3, so --kv_cache_max_frames is 12. Framewise defaults to KV_CACHE_SINK=4, KV_CACHE_FIFO_FRAMES=16, and KV_CACHE_CURRENT_FRAMES=1, so --kv_cache_max_frames is 21.

Chunkwise

bash scripts/infer_sgf_plus.sh chunkwise hf_weights/chunkwise/model.pt

This uses:

configs/sgf_plus_chunkwise.yaml
hf_weights/chunkwise/model.pt

Framewise

bash scripts/infer_sgf_plus.sh framewise hf_weights/framewise/model.pt

This uses:

configs/sgf_plus_framewise.yaml
hf_weights/framewise/model.pt

Custom checkpoint or prompt file

bash scripts/infer_sgf_plus.sh \
  chunkwise \
  hf_weights/chunkwise/model.pt \
  prompts/test_prompt.txt

Useful overrides:

NUM_OUTPUT_FRAMES=963 SEED=42 OUTPUT_ROOT=outputs/demo \
  bash scripts/infer_sgf_plus.sh chunkwise hf_weights/chunkwise/model.pt

For trained checkpoints, pass the release setting first and the produced logs/.../checkpoint_model_*/model.pt path as the second argument. The script uses EMA weights by default; set USE_EMA=0 to use the non-EMA generator weights.

⚡ Inference with Reactor Runtime

The reactor/ integration serves SGF+ as an interactive video model with Reactor Runtime and a browser frontend. It uses the released chunkwise checkpoint on one NVIDIA B200, supports text and optional reference images, and lets you update the prompt while generation continues.

Install the Reactor CLI, Docker and the NVIDIA Container Toolkit. From the repository root, build and start the service on an available GPU; inference weights download automatically on first startup:

cd reactor
reactor build
reactor run --gpus device=0 --port 8080

Once http://localhost:8080/health reports "state":"available", open another terminal at the repository root and start the frontend (Node.js 22.12+ and npm):

cd reactor/demo
npm ci
npm run dev

Open the printed URL, normally http://localhost:5173, set Runtime URL to http://localhost:8080, and click Connect. Enter a prompt, optionally choose an image, then click Start new video. Use Update prompt to change subsequent chunks and Pause / Resume to hold or continue the same video. Playback stays at the original 16 FPS export rate. See the Reactor guide for controls, validation and remote connection requirements, including WebRTC over SSH.

🏋️ Training

All training runs reported in the paper use 64 GPUs without gradient accumulation.

Reference training budget: 1,900 steps for framewise SGF+ and 700 steps for chunkwise SGF+. The number of training steps needed may vary slightly across random seeds.

Parameter configuration: In the paper, we use two sets of full model parameters, one for each task. When applying SGF+ to larger-scale models, we recommend using two sets of LoRA adapters in the attention and FFN layers, with each set dedicated to one task. We provide example code and configurations for this dual-LoRA setup. See the dual-LoRA examples for chunkwise_dual_lora and framewise_dual_lora.

Chunkwise SGF+

bash scripts/train_sgf_plus_chunkwise.sh

Equivalent explicit form:

bash scripts/train_sgf_plus_chunkwise.sh \
  configs/sgf_plus_chunkwise.yaml \
  logs/sgf_plus_chunkwise

Framewise SGF+

bash scripts/train_sgf_plus_framewise.sh

Equivalent explicit form:

bash scripts/train_sgf_plus_framewise.sh \
  configs/sgf_plus_framewise.yaml \
  logs/sgf_plus_framewise

The launchers accept [config.yaml] [logdir] [extra train.py args...] and support single-node and multi-node training. Without explicit or scheduler-provided topology settings, nodes auto-register through .rendezvous/ on the shared filesystem and launch static torchrun with an IP master address. For multi-node jobs, run the same command on every node within the gather window.

Useful overrides:

GATHER_WINDOW=90 NUM_GPUS=8 MASTER_PORT=29501 ENABLE_WANDB=1 \
  bash scripts/train_sgf_plus_chunkwise.sh logs/sgf_plus_chunkwise

To specify the topology manually, set NNODES, NODE_RANK, MASTER_ADDR and MASTER_PORT. Use a distinct NODE_RANK on each node and matching values for the other settings.

📊 Gradient Conflict Experiments

To reproduce our gradient-conflict experiments, see the experiment guide.

🙏 Acknowledgements

This repository builds on Self Gradient Forcing, Causal-Forcing, and Wan.

📮 Contact

For questions, please contact Zihan Su at [email protected] or Junhao Zhuang at [email protected].

📜 License

This project is released under the Apache-2.0 license.

📚 Citation

@article{su2026sgf+,
  title={SGF+: Decoupling Gradient Flows for Autoregressive Video Generation},
  author={Su, Zihan and Zhuang, Junhao and Li, Yaowei and Lu, Siwen and Li, Haoran and Li, Lingen and Wu, Haoyu and Jin, Weiyang and Zhang, Songchun and Huang, Haoyang and others},
  journal={arXiv preprint arXiv:2610.10429},
  year={2026}
}

@article{zhuang2026self,
  title={Self Gradient Forcing: Native Long Video Extrapolation},
  author={Zhuang, Junhao and Zhang, Shiyi and Bian, Yuxuan and Li, Yaowei and Luo, Yawen and Liu, Yijun and Jin, Weiyang and Zhang, Songchun and He, Xianglong and Zhang, Xuying and others},
  journal={arXiv preprint arXiv:2607.20368},
  year={2026}
}

Explore projetos relacionados

Carregando…