File size: 2,338 Bytes
153dd42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# MotionDetailCache on MAGI-1 (dev4-detail)

基于 [FlowCache4MAGI-1-dev3-motion](../FlowCache4MAGI-1-dev3-motion) 的扩展分支,在 MotionCache 的 **motion 度量** 之外,增加 **spatial detail 度量**,Phase 2 active token 由两者共同决定。

## 与 dev3 (MotionCache) 的差异

| 维度 | dev3 MotionCache | dev4 MotionDetailCache |
|------|------------------|------------------------|
| Phase 2 权重 | 仅 motion 权重 W_m | motion W_m + detail W_d 融合 |
| Detail proxy | — | latent 局部 k×k 空间方差 |
| 适用场景 | 运动区域优先计算 | 静止纹理/边缘/语义细节也优先保留 |

## Detail 度量

对每个 latent 像素 `(t, h, w)`:

1. 通道聚合幅度:`mag = mean(|x|, dim=C)` → `[N, T, H, W]`
2. 局部空间方差:在 `detail_window_size×detail_window_size` 窗口内计算 `Var(mag)`
3. Soft-mapping:帧内 min-max 归一化 → `W_d ∈ [detail_alpha, 1]`

高方差区域对应边缘、纹理、物体边界等 heterogeneous 邻域。

## Motion + Detail 融合

```
W_combined = combine(W_motion, W_detail)
A[p] += W_combined[p] · Δ_chunk
active[p] = A[p] > τ
```

`weight_combine_mode`(默认 `max`):

| 模式 | 公式 | 特点 |
|------|------|------|
| `max` | max(W_m, W_d) | 运动或细节任一显著即可加速累积(推荐) |
| `product` | W_m × W_d | 两者同时高才快速激活,更激进 reuse |
| `blend` | (1-λ)W_m + λW_d | 线性权衡,λ=`detail_lambda` |

## 默认超参

继承 dev3 的 motion 参数,并新增:

| 参数 | 默认值 | 说明 |
|------|--------|------|
| `detail_alpha` | 0.5 | detail 权重下限 |
| `detail_window_size` | 3 | 局部方差窗口(奇数) |
| `detail_lambda` | 0.5 | blend 模式下的 detail 权重 |
| `weight_combine_mode` | max | 融合方式 |

## 快速运行

```bash
cd FlowCache4MAGI-1-dev4-detail
conda activate magi
export CUDA_VISIBLE_DEVICES=0
export MASTER_ADDR=localhost
bash scripts/single_run/motiondetail_t2v.sh
```

## 代码结构

```
inference/pipeline/cache/
├── motioncache.py          # dev3 基类 MotionWiseCache
└── motiondetailcache.py    # dev4 MotionDetailCache

yaml_config/single_run/motiondetail_config.yaml
scripts/single_run/motiondetail_t2v.sh
```

其余 sparse forward、KV cache、integrate 逻辑与 dev3 完全一致。