kylinfires commited on
Commit
2aa4b75
·
verified ·
1 Parent(s): a590b35

README: 中文说明 + 量化结论 + 文本流剥离方向

Browse files
Files changed (1) hide show
  1. README.md +74 -192
README.md CHANGED
@@ -1,225 +1,107 @@
1
- ---
2
- license: apache-2.0
3
- language:
4
- - en
5
- - zh
6
- library_name: diffusers
7
- pipeline_tag: video-to-video
8
- base_model: jdopensource/JoyAI-Video-Edit
9
- tags:
10
- - video-editing
11
- - streaming
12
- - quantization
13
- - int8
14
- - int4
15
- - rocm
16
- ---
17
 
18
- # JoyAI-Video-Edit · optimization fork
 
19
 
20
- Fork of [jdopensource/JoyAI-Video-Edit](https://huggingface.co/jdopensource/JoyAI-Video-Edit)
21
- (Apache-2.0) focused on **deployability**: portable kernels, quantization tooling and
22
- measured quality numbers.
23
 
24
- Mirror: [github.com/q760440238/JoyAI-Video-Edit-optimized](https://github.com/q760440238/JoyAI-Video-Edit-optimized)
25
 
26
- ## What this fork adds
 
 
 
 
 
 
 
27
 
28
- - `deploy/xvideo/models/dit/fused_ops_torch.py` — pure-PyTorch equivalents of the
29
- `joyomni_ops` CUDA kernels (LayerNorm+modulate, QK-norm+3D RoPE, RMSNorm).
30
- Verified bit-exact against the CUDA path (99.997% identical, max 1 bf16 ulp).
31
- - `sgl_fused_ops.py` — automatic fallback to the torch path when `joyomni_ops`
32
- cannot be imported (ROCm / CPU / any backend).
33
- - `int4_linear.py` — int4 (group-wise) and int8 (per-channel) weight-only Linear,
34
- plus state-dict loaders for both formats.
35
- - `models.py` — `JOYOMNI_DIT_SD_DIR` (bf16 shards) and `JOYOMNI_DIT_INT4_DIR`
36
- (quantized) load paths alongside the original checkpoint loader.
37
- - `tools/quantization/` — RTN int4 (gs=64), int8, and attention-int8/MLP-int4 (gs=16).
38
- - `tools/jve_client.py` — headless WebSocket driver (reference image + prompt + frames).
39
 
40
- ## Measured quality (840x480, same weights/prompt/frames)
41
 
42
- | precision | weight size | PSNR vs bf16 | identity similarity |
43
  |---|---:|---:|---:|
44
- | bf16 | 31.8 GB | — | 0.314 |
45
- | **int8** | 15.2 GiB | 21.8 dB | **0.359** |
46
- | int4 (gs=64) | 8.1 GiB | 19.0 dB | 0.103 |
47
- | attn int8 + MLP int4 (gs=16) | 11.4 GiB | 19.2 dB | 0.199 |
48
 
49
- The pipeline is deterministic across restarts (identical int4 weights in two fresh
50
- processes: PSNR 138 dB), so these differences are real, not measurement noise.
51
 
52
- **int4 breaks reference-guided person swapping**; int8 preserves it. The identity
53
- signal lives entirely in the attention path — quantizing only attention to int4
54
- collapses the swap even with every MLP left in bf16.
55
 
56
- ---
57
 
58
- <h1 align="center">JoyAI-Video-Edit</h1>
59
- <h3 align="center">Real-Time Open-Ended Video Editing with Autoregressive Diffusion</h3>
60
-
61
- <p align="center">
62
- <a href="https://arxiv.org/abs/2608.03974"><img src="https://img.shields.io/badge/Paper-arXiv-red" alt="Paper"></a>
63
- <a href="https://huggingface.co/jdopensource/JoyAI-Video-Edit"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Checkpoint-JoyAI--Video--Edit-yellow" alt="Hugging Face"></a>
64
- <a href="https://huggingface.co/spaces/wxDai/joyai-video-edit"><img src="https://img.shields.io/badge/%F0%9F%9A%80%20Demo-Streaming--V2V-orange" alt="Demo"></a>
65
- <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License"></a>
66
- </p>
67
-
68
- <p align="center">
69
- <img src="assets/teaser.jpg" width="96%" alt="JoyAI-Video-Edit teaser">
70
- </p>
71
-
72
- JoyAI-Video-Edit is a real-time, instruction-guided video editing system for open-ended video streams. Given a live camera stream or uploaded video and a natural-language edit instruction, it edits frames causally as they arrive, without waiting for the full video, requiring a predefined video length, or revisiting future frames. In our deployment benchmark, the full end-to-end pipeline reaches 30 FPS at 720 × 1248, pushing video editing from offline batch processing toward interactive streaming generation.
73
-
74
- The system combines an MLLM-based condition encoder, a causal video VAE, and a 16B-parameter multimodal diffusion transformer. It is trained and deployed as an autoregressive diffusion editor, then accelerated with aligned autoregressive distribution matching distillation, long-horizon optimization, bounded KV-state inference, and deployment-oriented scheduling to sustain high-throughput 720p editing while reducing train-inference mismatch and accumulated temporal drift.
75
-
76
- ## 🔥🔥🔥 News!!
77
-
78
- - 2026.10.09: 🎉 We open-source our **[example training scripts](training/README.md)** and release **[LongV2VBench](https://huggingface.co/datasets/EasonXiao-888/LongV2VBench)** for long-form video-to-video editing evaluation.
79
- - 2026.08.24: 🎉 Consumer GPU support landed — real-time streaming video editing on a single GeForce RTX 5090 (32 GB): 840 × 480 @ 24 FPS. **[Deployment Guide](DEPLOYMENT.md)**
80
- - 2026.08.15: 🎉 Live demo released — real-time streaming video editing on a single RTX PRO 6000 (Blackwell) GPU: 840 × 480 @ 24 FPS or 720p @ 16 FPS. **[Try HuggingFace Demo](https://huggingface.co/spaces/wxDai/joyai-video-edit)**
81
- - 2026.08.14: 🎉 Released an upgraded checkpoint with significantly stronger reference-image-guided video editing (RV2V), delivering better subject and identity preservation, more faithful reference conditioning, and improved temporal consistency across long streams. Grab the new **[DiT weights](https://huggingface.co/jdopensource/JoyAI-Video-Edit/blob/main/dit/joyai_video_edit_dit_0811.pth)**.
82
- - 2026.08.05: 🎉 We release the deployment code, [technical report](https://arxiv.org/abs/2608.03974), and JoyAI-Video-Edit checkpoints. Please check the links above for details.
83
-
84
- ## 💎 Highlights
85
-
86
- - **Real-time open-ended editing.** Edits live or uploaded videos as frames arrive, without requiring the full sequence upfront.
87
- - **Diverse instruction control.** Supports subject edits, local edits, background changes, style transfer, motion changes, and reference-guided editing.
88
- - **Autoregressive diffusion design.** Combines an MLLM condition encoder, causal video VAE, and MMDiT backbone for streaming video editing.
89
- - **High-throughput 720p deployment.** Reaches 30 FPS end-to-end throughput at 720 × 1248 with bounded KV-state inference and stable per-chunk compute.
90
-
91
- ## 🕹️ Live Demo
92
-
93
- Point your webcam at yourself, type an instruction, and watch the edit stream back in real time — try it in the browser: **[Hugging Face Demo](https://huggingface.co/spaces/wxDai/joyai-video-edit)**. The screenshots below are captured live from it (left: camera source, right: streamed result).
94
-
95
- <p align="center">
96
- <img src="assets/live_demo/live_cartoon_group.jpg" width="96%" alt="Live demo — turn all people into cartoon style">
97
- </p>
98
-
99
- <table>
100
- <tr>
101
- <td><img src="assets/live_demo/live_optimus_prime.jpg" alt="Live demo — transform into Optimus Prime with background unchanged"></td>
102
- <td><img src="assets/live_demo/live_gundam.jpg" alt="Live demo — transform into a Gundam via reference-guided editing"></td>
103
- </tr>
104
- <tr>
105
- <td><img src="assets/live_demo/live_hanfu_palace.jpg" alt="Live demo — Ming-style gown outfit change with ancient palace background"></td>
106
- <td><img src="assets/live_demo/live_cel_anime.jpg" alt="Live demo — add cap and sunglasses, convert to hand-drawn cel animation"></td>
107
- </tr>
108
- </table>
109
-
110
- ## 🚧 TODO
111
-
112
- - [x] **Stronger model version in progress.** A more powerful version is under active development, with a particular focus on advancing reference-image-guided video editing (RV2V) capabilities.
113
- - [x] **Consumer GPU support.** Optimize deployment for consumer-grade GPUs such as GeForce RTX 5090.
114
- - [x] **LongV2VBench release.** Release LongV2VBench for long-form video-to-video editing evaluation.
115
- - [x] **Release full training and data pipelines.** Open-source the training framework and data generation pipeline.
116
- - [ ] **Diffusers support.** Provide a 🤗 Diffusers pipeline for JoyAI-Video-Edit to streamline loading and inference.
117
-
118
- ## 🎬 Showcase
119
-
120
- JoyAI-Video-Edit is designed for broad video editing tasks, including global appearance changes, local object edits, subject add/remove/replace, background replacement, style transfer, and reference-guided edits.
121
-
122
- https://github.com/user-attachments/assets/bca232c9-75df-46f9-b366-14cfa2651994
123
-
124
- <table>
125
- <tr>
126
- <th>Source</th>
127
- <th>Prompt</th>
128
- <th>Edited</th>
129
- </tr>
130
- <tr>
131
- <td><a href="https://github.com/user-attachments/assets/dc7c3cf6-de0b-4b7b-9afe-d4e38c4ea6e1"><img src="assets/cases/case01_source.gif" width="220" alt="Case 01 source"></a></td>
132
- <td>Transform the people, hairstyles, and interior into a British castle aristocratic style.</td>
133
- <td><a href="https://github.com/user-attachments/assets/dbb9b6de-9d63-4879-8418-96610eac79b3"><img src="assets/cases/case01_edited.gif" width="220" alt="Case 01 edited"></a></td>
134
- </tr>
135
- <tr>
136
- <td><a href="https://github.com/user-attachments/assets/79792d23-7037-43c2-b185-dfd529aac3b7"><img src="assets/cases/case02_source.gif" width="220" alt="Case 02 source"></a></td>
137
- <td>Turn the video into a watercolor wash style.</td>
138
- <td><a href="https://github.com/user-attachments/assets/a20dea9d-715f-45b6-ae1d-b8c694983910"><img src="assets/cases/case02_edited.gif" width="220" alt="Case 02 edited"></a></td>
139
- </tr>
140
- <tr>
141
- <td><a href="https://github.com/user-attachments/assets/92c1723b-78a6-4b04-837d-21545aeff823"><img src="assets/cases/case03_source.gif" width="220" alt="Case 03 source"></a></td>
142
- <td>Make all dogs white, add colorful hats, and turn the sunglasses hot pink.</td>
143
- <td><a href="https://github.com/user-attachments/assets/8412d011-9b08-46c8-820e-ab59e97773d4"><img src="assets/cases/case03_edited.gif" width="220" alt="Case 03 edited"></a></td>
144
- </tr>
145
- <tr>
146
- <td><a href="https://github.com/user-attachments/assets/e9d70802-96e8-4aa4-a577-9e9cf0f8705c"><img src="assets/cases/case04_source.gif" width="220" alt="Case 04 source"></a></td>
147
- <td>Dress the girl in a brown down jacket and blue baseball cap.</td>
148
- <td><a href="https://github.com/user-attachments/assets/5ae898bd-ee26-4a63-9342-72430c28b82f"><img src="assets/cases/case04_edited.gif" width="220" alt="Case 04 edited"></a></td>
149
- </tr>
150
- <tr>
151
- <td><a href="https://github.com/user-attachments/assets/b7b5e199-080c-4344-924e-01951fd05912"><img src="assets/cases/case05_source.gif" width="220" alt="Case 05 source"></a></td>
152
- <td>Remove the two white cats in pink clothes on both sides.</td>
153
- <td><a href="https://github.com/user-attachments/assets/8e1874b8-755c-4bb0-914d-155110501076"><img src="assets/cases/case05_edited.gif" width="220" alt="Case 05 edited"></a></td>
154
- </tr>
155
- </table>
156
-
157
- **RV2V:** Put the coat/dress/shirt ... from Image 1 on the model in the video
158
-
159
- https://github.com/user-attachments/assets/e887d087-af71-4de1-b5d3-bbfbd32922d8
160
-
161
-
162
- ## 📦 Model Download
163
-
164
- Download the released JoyAI-Video-Edit weights from [Hugging Face](https://huggingface.co/jdopensource/JoyAI-Video-Edit), then place them under:
165
-
166
- ```text
167
- deploy/deps/checkpoints/JoyAI-Video-Edit/
168
- |-- dit/
169
- | `-- joyai_video_edit_dit_0811.pth
170
- `-- vae/
171
- |-- config.json
172
- `-- diffusion_pytorch_model.safetensors
173
- ```
174
 
175
- <a id="quick-start"></a>
176
 
177
- ## 🚀 Quick Start
 
 
 
178
 
179
- ### 1. Install
180
 
181
- ```bash
182
- conda create -n joyai-video-edit python=3.10 -y
183
- conda activate joyai-video-edit
184
- python -m pip install -r deploy/requirements.txt
185
- ```
186
 
187
- Then build the in-tree CUDA op library `deploy/joyomni_ops` (**required** — the DiT calls its fused kernels at runtime) and, per GPU, SageAttention / flash-attn-4: follow [`DEPLOYMENT.md` §2](DEPLOYMENT.md#2-prepare-the-environment).
 
 
 
 
 
188
 
189
- ### 2. Prepare Checkpoints
190
 
191
- Download the released weights from the Hugging Face link above. MiMo-VL is a required external dependency; the ONNX detectors are optional (missing files just disable the corresponding gates). See [`DEPLOYMENT.md`](DEPLOYMENT.md) for details.
192
 
193
- ### 3. Launch
 
 
 
 
 
 
 
194
 
195
  ```bash
196
- cd deploy
197
- bash run_server.sh
 
 
 
 
 
 
 
 
198
  ```
199
 
200
- Then open:
201
 
202
- ```text
203
- http://localhost:8080
 
204
  ```
205
 
206
- The server binds `0.0.0.0:8080` by default — for remote machines, just open the port (or use SSH port forwarding).
207
 
208
- ## 📚 Citation
209
 
210
- If JoyAI-Video-Edit is useful for your research or product prototype, please cite:
211
 
212
- ```bibtex
213
- @article{xiao2026joyai,
214
- title={JoyAI-Video-Edit: Real-Time Open-Ended Video Editing with Autoregressive Diffusion},
215
- author={Xiao, Yicheng and Dai, Wenxun and Qin, Xinran and Song, Lin and Zhang, Maoquan and Xu, Hang and Chen, Yukang and Li, Yitong and Zhang, Guohui and Zhang, Yuan and Zhang, Xuying and Zhang, Tommy and Yuan, Jianlong and Li, Peihao and Lu, Shuai and Fu, Siming and Zhao, Chuyang and Han, Xin and Huang, Jie and Li, Wenbo and Ma, Guoqing and Huang, Wei and Qi, Xiaojuan and Huang, Haoyang and Duan, Nan},
216
- journal={arXiv preprint arXiv:2608.03974},
217
- year={2026}
218
- }
219
- ```
220
 
221
- <a id="license"></a>
222
 
223
- ## ⚖️ License Agreement
224
 
225
- JoyAI-Video-Edit is licensed under Apache 2.0.
 
1
+ # Joy-face_change_optimized
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ [JoyAI-Video-Edit](https://github.com/jd-opensource/JoyAI-Video-Edit) 的优化分支(Apache-2.0)。
4
+ 目标:**降低部署门槛**——可移植算子、量化工具链、以及实测出来的精度/显存结论。
5
 
6
+ - GitHub: https://github.com/q760440238/Joy-face_change_optimized
7
+ - Hugging Face: https://huggingface.co/kylinfires/Joy-face_change_optimized
8
+ - 魔搭: https://www.modelscope.cn/models/kylinfires/Joy-face_change_optimized
9
 
10
+ ## 本分支做了什么
11
 
12
+ | 文件 | 作用 |
13
+ |---|---|
14
+ | `deploy/xvideo/models/dit/fused_ops_torch.py` | 用纯 PyTorch 复刻 `joyomni_ops` 的 CUDA kernel(LayerNorm+modulate、QK-norm+3D RoPE、RMSNorm) |
15
+ | `deploy/xvideo/models/dit/sgl_fused_ops.py` | `joyomni_ops` 不可用时自动回退到上面的实现(ROCm / CPU 也能跑) |
16
+ | `deploy/xvideo/models/dit/int4_linear.py` | int4(分组)与 int8(逐通道)的 weight-only Linear,含加载器 |
17
+ | `deploy/xvideo/models/models.py` | 新增 `JOYOMNI_DIT_SD_DIR`(bf16 分片)与 `JOYOMNI_DIT_INT4_DIR`(量化权重)两条加载路径 |
18
+ | `tools/quantization/` | RTN int4 (gs=64)、int8、attn-int8/MLP-int4 (gs=16) 三套量化脚本 |
19
+ | `tools/jve_client.py` | 无头 WebSocket 驱动(参考图 + 指令 + 帧序列),用于自动化验证 |
20
 
21
+ PyTorch 回退与 CUDA 版**逐张量验证一致**:99.997% 元素完全相同,最大偏差 1 个 bf16 ulp。
 
 
 
 
 
 
 
 
 
 
22
 
23
+ ## 量化实测结论(840×480,同权重同素材同 prompt)
24
 
25
+ | 精度 | 权重体积 | 与 bf16 的 PSNR | 参考人物相似度 |
26
  |---|---:|---:|---:|
27
+ | bf16(基线) | 31.8 GB | — | 0.314 |
28
+ | **int8(逐通道)** | 15.2 GiB | 21.8 dB | **0.359** ✅ |
29
+ | int4 (gs=64) | 8.1 GiB | 19.0 dB | 0.103 ❌ |
30
+ | attn int8 + MLP int4 (gs=16) | 11.4 GiB | 19.2 dB | 0.199 ⚠️ |
31
 
32
+ 流水线跨重启完全确定(同一份 int4 权重在两个新进程里跑出 **138 dB**,身份相似度 0.103 vs 0.103),所以上述差异是真实损失而非测量噪声。
 
33
 
34
+ **结论:int4 会摧毁"参考图换人"能力,int8 不会。** 身份信息完全走注意力通路——只把注意力压到 int4、MLP 全保 bf16,换人也会失效(0.027)。
 
 
35
 
36
+ ## 优化方向
37
 
38
+ ### 1. 剥离文本流权重(最大收益,进行中)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ 模型每层的参数构成:
41
 
42
+ | 分支 | 每 block | ×40 | 占比 |
43
+ |---|---:|---:|---:|
44
+ | 图像流 `img_attn + img_mlp` | 201 M | 8.05 B | 49.5% |
45
+ | **文本流 `txt_attn + txt_mlp`** | **201 M** | **8.05 B** | **49.5%** |
46
 
47
+ 文本 token 的 K/V 只依赖指令,**与画面无关**,一次会话内指令不变。因此可以:
48
 
49
+ 1. 会话开始时跑**一次**文本分支,逐层缓存 `txt_k`(qk-norm 之后)、`txt_v`
50
+ 2. 之后每个 chunk 传 `skip_text_stream=True`,attention 的 K/V = 当前图像 + 静态缓存(文本 + 参考图)
51
+ 3. 预填充完成后把 **8.05 B 文本流权重卸到 CPU 内存**
52
+
53
+ 代码基础已经具备:`dit.py` 的 block forward 本来就有 `skip_text_stream` 参数,`pipeline._prefill_static_reference_kv_cache()` 已经用同一套 KV 缓存机制给参考图做静态预填充。
54
 
55
+ | 组成 | 现状 | 剥离后 |
56
+ |---|---:|---:|
57
+ | 图像流权重 | 8.05 GB | 8.05 GB |
58
+ | 文本流权重 | 8.05 GB | **0**(常驻内存) |
59
+ | VAE + graph + KV | 7.7 GB | 7.7 GB |
60
+ | **合计** | **23.9 GB** | **~15.8 GB** |
61
 
62
+ 即 **16 GB 显卡可跑**,且用 int8(质量 0.359 优于 bf16 的 0.314),不靠 int4 硬压。额外收益:每 chunk 少算 40 次 `txt_mlp`,帧率预计 +30~40%。
63
 
64
+ > 状态:方案与代码路径已确认,实现待完成。验收标准:缓存版 vs 完整版 PSNR > 40 dB、身份相似度差 < 0.01。
65
 
66
+ ### 2. 其他方向
67
+
68
+ - **MLP 5-bit**:注意力 int8 + MLP 5-bit 约 13.3 GiB,误差预计 0.35%,相似度有望到 0.27–0.29
69
+ - **参考图 KV 复用**:同一张参考图跨会话复用,省一次 prefill
70
+ - **VAE 分时驻留**:encode/decode 之间释放对方,省约 0.7 GB
71
+ - **HEAD 输出量化**:`proj_out` 与 `img_in` 保持 bf16(已默认)
72
+
73
+ ## 快速开始
74
 
75
  ```bash
76
+ python -m pip install -r deploy/requirements.txt
77
+
78
+ # 三种权重加载方式(互不影响)
79
+ # 1) 原始 .pth(默认)
80
+ # 2) bf16 分片
81
+ export JOYOMNI_DIT_SD_DIR=/path/to/diffusers/transformer
82
+ # 3) 量化权重
83
+ export JOYOMNI_DIT_INT4_DIR=/path/to/int8_export
84
+
85
+ bash deploy/run_server.sh
86
  ```
87
 
88
+ 量化:
89
 
90
+ ```bash
91
+ python tools/quantization/quantize_int8.py # 15.2 GiB,质量可用
92
+ python tools/quantization/quantize_int4.py # 8.1 GiB,会摧毁换人能力
93
  ```
94
 
95
+ ---
96
 
97
+ ## English (concise)
98
 
99
+ Fork of [JoyAI-Video-Edit](https://github.com/jd-opensource/JoyAI-Video-Edit) (Apache-2.0) focused on deployability.
100
 
101
+ **Adds:** pure-PyTorch equivalents of the `joyomni_ops` CUDA kernels (bit-exact, max 1 bf16 ulp) with automatic fallback for ROCm/CPU; int4/int8 weight-only Linear plus state-dict loaders; three quantization recipes; a headless WebSocket client.
 
 
 
 
 
 
 
102
 
103
+ **Measured (840x480, identical weights/prompt/frames):** bf16 identity 0.314 → **int8 0.359** (15.2 GiB) → attn-int8+MLP-int4 0.199 (11.4 GiB) → int4 0.103 (8.1 GiB). The pipeline is deterministic across restarts (138 dB on identical int4 weights), so these are real. **int4 breaks reference-guided person swapping; int8 preserves it** — the identity signal lives entirely in the attention path.
104
 
105
+ **Optimization in progress — strip the text stream:** the txt branch (`txt_attn + txt_mlp`) is 8.05 B params, 49.5% of the model. Text K/V depends only on the prompt, so it can be prefilled once per session, cached as static KV, and the weights offloaded to host RAM. The block forward already accepts `skip_text_stream=True` and the pipeline already prefills static KV for the reference image. Expected: **23.9 GB → ~15.8 GB**, enabling 16 GB cards at int8 quality, plus 30-40% faster chunks.
106
 
107
+ See `NOTICE` for the list of modified files.