主报告
Read-only attention observability · 2026-07-31T17:19:21Z

KV Cache 里的异常值,究竟聚集在哪里?

CatNIP / CatPolaris 原生 22B BF16 流式推理:三个差异显著的 10 秒 prompt,逐 chunk 观察 48 层四类 cache attention,并对代表层还原 Q、K 与 S=QKᵀ/√d。

3controlled prompts
16chunks / video
48transformer layers
4-NFEtorch.bfloat16
9.96s249 frames @ 25.0 fps
Executive readout

先看结论

outlier 定义为偏离中位数超过 6 × 1.4826 × MAD;极值位置使用完整张量,比例与分位数使用确定性等距样本。

  1. 按 6×MAD robust outlier 比例汇总,Q/K 最集中的 prompt 是“人物近景与连续语音”(Q=1.917%,K=2.168%),峰值出现在 chunk 15。
  2. 代表层所选极值 head 的 S robust 峰值平均最强的是“高速高纹理运动”(平均 max robust-z=4.9)。
  3. 历史存在时,代表层/极值 head 的 softmax 概率质量平均为 sink 24.4% / recent 32.3% / current 43.3%;最高区域是 current。
  4. 全局最极端记录位于 fast_motion · Q · video_self · layer 0 · chunk 11,robust-z=1444.2;位置为 video query token 357 (local latent frame 0, y=23, x=12), channel 1021。
PromptQ outlierK outlierS outlierPeak chunksink / recent / current
静态低熵场景1.918%2.096%0.922%1526.4% / 33.0% / 40.6%
高速高纹理运动1.902%2.124%0.127%1522.2% / 31.0% / 46.7%
人物近景与连续语音1.917%2.168%0.063%1524.6% / 32.7% / 42.7%
Generated evidence

同 seed 的三段视频

请求 10.00 秒;因 LTX causal latent grid 对齐,实际每段 249 帧 / 9.96 秒。视频均由本次被观测的同一推理过程产出。

calm_static

静态低熵场景

锁定镜头、单主体、低纹理、无语言,用作低运动/低语义切换基线。

完整 prompt
[VISUAL]: A locked-off wide shot of a single pale ceramic vase on a matte gray table in a quiet fog-filled studio. Soft diffuse morning light, nearly monochrome palette, empty background, no people, no cuts, photorealistic.
[SPEECH]: None
[SOUNDS]: Faint steady room tone only.
[TEXT]: None
ffprobe: {"programs": [], "streams": [{"width": 480, "height": 832, "avg_frame_rate": "25/1", "nb_frames": "249"}], "format": {"duration": "9.960000", "size": "491120"}}
fast_motion

高速高纹理运动

高速主体、复杂粒子、强烈颜色和追逐镜头,最大化时空变化。

完整 prompt
[VISUAL]: An aggressive low-angle tracking shot races beside a scarlet motocross rider blasting through a neon night market in heavy rain. Water sprays across the lens, banners whip, sparks scatter, crowds dodge, cyan and magenta reflections streak over wet pavement, rapid continuous motion, photorealistic, no cuts.
[SPEECH]: None
[SOUNDS]: Roaring motorcycle engine, splashing water, rattling stalls, distant crowd.
[TEXT]: None
ffprobe: {"programs": [], "streams": [{"width": 480, "height": 832, "avg_frame_rate": "25/1", "nb_frames": "249"}], "format": {"duration": "9.960000", "size": "10000282"}}
talking_closeup

人物近景与连续语音

人脸、口型、精细局部运动和连续语音,使视频/音频及跨模态 cache 同时承压。

完整 prompt
[VISUAL]: A tight cinematic close-up of an elderly East Asian woman scientist facing the camera inside a bright orbital greenhouse. Her eyes, lips, and hands move naturally as she speaks; translucent leaves drift behind her; stable slow push-in, crisp skin detail, photorealistic, no cuts.
[SPEECH]: 'Every small discovery changes how we understand our home among the stars.'
[SOUNDS]: Clear warm female voice, gentle ventilation hum, occasional leaf rustle.
[TEXT]: None
ffprobe: {"programs": [], "streams": [{"width": 480, "height": 832, "avg_frame_rate": "25/1", "nb_frames": "249"}], "format": {"duration": "9.960000", "size": "2259677"}}
All-layer map

