JunhaoZhuang commited on
Commit
eb53677
ยท
verified ยท
1 Parent(s): 5a3fe36

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +198 -0
README.md CHANGED
@@ -1,3 +1,201 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+ <div align="center">
5
+
6
+ # โšก Self Gradient Forcing
7
+
8
+ ### Native Long-Video Extrapolation with Gradient-Recovered Autoregressive Training
9
+
10
+ <p>
11
+ <a href='http://zhuang2002.github.io/SelfGradientForcing'><img src='https://img.shields.io/badge/Project-Page-Green'></a> &nbsp;
12
+ <a href="https://arxiv.org/abs/2510.12747"><img src="https://img.shields.io/badge/arXiv-2510.12747-b31b1b.svg"></a> &nbsp;
13
+ <a href="https://huggingface.co/JunhaoZhuang/Self_Gradient_Forcing"><img src="https://img.shields.io/badge/๐Ÿค—%20Hugging%20Face-Models-yellow" alt="Hugging Face"></a> &nbsp;
14
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue" alt="License"></a>
15
+ </p>
16
+
17
+ <p>
18
+ <strong>Junhao Zhuang, Shiyi Zhang, Yuxuan Bian, Yaowei Li, Yawen Luo, Yijun Liu, Weiyang Jin, Songchun Zhang, Xianglong He, Xuying Zhang, Haoran Li, Haoyang Huang, Zeyue Xue, Nan Duan</strong>
19
+ </p>
20
+
21
+ <p>
22
+ Joy Future Academy, JD
23
+ </p>
24
+
25
+ <h4>
26
+ <a href="https://huggingface.co/JunhaoZhuang/Self_Gradient_Forcing">๐Ÿค— Model Weights</a>
27
+ ยท
28
+ <a href="mailto:zhuangjh23@mails.tsinghua.edu.cn">๐Ÿ“ฎ Contact</a>
29
+ ยท
30
+ <a href="LICENSE">๐Ÿ“œ License</a>
31
+ </h4>
32
+
33
+ โญ If Self Gradient Forcing is useful for your research, please consider starring this repository.
34
+
35
+ </div>
36
+
37
+ <p align="center">
38
+ <img src="https://github.com/zhuang2002/Self_Gradient_Forcing/blob/main/assets/teaser.jpg" width="95%" alt="Self Gradient Forcing teaser">
39
+ </p>
40
+
41
+ ## ๐Ÿ”ฅ News
42
+
43
+ - **2026-07-23**: Paper, model checkpoints, inference scripts, and training code are publicly released.
44
+
45
+ ## ๐Ÿง  Method Overview
46
+
47
+ Self Gradient Forcing (SGF) recovers the missing context-gradient path for self-generated causal memory through a bounded two-pass replay, enabling models trained with only a 5-second window to extrapolate to minute-scale videos with stronger identity, layout, and temporal stability.
48
+
49
+ <p align="center">
50
+ <img src="https://github.com/zhuang2002/Self_Gradient_Forcing/blob/main/assets/flowchat.jpg" width="95%" alt="Self Gradient Forcing method overview">
51
+ </p>
52
+
53
+ ## ๐Ÿ› ๏ธ Installation
54
+
55
+ The environment follows the Causal-Forcing setup.
56
+
57
+ ```bash
58
+ conda create -n self_gradient_forcing python=3.10 -y
59
+ conda activate self_gradient_forcing
60
+
61
+ pip install -r requirements.txt
62
+ pip install flash-attn --no-build-isolation
63
+ python setup.py develop
64
+ ```
65
+
66
+ ## โฌ‡๏ธ Download Weights
67
+
68
+ ```bash
69
+ bash scripts/download_weights.sh
70
+ ```
71
+
72
+ 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.
73
+
74
+ It downloads:
75
+
76
+ - Wan base models to `wan_models/Wan2.1-T2V-1.3B` and `wan_models/Wan2.1-T2V-14B`.
77
+ - All [Causal-Forcing](https://github.com/thu-ml/Causal-Forcing) initialization checkpoints under `checkpoints/init/framewise/` and `checkpoints/init/chunkwise/`: `ar_diffusion.pt`, `causal_cd.pt`, and `causal_ode.pt`.
78
+ - Released SGF inference checkpoints to `checkpoints/framewise/ar/model.pt` and `checkpoints/chunkwise/ar/model.pt`.
79
+ - The training prompt list to `prompts/vidprom_filtered_extended.txt`.
80
+
81
+ ## ๐Ÿš€ Inference
82
+
83
+ 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.
84
+ The inference script takes the release setting name (`framewise` or `chunkwise`) and selects the matching config and checkpoint automatically:
85
+
86
+ - framewise config: `configs/self_gradient_forcing_framewise.yaml`
87
+ - chunkwise config: `configs/self_gradient_forcing_chunkwise.yaml`
88
+
89
+ The long-video KV-cache geometry is set in `scripts/infer_self_gradient_forcing.sh`. Framewise defaults to `KV_CACHE_SINK=4`, `KV_CACHE_FIFO_FRAMES=16`, and `KV_CACHE_CURRENT_FRAMES=1`, so the actual `--kv_cache_max_frames` passed to `inference.py` is `4 + 16 + 1 = 21`. 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`.
90
+
91
+ ### Framewise
92
+
93
+ ```bash
94
+ bash scripts/infer_self_gradient_forcing.sh framewise
95
+ ```
96
+
97
+ This uses:
98
+
99
+ ```text
100
+ configs/self_gradient_forcing_framewise.yaml
101
+ checkpoints/framewise/ar/model.pt
102
+ ```
103
+
104
+ ### Chunkwise
105
+
106
+ ```bash
107
+ bash scripts/infer_self_gradient_forcing.sh chunkwise
108
+ ```
109
+
110
+ This uses:
111
+
112
+ ```text
113
+ configs/self_gradient_forcing_chunkwise.yaml
114
+ checkpoints/chunkwise/ar/model.pt
115
+ ```
116
+
117
+ ### Custom checkpoint or prompt file
118
+
119
+ ```bash
120
+ bash scripts/infer_self_gradient_forcing.sh \
121
+ framewise \
122
+ checkpoints/framewise/ar/model.pt \
123
+ prompts/test_prompt.txt
124
+ ```
125
+
126
+ Useful overrides:
127
+
128
+ ```bash
129
+ NUM_OUTPUT_FRAMES=963 SEED=42 OUTPUT_ROOT=outputs/demo \
130
+ bash scripts/infer_self_gradient_forcing.sh framewise
131
+ ```
132
+
133
+ 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` if you explicitly want the non-EMA `generator` weights.
134
+
135
+ ## ๐Ÿ‹๏ธ Training
136
+
137
+ ### Framewise SGF
138
+
139
+ ```bash
140
+ bash scripts/train_self_gradient_forcing_framewise.sh
141
+ ```
142
+
143
+ Equivalent explicit form:
144
+
145
+ ```bash
146
+ bash scripts/train_self_gradient_forcing_framewise.sh \
147
+ configs/self_gradient_forcing_framewise.yaml \
148
+ logs/sgf_framewise
149
+ ```
150
+
151
+ ### Chunkwise SGF
152
+
153
+ ```bash
154
+ bash scripts/train_self_gradient_forcing_chunkwise.sh
155
+ ```
156
+
157
+ Equivalent explicit form:
158
+
159
+ ```bash
160
+ bash scripts/train_self_gradient_forcing_chunkwise.sh \
161
+ configs/self_gradient_forcing_chunkwise.yaml \
162
+ logs/sgf_chunkwise
163
+ ```
164
+
165
+ The launchers accept `[config.yaml] [logdir] [extra train.py args...]`, matching the multi-node launcher convention used by the reference training scripts. They support single-node and multi-node training. For multi-node jobs, run the same command on every node within the gather window. The scripts auto-register nodes through `.rendezvous/` on the shared filesystem and launch static `torchrun` with an IP master address.
166
+
167
+ Useful overrides:
168
+
169
+ ```bash
170
+ GATHER_WINDOW=90 NUM_GPUS=8 MASTER_PORT=29501 ENABLE_WANDB=1 \
171
+ bash scripts/train_self_gradient_forcing_framewise.sh logs/sgf_framewise
172
+
173
+ NNODES=2 NODE_RANK=0 MASTER_ADDR=10.0.0.1 NUM_GPUS=8 \
174
+ bash scripts/train_self_gradient_forcing_chunkwise.sh logs/sgf_chunkwise
175
+ ```
176
+
177
+ ## ๐Ÿ™ Acknowledgements
178
+
179
+ This implementation builds on the Wan video model ecosystem and follows the installation conventions of `thu-ml/Causal-Forcing`. We thank the open-source community for the infrastructure that made this release possible.
180
+
181
+ ## ๐Ÿ“ฎ Contact
182
+
183
+ For questions, please contact Junhao Zhuang at [zhuangjh23@mails.tsinghua.edu.cn](mailto:zhuangjh23@mails.tsinghua.edu.cn).
184
+
185
+ ## ๐Ÿ“œ License
186
+
187
+ This project is released under the Apache-2.0 license.
188
+
189
+ ### ๐Ÿ“œ Citation
190
+
191
+ ```bibtex
192
+ @article{zhuang2026sgf,
193
+ title = {Self Gradient Forcing: Native Long Video Extrapolation},
194
+ author = {Zhuang, Junhao and Zhang, Shiyi and Bian, Yuxuan and Li, Yaowei
195
+ and Luo, Yawen and Jin, Weiyang and Zhang, Songchun and He, Xianglong
196
+ and Zhang, Xuying and Li, Haoran and Huang, Haoyang and Xue, Zeyue
197
+ and Duan, Nan},
198
+ journal = {arXiv preprint},
199
+ year = {2026}
200
+ }
201
+ ```