Files
myWiki/concepts/block-causal-attention.md

50 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Block-Causal Attention"
created: 2026-06-25
updated: 2026-06-25
type: concept
tags: [attention, streaming, transformer, causal, multimodal]
sources:
- "[[wan-streamer]]"
---
# Block-Causal Attention
**Block-Causal Attention** 是一种介于标准因果注意力causal attention和双向注意力bidirectional attention之间的注意力模式专为流式多模态生成设计。它在 Wan-Streamer 中作为协调交错的视觉、音频和文本 token 流式生成的核心机制。
## 核心机制
在标准因果注意力中,每个 token 只能关注其之前的 token。在双向注意力中每个 token 可以关注所有 token。**Block-causal attention** 将序列划分为块blocks在每个块内允许双向注意力但跨块之间保持因果约束
- **块内intra-block**token 可以关注同块内的所有 token双向
- **块间inter-block**token 只能关注之前块的 token因果
这种设计在流式生成中取得了关键权衡:块内双向注意力保证了同帧内多模态 token如音频+视频+文本)的充分交互和同步,而块间因果约束保证了流式推理的可行性(不需要等待未来帧)。
## 在 Wan-Streamer 中的应用
在 Wan-Streamer 的全双工流式交互中,每个 160ms 的流式单元形成一个块。块内包含该时刻的用户输入 token 和 Agent 响应 token视觉、音频、文本块内双向注意力确保
- 语音和视频潜变量的耦合生成
- 嘴唇运动与语音的天然同步
- 跨模态语义对齐
跨块因果约束确保:
- 增量流式推理(不需要等待整个对话完成)
- KV-cache 的可复用性
- 全历史上下文的线性的计算复杂度
## 与其他注意力模式对比
| 模式 | 块内 | 块间 | 适用场景 |
|------|------|------|----------|
| Causal | 因果 | 因果 | 标准自回归语言模型 |
| Bidirectional | 双向 | 双向 | BERT 类理解任务 |
| **Block-Causal** | **双向** | **因果** | **流式多模态生成** |
## 参考
- [[wan-streamer]] — 首次在端到端流式交互基础模型中应用
- [[native-streaming-ar-training]]
- [[kv-cache]]