48 层 × 16 chunks 的 outlier 分布

每个像素是 commit pass 的 6×MAD outlier 比例。纵轴 layer 0→47,横轴 chunk 0→末尾;覆盖全部层,不只代表层。

low ← outlier fraction → high · hover for exact layer/chunk

把鼠标移到图上查看数值。

每个 chunk 约 0.64 秒;chunk 0 是无历史 KV 的基线。后续 K 分为 sink / recent history / current。

Concrete head drill-down

一个 prompt / chunk / layer / head,到底看到了什么?

这里不再展平所有 head:Q、K、S 和真实 Attention 都来自同一个明确 head。K 的 sink、recent history、current chunk 边界会直接画在图上;同一 layer + attention + tensor 全局共用色标。

L0 · 输入/早期L12 · 早中期L24 · 中层L36 · 晚中期L47 · 输出/末层
代表层具体 headQ outlier / zK outlier / zS outlier / zAttention mass: sink / recent / currentEntropy / top P
Q · 当前 query token × head channel

只含本 chunk 的 query;蓝色为负、米白为零、红色为正。

K · [sink | recent history | current] key × channel

横线是精确 cache 边界:上方历史,下方当前 chunk。

S = QKᵀ/√d · query × all keys

未归一化 logits;竖线按 key 轴分隔 sink / recent / current。

Attention = softmax(S + mask) · query × all keys

真实 mask 后概率,深色→高概率;池化格保留块内最大概率。

把鼠标移到任一图上,可查看该格对应的原始 token/channel 范围、近似数值和 cache 区域。
Noise-step check

NFE 与 commit 的 outlier 比例

代表层的四个 noisy forward 也被统计;commit 是 sigma=0 clean warm pass,写入下一 chunk 真正读取的 cache。

PhaseQ outlierK outlier
nfe_02.661%2.819%
nfe_12.933%2.850%
nfe_23.074%2.890%
nfe_33.303%2.974%
commit3.347%3.025%
Exact extrema

全局 Top-24 robust 极值

Q/K 极值来自完整张量;S 极值来自代表层中 Q/K 联合绝对值最大的 head。

PromptKindAttentionLayerChunkRobust-zOutlier fracLocation
fast_motionQvideo_self0111444.223.682%video query token 357 (local latent frame 0, y=23, x=12), channel 1021
fast_motionQvideo_self091427.323.567%video query token 628 (local latent frame 1, y=15, x=13), channel 957
fast_motionQvideo_self011416.223.472%video query token 719 (local latent frame 1, y=21, x=14), channel 1021
fast_motionQvideo_self031365.723.794%video query token 326 (local latent frame 0, y=21, x=11), channel 957
fast_motionQvideo_self061363.123.673%video query token 765 (local latent frame 1, y=25, x=0), channel 957
fast_motionQvideo_self041346.423.786%video query token 733 (local latent frame 1, y=22, x=13), channel 1021
fast_motionQvideo_self0141340.823.605%video query token 375 (local latent frame 0, y=25, x=0), channel 1021
fast_motionQvideo_self0121329.123.568%video query token 765 (local latent frame 1, y=25, x=0), channel 957
calm_staticKvideo_self03351.720.399%video key token 618 (sink), channel 968
calm_staticKvideo_self08351.320.388%video key token 618 (sink), channel 968
calm_staticKvideo_self05349.120.335%video key token 618 (sink), channel 968
calm_staticKvideo_self09347.720.286%video key token 618 (sink), channel 968
calm_staticKvideo_self011346.920.336%video key token 618 (sink), channel 968
calm_staticKvideo_self010346.820.335%video key token 618 (sink), channel 968
calm_staticKvideo_self02346.820.200%video key token 618 (sink), channel 968
calm_staticKvideo_self015346.120.347%video key token 618 (sink), channel 968
calm_staticSv2a241521.50.379%query token 14 → key 1559 (sink)
calm_staticSv2a24720.60.470%query token 12 → key 2744 (recent history)
calm_staticSv2a241020.30.368%query token 12 → key 1559 (sink)
calm_staticSv2a24919.50.377%query token 0 → key 1559 (sink)
calm_staticSv2a24819.20.393%query token 15 → key 1559 (sink)
calm_staticSv2a24619.00.438%query token 3 → key 1559 (sink)
calm_staticSv2a24319.00.404%query token 6 → key 1559 (sink)
calm_staticSv2a24518.70.467%query token 14 → key 4304 (current chunk)
Method & boundaries

