SpXMerlin1D commited on
Commit
b91eb08
·
verified ·
1 Parent(s): 06c3818

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +224 -1
README.md CHANGED
@@ -12,4 +12,227 @@ library_name: adapter
12
  pipeline_tag: text-to-video
13
  base_model:
14
  - MiniMaxAI/MiniMax-H3
15
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  pipeline_tag: text-to-video
13
  base_model:
14
  - MiniMaxAI/MiniMax-H3
15
+ ---
16
+
17
+ # CondBridge: Interface-Distilled Text Conditioning for MiniMax-H3
18
+
19
+ ## A DeepSeek-V4-Flash 0731 Assisted Project
20
+
21
+ **A 1.14B adapter that bridges a lightweight Qwen3.5-4B student to the
22
+ MiniMax-H3 33B text encoder's injection space.** It converts the student's
23
+ hidden states into the exact CLIP-injection representation the H3 DiT expects
24
+ (post-`condition_proj` + `token_refiner`), replacing the 33B teacher encoder
25
+ end-to-end.
26
+
27
+ ## Model Description
28
+
29
+ MiniMax-H3 video generation conditions the DiT on text embeddings produced by a
30
+ 33B text encoder (`condition_proj` + 2-layer `token_refiner`). Running it locally
31
+ is heavy. **CondBridge distills that interface** into a 1.14B adapter that
32
+ consumes:
33
+
34
+ | Input | Shape | Source |
35
+ |---|---|---|
36
+ | `h3_ids` | `[S_T]` | H3 tokenizer (vocab 151,643) |
37
+ | `student_hidden` | `[S_S, 2560]` | Qwen3.5-4B `hidden_states[-1]` (post-final-norm) |
38
+
39
+ and outputs the teacher-equivalent representation `[1, S_T, 5376]`. Because the
40
+ output lives in the same space as the teacher's post-refiner embeddings, the DiT
41
+ consumes it directly — **no changes to the DiT forward pass, no black frames.**
42
+
43
+ ## Architecture
44
+
45
+ `H3Adapter` — 1.144B params total:
46
+
47
+ | Module | Params | Role |
48
+ |---|---|---|
49
+ | `source_projection` | 13.8M | student 2560 → 5376 (KV) |
50
+ | `query_embedding` | 40.3M | H3 ids → 5376 query (embed 151,936×256 + proj) |
51
+ | `cross_attention` | 319M | 32-head resampler, QK-norm + tanh gate |
52
+ | `token_refiner` | 751M | 2 pre-norm blocks + final RMSNorm (mirrors teacher) |
53
+
54
+ Forward: `kv = source_proj(student)` → `x = cross_attn(query_embed(h3_ids), kv)`
55
+ → `token_refiner(x)`.
56
+
57
+ ## Training Data
58
+
59
+ - 10,032 prompts generated from a 9-skill element-pool Cartesian combos
60
+ (subjects/actions/scenes/camera/lighting/styles...), deduplicated to **10,027**
61
+ - Each prompt: H3 tokenizer ids + Qwen3.5-4B hidden states + teacher target
62
+ (`condition_proj` + `token_refiner` output of the official encoder)
63
+ - Feature-space dedup + length bucketing (short/medium/long)
64
+
65
+ ## Training Details
66
+
67
+ Two-stage fine-tuning (32GB GPU, bf16):
68
+
69
+ | Stage | Duration | Steps | Scope | Result |
70
+ |---|---|---|---|---|
71
+ | 1 | 4h | 18,874 | adapter body, refiner frozen (DiT init) | cos 0.8856 |
72
+ | 2 | 1.5h | 4,135 | all params, refiner lr×0.1 | **cos 0.9229** |
73
+
74
+ - Optimizer: Muon (2D weights) + AdamW8bit (1D), WSD schedule, wd 0.02
75
+ - Loss v3: `huber×1.0 + cos×0.8 + infonce×0.05 + sp×0.1 + mag×0.1 + stat×0.0002`
76
+ with a curriculum ramp on the contrastive terms
77
+ - Scale handled via RMS target-norm alignment (`pn = normalize(pred) × target_norm`)
78
+
79
+ ## Evaluation
80
+
81
+ Held-out 1,002 prompts (disjoint from train):
82
+
83
+ | Metric | Value |
84
+ |---|---|
85
+ | **cosine** (token-level) | **0.9229** |
86
+ | **MSE** | 0.8162 |
87
+ | **norm_ratio** (pred/target scale) | 1.013 |
88
+
89
+ Verified end-to-end: ComfyUI T2V generation with the adapter matches the prompt
90
+ content (no black frames, no semantic mismatch).
91
+
92
+ ## Usage
93
+
94
+ ```python
95
+ import torch
96
+ from transformers import AutoTokenizer
97
+ from adapter.model import H3Adapter # repo code
98
+ from safetensors.torch import load_file
99
+
100
+ adapter = H3Adapter().to(torch.bfloat16)
101
+ adapter.load_state_dict(load_file("condbridge.safetensors"))
102
+ adapter.eval()
103
+
104
+ h3_tok = AutoTokenizer.from_pretrained("<h3 tokenizer>")
105
+ # student_hidden: Qwen3.5-4B hidden_states[-1] [S_S, 2560]
106
+ h3_ids = h3_tok(prompt, add_special_tokens=False)["input_ids"]
107
+ embeds = adapter(torch.tensor([h3_ids]), student_hidden.unsqueeze(0)) # [1, S_T, 5376]
108
+ ```
109
+
110
+ Requires: `Qwen3.5-4B` (student), MiniMax-H3 tokenizer, the H3 DiT.
111
+
112
+ ## ComfyUI Integration
113
+
114
+ Use with the [ComfyUI-MiniMaxH3-Adapter] node: `MiniMaxH3AdapterLoader`
115
+ (student dir + adapter .safetensors) → plug into official
116
+ `MiniMaxH3ImageToVideo`. The node exposes the adapter as a duck-typed CLIP.
117
+
118
+ ## Limitations
119
+
120
+ - Distilled fidelity is bounded by the student (Qwen3.5-4B): complex multi-shot
121
+ or long cinematic prompts may drift from the 33B teacher.
122
+ - Trained on generated prompt combinations (9-skill template), not in-the-wild
123
+ caption distributions.
124
+ - Unconditional/vision-input (image-to-video) conditioning is out of scope.
125
+ - Intended for research / local use; check MiniMax-H3 terms of service.
126
+
127
+ ## Training your own CondBridge
128
+
129
+ - Training Code to be released soon
130
+
131
+ # CondBridge:面向 MiniMax-H3 的接口蒸馏文本条件适配器
132
+
133
+ ## 本项目在DeepSeek-V4-Flash 0731帮助下完成
134
+
135
+ **一个 1.14B 参数的适配器,为轻量级 Qwen3.5-4B 学生模型搭建通往 MiniMax-H3
136
+ 33B 文本编码器注入空间的"桥"。** 它将学生模型的隐藏状态转换为 H3 DiT 期望的
137
+ CLIP 注入表示(`condition_proj` + `token_refiner` 之后的结果),端到端替代
138
+ 33B 教师编码器。
139
+
140
+ ## 模型描述
141
+
142
+ MiniMax-H3 视频生成用 33B 文本编码器(`condition_proj` + 2 层 `token_refiner`)
143
+ 产生文本嵌入来条件化 DiT。本地��行它很重。**CondBridge 蒸馏了这套接口**,用
144
+ 一个 1.14B 适配器消费:
145
+
146
+ | 输入 | 形状 | 来源 |
147
+ |---|---|---|
148
+ | `h3_ids` | `[S_T]` | H3 tokenizer(词表 151,643) |
149
+ | `student_hidden` | `[S_S, 2560]` | Qwen3.5-4B `hidden_states[-1]`(final-norm 后) |
150
+
151
+ 并输出与教师等价的表示 `[1, S_T, 5376]`。由于输出与教师的 post-refiner 嵌入
152
+ 处于同一空间,DiT 可直接消费——**无需改动 DiT 前向,无黑屏。**
153
+
154
+ ## 模型架构
155
+
156
+ `H3Adapter` — 共 1.144B 参数:
157
+
158
+ | 模块 | 参数量 | 作用 |
159
+ |---|---|---|
160
+ | `source_projection` | 13.8M | 学生 2560 → 5376(作为 KV) |
161
+ | `query_embedding` | 40.3M | H3 ids → 5376 查询(embed 151,936×256 + proj) |
162
+ | `cross_attention` | 319M | 32 头重采样器,QK-norm + tanh 门控 |
163
+ | `token_refiner` | 751M | 2 个 pre-norm block + final RMSNorm(镜像教师) |
164
+
165
+ 前向:`kv = source_proj(student)` → `x = cross_attn(query_embed(h3_ids), kv)`
166
+ → `token_refiner(x)`。
167
+
168
+ ## 训练数据
169
+
170
+ - 从 9 类技能元素池笛卡尔组合生成 10,032 条 prompt
171
+ (主体/动作/场景/镜头/灯光/风格...),去重后 **10,027** 条
172
+ - 每条 prompt 含:H3 tokenizer ids + Qwen3.5-4B 隐藏状态 + 教师目标
173
+ (官方编码器的 `condition_proj` + `token_refiner` 输出)
174
+ - 特征空间去重 + 长度分桶(短/中/长)
175
+
176
+ ## 训练细节
177
+
178
+ 两阶段微调(32GB 显卡,bf16):
179
+
180
+ | 阶段 | 时长 | 步数 | 范围 | 结果 |
181
+ |---|---|---|---|---|
182
+ | 1 | 4h | 18,874 | 适配器主体,refiner 冻结(DiT 初始化) | cos 0.8856 |
183
+ | 2 | 1.5h | 4,135 | 全参数,refiner lr×0.1 | **cos 0.9229** |
184
+
185
+ - 优化器:Muon(2D 权重)+ AdamW8bit(1D 权重),WSD 调度,wd 0.02
186
+ - Loss v3:`huber×1.0 + cos×0.8 + infonce×0.05 + sp×0.1 + mag×0.1 + stat×0.0002`,
187
+ 对比项带课程 ramp
188
+ - 尺度处理:RMS 目标范数对齐(`pn = normalize(pred) × target_norm`)
189
+
190
+ ## 评测结果
191
+
192
+ Held-out 1,002 条 prompt(与训练集不重叠):
193
+
194
+ | 指标 | 数值 |
195
+ |---|---|
196
+ | **cosine**(逐 token) | **0.9229** |
197
+ | **MSE** | 0.8162 |
198
+ | **norm_ratio**(预测/目标尺度) | 1.013 |
199
+
200
+ 端到端验证:ComfyUI T2V 生成内容与 prompt 对齐(无黑屏、无语义错位)。
201
+
202
+ ## 使用方法
203
+
204
+ ```python
205
+ import torch
206
+ from transformers import AutoTokenizer
207
+ from adapter.model import H3Adapter # 仓库代码
208
+ from safetensors.torch import load_file
209
+
210
+ adapter = H3Adapter().to(torch.bfloat16)
211
+ adapter.load_state_dict(load_file("condbridge.safetensors"))
212
+ adapter.eval()
213
+
214
+ h3_tok = AutoTokenizer.from_pretrained("<h3 tokenizer>")
215
+ # student_hidden: Qwen3.5-4B hidden_states[-1] [S_S, 2560]
216
+ h3_ids = h3_tok(prompt, add_special_tokens=False)["input_ids"]
217
+ embeds = adapter(torch.tensor([h3_ids]), student_hidden.unsqueeze(0)) # [1, S_T, 5376]
218
+ ```
219
+
220
+ 依赖:`Qwen3.5-4B`(学生)、MiniMax-H3 tokenizer、H3 DiT。
221
+
222
+ ## ComfyUI 集成
223
+
224
+ 配合 [ComfyUI-MiniMaxH3-Adapter] 节点使用:`MiniMaxH3AdapterLoader`
225
+ (学生目录 + 适配器 .safetensors)→ 接入官方 `MiniMaxH3ImageToVideo` 节点。
226
+ 节点把适配器封装成鸭子类型 CLIP。
227
+
228
+ ## 局限性
229
+
230
+ - 蒸馏保真度受限于学生(Qwen3.5-4B):复杂多镜头或长电影级 prompt 可能
231
+ 偏离 33B 教师
232
+ - 训练数据是生成的 prompt 组合(9 类技能模板),非真实世界字幕分布
233
+ - 不支持无条件 / 图像输入(图生视频)条件化
234
+ - 面向研究 / 本地使用;请遵守 MiniMax-H3 服务条款
235
+
236
+ # 我自己想训练一个CondBridge
237
+
238
+ - 训练代码整理后发布