如何读这些图

Q/K 口径
SDPA 边界:linear projection、RMSNorm、RoPE 之后;K 已按真实顺序拼成 [sink | recent history | current]。观察器随后原样调用 attention。
两种具体 head
“极值 head”按该次调用中 Q/K 联合绝对最大值选择;“中位参考 head”按同一指标排序取中位数,用来判断现象是否只由异常 head 驱动。
S 与 Attention
S=QKᵀ/√d 以 float32 计算;Attention=softmax(S+mask)。Q/K/S 使用保留符号的块内绝对极值池化,Attention 使用块内最大值池化。
为何看 commit
每 chunk 有 4 次 noisy NFE 和一次 sigma=0 warm pass。只有 warm pass commit 后成为下一 chunk 读取的历史 KV。
色标与量化
同一 layer、attention 类型、tensor 在全部 prompt/chunk/head 间共用 99.5% 色标。报告内嵌图采用 8-bit 量化;trace 中保留 float16 池化值。
唯一执行差异
关闭 per-block torch.compile 以做 Python 边界观测;checkpoint、BF16、4-NFE、CLF=2、cache eviction、ctx renorm、分辨率和 seed 保持一致。
完整运行 manifest
{
  "schema_version": 2,
  "created_utc": "2026-07-31T17:19:21Z",
  "experiment": "CatPolaris/CatNIP native BF16 fine-grained per-head KV-cache Q/K/S/Attention analysis",
  "runs": [
    {
      "id": "calm_static",
      "title": "静态低熵场景",
      "rationale": "锁定镜头、单主体、低纹理、无语言,用作低运动/低语义切换基线。",
      "text": "[VISUAL]: A locked-off wide shot of a single pale ceramic vase on a matte gray table in a quiet fog-filled studio. Soft diffuse morning light, nearly monochrome palette, empty background, no people, no cuts, photorealistic.\n[SPEECH]: None\n[SOUNDS]: Faint steady room tone only.\n[TEXT]: None",
      "video": "videos/calm_static.mp4",
      "trace": "traces/calm_static.pt",
      "wall_time_s": 37.2357292175293,
      "prompt_id": "calm_static",
      "stat_records": 9024,
      "heatmap_records": 320,
      "trace_path": "/workspace/kv_cache_analysis/results/20260731_bf16_kv_cache_fine/traces/calm_static.pt",
      "expected_top_level_forwards": 80,
      "actual_top_level_forwards": 80
    },
    {
      "id": "fast_motion",
      "title": "高速高纹理运动",
      "rationale": "高速主体、复杂粒子、强烈颜色和追逐镜头,最大化时空变化。",
      "text": "[VISUAL]: An aggressive low-angle tracking shot races beside a scarlet motocross rider blasting through a neon night market in heavy rain. Water sprays across the lens, banners whip, sparks scatter, crowds dodge, cyan and magenta reflections streak over wet pavement, rapid continuous motion, photorealistic, no cuts.\n[SPEECH]: None\n[SOUNDS]: Roaring motorcycle engine, splashing water, rattling stalls, distant crowd.\n[TEXT]: None",
      "video": "videos/fast_motion.mp4",
      "trace": "traces/fast_motion.pt",
      "wall_time_s": 23.94784116744995,
      "prompt_id": "fast_motion",
      "stat_records": 9024,
      "heatmap_records": 320,
      "trace_path": "/workspace/kv_cache_analysis/results/20260731_bf16_kv_cache_fine/traces/fast_motion.pt",
      "expected_top_level_forwards": 80,
      "actual_top_level_forwards": 80
    },
    {
      "id": "talking_closeup",
      "title": "人物近景与连续语音",
      "rationale": "人脸、口型、精细局部运动和连续语音,使视频/音频及跨模态 cache 同时承压。",
      "text": "[VISUAL]: A tight cinematic close-up of an elderly East Asian woman scientist facing the camera inside a bright orbital greenhouse. Her eyes, lips, and hands move naturally as she speaks; translucent leaves drift behind her; stable slow push-in, crisp skin detail, photorealistic, no cuts.\n[SPEECH]: 'Every small discovery changes how we understand our home among the stars.'\n[SOUNDS]: Clear warm female voice, gentle ventilation hum, occasional leaf rustle.\n[TEXT]: None",
      "video": "videos/talking_closeup.mp4",
      "trace": "traces/talking_closeup.pt",
      "wall_time_s": 23.370716333389282,
      "prompt_id": "talking_closeup",
      "stat_records": 9024,
      "heatmap_records": 320,
      "trace_path": "/workspace/kv_cache_analysis/results/20260731_bf16_kv_cache_fine/traces/talking_closeup.pt",
      "expected_top_level_forwards": 80,
      "actual_top_level_forwards": 80
    }
  ],
  "config": {
    "checkpoint": "/workspace/wuhan_inference/models/rl16/merged_sst1500_rl16.safetensors",
    "base_checkpoint": "/workspace/wuhan_inference/models/ltx-2.3-22b-dev.safetensors",
    "dtype": "torch.bfloat16",
    "compile_blocks": false,
    "compile_difference_reason": "Python-side read-only Q/K/S observation at the SDPA boundary",
    "steps": 4,
    "sigmas": [
      1.0,
      0.909375011920929,
      0.7250000238418579,
      0.421875,
      0.0
    ],
    "chunk_latent_frames": 2,
    "chunk_schedule": [
      2
    ],
    "max_cache_frames": 10,
    "sink_frames": 4,
    "fps": 25.0,
    "height": 832,
    "width": 480,
    "seed": 20260731,
    "requested_duration_s": 10.0,
    "realized_duration_s": 9.96,
    "latent_frames": 32,
    "pixel_frames": 249,
    "num_chunks": 16,
    "prod_renorm": "1",
    "prod_renorm_mode": "ctx",
    "prod_renorm_skip": "2",
    "text_encoder_dtype_mode": "bf16",
    "text_encoder_device": "cuda:1",
    "decode_device": "cuda:1",
    "selected_heatmap_layers": [
      0,
      12,
      24,
      36,
      47
    ],
    "detailed_head_roles": [
      "extreme",
      "reference"
    ],
    "detailed_tensor_kinds": [
      "Q",
      "K",
      "S",
      "A"
    ],
    "key_region_order": [
      "sink",
      "recent_history",
      "current_chunk"
    ],
    "quantile_stat_sample_cap": 65536,
    "heatmap_pool_shape": [
      64,
      96
    ],
    "transformer_layers": 48,
    "transformer_parameter_count": 18988838144,
    "transformer_dtypes": [
      "torch.bfloat16"
    ],
    "transformer_devices": [
      "cuda:0"
    ]
  },
  "software": {
    "python": "3.12.13",
    "torch": "2.12.0+cu130",
    "cuda_runtime": "13.0"
  },
  "hardware": [
    {
      "index": 0,
      "name": "NVIDIA H100 80GB HBM3",
      "total_memory_bytes": 85017493504,
      "capability": [
        9,
        0
      ]
    },
    {
      "index": 1,
      "name": "NVIDIA H100 80GB HBM3",
      "total_memory_bytes": 85017493504,
      "capability": [
        9,
        0
      ]
    }
  ],
  "total_wall_time_s": 475.6668462753296
}