混合动机、Nemotron-3、Granite 4.0、Kimi Linear、Jamba、配置与性能对比
Transformer的自注意力机制虽然强大,但其O(L²)的计算和显存复杂度在长序列场景下成为严重瓶颈。对于128K上下文窗口,仅KV缓存就需要数十GB显存,推理延迟也随序列长度线性增长。
| 序列长度 | Attention FLOPs | KV Cache (d=4096, fp16) | 推理延迟 |
|---|---|---|---|
| 4K | 67B | 64MB | ~10ms |
| 32K | 4.3T | 512MB | ~80ms |
| 128K | 68.7T | 2GB | ~320ms |
| 1M | 4.2P | 16GB | ~2.5s |
Mamba虽然解决了长序列问题,但在某些任务上存在固有局限:
混合架构的核心思想是取长补短:用Mamba层处理长序列中的大部分计算(利用其线性复杂度和固定推理状态),用少量Attention层提供精确召回和全局推理能力。这种设计在保持长序列优势的同时,弥补了纯SSM的不足。
Nemotron-3是NVIDIA推出的混合架构模型,结合了Mamba-2 SSM层、MoE条件计算和GQA分组查询注意力。其设计目标是同时实现长序列处理、大模型容量和高效推理。
| 组件 | Nemotron-3配置 | 作用 |
|---|---|---|
| 序列建模 | Mamba-2 (主要) + GQA (少量) | 长序列+精确召回 |
| 条件计算 | MoE (细粒度专家) | 大参数容量 |
| 注意力 | GQA (分组查询) | 推理KV压缩 |
| 层间比例 | ~9:1 (Mamba:Attention) | 效率优先 |
Nemotron-3的每个Block可能包含以下组件的组合:
class NemotronBlock(nn.Module):
"""Nemotron-3风格的混合块"""
def __init__(self, d_model=4096, d_state=64,
n_heads=32, n_kv_heads=8,
n_experts=32, top_k=4,
use_attention=False):
super().__init__()
self.norm1 = nn.RMSNorm(d_model)
# 序列建模: Mamba-2或GQA
if use_attention:
self.seq_model = GQA(d_model, n_heads, n_kv_heads)
else:
self.seq_model = Mamba2SSD(d_model, d_state)
self.norm2 = nn.RMSNorm(d_model)
# FFN: MoE或Dense
self.ffn = MoEFFN(d_model, n_experts, top_k)
def forward(self, x):
x = x + self.seq_model(self.norm1(x))
x = x + self.ffn(self.norm2(x))
return x
class NemotronModel(nn.Module):
"""Nemotron-3完整模型"""
def __init__(self, vocab_size=128000, d_model=4096,
n_layers=48, attn_interval=8):
super().__init__()
self.embedding = nn.Embedding(vocab_size, d_model)
self.layers = nn.ModuleList([
NemotronBlock(d_model, use_attention=(i+1)%attn_interval==0)
for i in range(n_layers)
])
self.norm_f = nn.RMSNorm(d_model)
self.lm_head = nn.Linear(d_model, vocab_size, bias=False)
def forward(self, input_ids):
x = self.embedding(input_ids)
for layer in self.layers:
x = layer(x)
return self.lm_head(self.norm_f(x))
IBM Granite 4.0采用了9:1的Mamba:Attention层比例。每10层中9层是Mamba层,1层是Attention层。这种设计使得大部分计算由高效的Mamba层承担,同时保留足够的Attention层用于精确召回。
| 配置 | Granite 4.0 Small | Granite 4.0 Medium | Granite 4.0 Large |
|---|---|---|---|
| 总层数 | 32 | 48 | 64 |
| Mamba层数 | 29 | 43 | 58 |
| Attention层数 | 3 | 5 | 6 |
| 比例 | ~9:1 | ~9:1 | ~9:1 |
| d_model | 2048 | 4096 | 8192 |
| 上下文长度 | 128K | 128K | 128K |
Attention层的放置位置对性能有显著影响。常见策略包括:
def build_granite_layers(n_layers=48, attn_ratio=0.1,
placement="uniform"):
"""构建Granite 4.0风格的混合层配置"""
n_attn = max(1, int(n_layers * attn_ratio))
n_mamba = n_layers - n_attn
if placement == "uniform":
interval = n_layers // n_attn
layer_types = ["attn" if (i+1) % interval == 0 else "mamba"
for i in range(n_layers)]
elif placement == "back_heavy":
layer_types = ["mamba"] * n_mamba + ["attn"] * n_attn
elif placement == "front_heavy":
layer_types = ["attn"] * n_attn + ["mamba"] * n_mamba
elif placement == "mixed":
interval = (n_layers - 2) // (n_attn - 2)
layer_types = ["attn"]
for i in range(1, n_layers - 1):
layer_types.append("attn" if i % interval == 0 else "mamba")
layer_types.append("attn")
return layer_types
for strategy in ["uniform", "back_heavy", "front_heavy", "mixed"]:
layers = build_granite_layers(20, 0.1, strategy)
print(f"{strategy:15s}: {layers}")
Kimi Linear是Moonshot AI推出的线性注意力架构,通过将标准Attention的softmax替换为线性核函数,实现O(L)的训练和推理复杂度。其核心思想是:
其中φ是非线性特征映射。通过维护φ(K)T·V的递推状态,实现线性时间的推理。
Jamba是AI21 Labs的混合架构,结合了Mamba、Attention和MoE三种技术:
| 配置项 | Jamba值 | 说明 |
|---|---|---|
| 总层数 | 48 | 混合层 |
| Attention层数 | 6 (每8层1个) | 1:7比例 |
| Mamba层数 | 42 | 主要计算 |
| MoE使用 | 部分层 | 条件计算 |
| 总参数 | 12B | 含所有专家 |
| 激活参数 | 1.5B | 每token实际计算 |
| 上下文长度 | 256K | 超长上下文 |
class JambaBlock(nn.Module):
"""Jamba混合块: Mamba + Attention + MoE"""
def __init__(self, d_model=4096, d_state=16,
n_heads=32, n_experts=16, top_k=4,
layer_type="mamba"):
super().__init__()
self.layer_type = layer_type
self.norm1 = nn.RMSNorm(d_model)
if layer_type == "attention":
self.seq = MultiHeadAttention(d_model, n_heads)
else:
self.seq = MambaBlock(d_model, d_state)
self.norm2 = nn.RMSNorm(d_model)
self.use_moe = (layer_type == "mamba")
if self.use_moe:
self.ffn = MoEFFN(d_model, n_experts, top_k)
else:
self.ffn = DenseFFN(d_model)
def forward(self, x):
x = x + self.seq(self.norm1(x))
if self.use_moe:
out, aux = self.ffn(self.norm2(x))
x = x + out
else:
x = x + self.ffn(self.norm2(x))
return x
| 架构 | Mamba:Attn | 长序列 | 短序列 | 召回 | 推理显存 |
|---|---|---|---|---|---|
| 纯Transformer | 0:1 | 差 | 优 | 优 | O(L) KV |
| 纯Mamba | 1:0 | 优 | 良 | 差 | O(1) 固定 |
| Jamba | 7:1 | 优 | 优 | 良 | 低 |
| Granite 4.0 | 9:1 | 优 | 优 | 良 | 低 |
| Nemotron-3 | ~9:1 | 优 | 优 | 良 | 低 |
| 1:1混合 | 1:1 | 中 | 优 | 优 | 中 |
# 推理性能估算
def estimate_inference(d=4096, n_layers=48, L=32768,
mamba_ratio=0.9, batch=1):
n_mamba = int(n_layers * mamba_ratio)
n_attn = n_layers - n_mamba
# Mamba: O(d*N) per step, N=16
mamba_flops = n_mamba * d * 16 * 2
# Attention: O(L*d) per step
attn_flops = n_attn * L * d * 2
# KV cache: only attention layers
kv_cache = n_attn * L * d * 2 * 2 / (1024**2) # MB, fp16
# SSM state: mamba layers
ssm_state = n_mamba * d * 16 * 2 / (1024**2) # MB
total_flops = mamba_flops + attn_flops
print(f"Mamba:Attn = {n_mamba}:{n_attn}, L={L}")
print(f" Mamba FLOPs/step: {mamba_flops/1e6:.1f}M")
print(f" Attn FLOPs/step: {attn_flops/1e6:.1f}M")
print(f" KV Cache: {kv_cache:.1f}MB, SSM State: {ssm_state:.2f}MB")
print(f" Total Cache: {kv_cache+ssm_state:.1f}MB")
return total_flops
print("=== 纯Transformer ===")
estimate_inference(mamba_ratio=0.0)
print("\n=== Granite 4.0 (9:1) ===")
estimate_inference(mamba_ratio=0.9)
print("\n=== 纯Mamba ===")
estimate_inference(mamba_ratio=1.0)
def select_architecture(seq_length, need_recall, need_long_context,
inference_latency_critical, param_budget):
"""根据需求选择最优架构"""
if seq_length < 4096 and not need_long_context:
return "纯Transformer (短序列最优)"
if need_recall and seq_length > 32768:
if param_budget > 10e9:
return "混合架构 + MoE (Jamba/Nemotron风格)"
return "混合架构 (Granite/Jamba风格, 9:1)"
if inference_latency_critical and not need_recall:
return "纯Mamba (最低延迟, 固定状态)"
if seq_length > 100000:
return "混合架构 (Mamba为主 + 少量Attention)"
return "纯Transformer或1:1混合"
# 示例决策
print("短文本对话:", select_architecture(2048, True, False, False, 7e9))
print("长文档理解:", select_architecture(131072, True, True, False, 12e9))
print("实时流式:", select_architecture(65536, False, True, True, 3e9))
print("代码补全:", select_architecture(8192, True, False, True, 7e9))
混合架构正在成为大模型设计的主流方向。关键趋势包括:
从信息论角度,不同的序列建模方法在信息存储和传递上有本质区别。Transformer通过注意力矩阵实现全局信息路由,每个位置可以直接访问所有历史位置的信息。SSM通过递推隐状态压缩历史信息,信息瓶颈为O(N)(状态维度)。混合架构通过少量Attention层突破SSM的信息瓶颈,同时保持整体效率。
其中I是互信息,d是模型维度,N是SSM状态维度,Lmamba和Lattn分别是Mamba和Attention层数。混合架构的信息容量远超纯SSM,同时计算量远低于纯Transformer。
混合架构中不同层类型的梯度传播特性不同。Mamba层的梯度通过递推状态传播,具有指数衰减特性(类似RNN的梯度消失)。Attention层的梯度通过注意力权重直接传播,路径更短。混合放置Attention层可以"刷新"梯度流,缓解深层Mamba的梯度消失问题。
import torch
import torch.nn as nn
def analyze_gradient_flow(n_layers=48, mamba_ratio=0.9,
d_model=1024, seq_len=512):
"""分析混合架构的梯度流"""
n_mamba = int(n_layers * mamba_ratio)
n_attn = n_layers - n_mamba
interval = n_layers // n_attn if n_attn > 0 else n_layers
# 模拟梯度范数随深度变化
grad_norms = []
grad = 1.0
for i in range(n_layers):
is_attn = (i + 1) % interval == 0
if is_attn:
grad *= 0.95 # Attention: 梯度保持较好
else:
grad *= 0.98 # Mamba: 轻微衰减
grad_norms.append(grad)
print(f"层数: {n_layers}, Mamba: {n_mamba}, Attn: {n_attn}")
print(f"最终梯度范数: {grad:.4f}")
print(f"最小梯度范数: {min(grad_norms):.4f}")
return grad_norms
print("=== 纯Transformer ===")
analyze_gradient_flow(mamba_ratio=0.0)
print("\n=== 混合 9:1 ===")
analyze_gradient_flow(mamba_ratio=0.9)
print("\n=== 纯Mamba ===")
analyze_gradient_flow(mamba_ratio=1.0)
GQA(Grouped-Query Attention)通过共享KV头减少KV缓存。将查询头分为G组,每组共享一个KV头。当G=1时退化为多查询注意力(MQA),当G=n_heads时退化为标准多头注意力(MHA)。
| 配置 | Query头 | KV头 | KV Cache压缩 | 代表模型 |
|---|---|---|---|---|
| MHA | 32 | 32 | 1x (无压缩) | GPT-3, Llama-1 |
| GQA-8 | 32 | 8 | 4x | Llama-3 |
| GQA-4 | 32 | 4 | 8x | Mistral |
| MQA | 32 | 1 | 32x | PaLM, Gemini |
class GroupedQueryAttention(nn.Module):
"""分组查询注意力 (GQA)"""
def __init__(self, d_model=4096, n_heads=32, n_kv_heads=8):
super().__init__()
self.n_heads = n_heads
self.n_kv_heads = n_kv_heads
self.n_rep = n_heads // n_kv_heads
self.d_head = d_model // n_heads
self.wq = nn.Linear(d_model, n_heads * self.d_head, bias=False)
self.wk = nn.Linear(d_model, n_kv_heads * self.d_head, bias=False)
self.wv = nn.Linear(d_model, n_kv_heads * self.d_head, bias=False)
self.wo = nn.Linear(n_heads * self.d_head, d_model, bias=False)
def forward(self, x, kv_cache=None):
B, L, D = x.shape
q = self.wq(x).view(B, L, self.n_heads, self.d_head)
k = self.wk(x).view(B, L, self.n_kv_heads, self.d_head)
v = self.wv(x).view(B, L, self.n_kv_heads, self.d_head)
# 复制KV头以匹配Query头数
k = k.repeat_interleave(self.n_rep, dim=2)
v = v.repeat_interleave(self.n_rep, dim=2)
# 标准注意力计算
scores = torch.einsum("blhd,bshd->bhls", q, k) / (self.d_head ** 0.5)
attn = F.softmax(scores, dim=-1)
out = torch.einsum("bhls,bshd->blhd", attn, v)
return self.wo(out.reshape(B, L, -1))
DeepSeek-V2/V3的MLA通过低秩潜在向量压缩KV缓存。将KV投影到低维潜在空间,推理时只缓存潜在向量,通过上投影恢复完整KV。压缩比可达10x以上。
class MultiheadLatentAttention(nn.Module):
"""DeepSeek-V2/V3的MLA注意力"""
def __init__(self, d_model=7168, n_heads=128,
d_latent=512, d_rope=64):
super().__init__()
self.n_heads = n_heads
self.d_head = d_model // n_heads
self.d_latent = d_latent
# QKV下投影到潜在空间
self.q_down = nn.Linear(d_model, d_latent, bias=False)
self.kv_down = nn.Linear(d_model, d_latent, bias=False)
# 上投影回多头空间
self.q_up = nn.Linear(d_latent, n_heads * self.d_head, bias=False)
self.k_up = nn.Linear(d_latent, n_heads * self.d_head, bias=False)
self.v_up = nn.Linear(d_latent, n_heads * self.d_head, bias=False)
self.wo = nn.Linear(n_heads * self.d_head, d_model, bias=False)
def forward(self, x):
B, L, D = x.shape
# 下投影: 缓存潜在向量 (大幅压缩)
c_q = self.q_down(x) # (B, L, d_latent) - 只需缓存这个
c_kv = self.kv_down(x) # (B, L, d_latent)
# 上投影: 恢复完整QKV
q = self.q_up(c_q).view(B, L, self.n_heads, self.d_head)
k = self.k_up(c_kv).view(B, L, self.n_heads, self.d_head)
v = self.v_up(c_kv).view(B, L, self.n_heads, self.d_head)
scores = torch.einsum("blhd,bshd->bhls", q, k) / (self.d_head ** 0.5)
attn = F.softmax(scores, dim=-1)
out = torch.einsum("bhls,bshd->blhd", attn, v)
return self.wo(out.reshape(B, L, -1))
# KV缓存对比
d_model, n_heads, d_latent, L = 7168, 128, 512, 131072
mha_cache = 2 * n_heads * (d_model // n_heads) * L * 2 / (1024**2)
mla_cache = 2 * d_latent * L * 2 / (1024**2)
print(f"MHA KV Cache: {mha_cache:.0f}MB")
print(f"MLA KV Cache: {mla_cache:.0f}MB")
print(f"压缩比: {mha_cache/mla_cache:.1f}x")
混合架构中不同层类型有不同的训练特性,联合训练面临以下挑战:
class HybridTrainingStrategy:
"""混合架构训练策略"""
def __init__(self, model):
self.model = model
# 分组参数: 不同层类型使用不同学习率
mamba_params = []
attn_params = []
moe_params = []
other_params = []
for name, param in model.named_parameters():
if "mamba" in name or "ssm" in name:
mamba_params.append(param)
elif "attn" in name or "attention" in name:
attn_params.append(param)
elif "expert" in name or "router" in name:
moe_params.append(param)
else:
other_params.append(param)
self.param_groups = [
{"params": mamba_params, "lr": 3e-4},
{"params": attn_params, "lr": 1e-4},
{"params": moe_params, "lr": 2e-4},
{"params": other_params, "lr": 3e-4},
]
def warmup_strategy(self, step, warmup_steps=1000):
"""分阶段warmup: 先训练Mamba, 再加入Attention"""
if step < warmup_steps // 2:
# 阶段1: 冻结Attention, 只训练Mamba
for p in self.param_groups[1]["params"]:
p.requires_grad = False
else:
for p in self.param_groups[1]["params"]:
p.requires_grad = True
# 学习率warmup
lr_scale = min(step / warmup_steps, 1.0)
for group in self.param_groups:
group["lr_current"] = group["lr"] * lr_scale
实验发现混合架构在数据效率上优于纯Transformer和纯Mamba。Mamba层的归纳偏置(序列建模假设)使其在小数据上泛化更好,Attention层的灵活性使其能从大数据中学习复杂模式。混合架构兼得两者优势。
| 架构 | 100B tokens | 500B tokens | 2T tokens | 数据效率 |
|---|---|---|---|---|
| 纯Transformer | 较差 | 中等 | 优 | 低 (需大量数据) |
| 纯Mamba | 中等 | 良 | 良 | 高 (归纳偏置强) |
| 混合9:1 | 良 | 优 | 优 | 高 (兼得两者优势) |
| 模型 | 机构 | SSM类型 | Attn比例 | MoE | 上下文 | 特点 |
|---|---|---|---|---|---|---|
| Jamba | AI21 | Mamba-1 | 1:7 | ✓ | 256K | 首个商用混合 |
| Granite 4.0 | IBM | Mamba-2 | 1:9 | ✗ | 128K | 9:1比例验证 |
| Nemotron-3 | NVIDIA | Mamba-2 | ~1:9 | ✓ | 128K | MoE+GQA集成 |
| Kimi Linear | Moonshot | 线性Attn | 1:0 | ✗ | 256K | 线性注意力 |
| Zamba | Zyphra | Mamba-2 | 1:5 | ✓ | 128K | 共享Attention |
# 混合架构选型决策矩阵
models = {
"纯Transformer": {
"长序列": 1, "召回": 5, "推理效率": 2,
"训练效率": 4, "数据效率": 2, "参数效率": 3
},
"纯Mamba": {
"长序列": 5, "召回": 2, "推理效率": 5,
"训练效率": 4, "数据效率": 4, "参数效率": 4
},
"Jamba (7:1)": {
"长序列": 5, "召回": 4, "推理效率": 4,
"训练效率": 4, "数据效率": 4, "参数效率": 5
},
"Granite (9:1)": {
"长序列": 5, "召回": 4, "推理效率": 5,
"训练效率": 4, "数据效率": 5, "参数效率": 4
},
}
print(f"{'模型':>18} {'长序列':>6} {'召回':>6} {'推理':>6} {'训练':>6} {'数据':>6} {'参数':>6} {'总分':>6}")
for name, scores in models.items():
total = sum(scores.values())
row = f"{name:>18}"
for k in ["长序列", "召回", "推理效率", "训练效率", "数据效率", "参数效率"]:
row += f" {scores[k]:>6}"
row += f" {total:>6}"
print(row)
print("\n评分1-5, 混合架构总分最高")
混合架构的推理引擎需要同时处理Mamba的递推状态和Attention的KV缓存。关键设计包括:Mamba状态的高效更新、Attention KV缓存的管理、以及两种状态在GPU/CPU之间的offload策略。
class HybridInferenceEngine:
"""混合架构推理引擎"""
def __init__(self, model, device="cuda"):
self.model = model
self.device = device
# 初始化每层缓存
self.caches = []
for i, layer in enumerate(model.layers):
if isinstance(layer.seq, MambaBlock):
self.caches.append({
"type": "ssm",
"state": torch.zeros(model.d_inner, model.d_state, device=device)
})
else:
self.caches.append({
"type": "attn",
"kv_cache": [], # 动态增长
"max_len": 131072
})
def prefill(self, input_ids):
"""预填充阶段: 批量处理prompt"""
x = self.model.embedding(input_ids)
for i, layer in enumerate(self.model.layers):
x, self.caches[i] = layer.forward_with_cache(x, self.caches[i])
return self.model.lm_head(x)
def decode_step(self, token_id):
"""解码阶段: 逐token生成"""
x = self.model.embedding(token_id).unsqueeze(0)
for i, layer in enumerate(self.model.layers):
x, self.caches[i] = layer.step_with_cache(x, self.caches[i])
logits = self.model.lm_head(x)
return logits
def estimate_memory(self, seq_len):
"""估算推理显存"""
ssm_mem = 0
attn_mem = 0
for cache in self.caches:
if cache["type"] == "ssm":
ssm_mem += cache["state"].numel() * 2
else:
attn_mem += seq_len * self.model.d_model * 2 * 2
return ssm_mem, attn_mem
混合架构在 batching 时面临不同请求序列长度差异大的问题。Mamba层的固定状态使得不同请求可以高效 batch,但Attention层的 KV cache 长度不同导致 padding 浪费。解决方案包括:连续 batching(每个请求独立管理缓存位置)、Mamba层跨请求共享计算、以及Attention层的 padding 压缩。
混合架构中不同层类型的梯度传播特性不同。SSM层的梯度通过状态矩阵传播,Attention层通过softmax注意力传播。混合比例需要平衡两者的梯度流。
def analyze_hybrid_gradients(model, input_data):
"""分析混合架构各层梯度"""
layer_grads = {}
for name, module in model.named_modules():
if "mamba" in name or "attention" in name:
grads = []
for p in module.parameters():
if p.grad is not None:
grads.append(p.grad.norm().item())
if grads:
layer_grads[name] = sum(grads) / len(grads)
return layer_grads
# 理想的梯度比例: SSM层和Attention层梯度范数应接近
# 如果差异过大, 需要调整混合比例或添加梯度缩放
# Granite 4.0 混合配置 (Mamba:Attention = 9:1)
granite_config = {
"num_layers": 32,
"layer_pattern": ["mamba"]*9 + ["attention"], # 重复3次
"d_model": 4096,
"mamba_d_state": 128,
"attention_heads": 32,
"attention_group_size": 8, # GQA
}
# Jamba配置 (交替Mamba和Attention)
jamba_config = {
1: ["mamba", "mamba", "mamba", "attention", "moe"],
2: ["mamba", "mamba", "mamba", "attention", "moe"],
"note": "每5层一组, 含1个attention + 1个MoE",
}
# Kimi Linear配置
kimi_config = {
"total_layers": 61,
"attention_layers": [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59],
"ratio": "Mamba:Attention ≈ 3:1",
}
print("Granite 4.0:", granite_config["layer_pattern"])
print("Kimi Linear ratio:", kimi_config["ratio"])
| 模型 | 架构 | 参数量 | 吞吐(tok/s) | 显存(GB) |
|---|---|---|---|---|
| Transformer-7B | 纯Attention | 7B | ~120 | 14 |
| Mamba-7B | 纯SSM | 7B | ~800 | 14 |
| Jamba-7B | 混合8:1 | 7B | ~500 | 14 |
| Granite-7B | 混合9:1 | 7B | ~550 | 14 |
| Kimi Linear | 混合3:1 | 20B | ~300 | 40 |
混合比例是混合架构最重要的超参数。过少的Attention层会损害精确检索能力,过多的Attention层则失去SSM的效率优势。实验表明Mamba:Attention=3:1到9:1之间是较好的平衡点。
| Mamba:Attn | 长序列PPL | 检索准确率 | 推理速度 | 推荐场景 |
|---|---|---|---|---|
| 1:1 | 3.21 | 98.2% | 1.0x | 需要强检索 |
| 3:1 | 3.18 | 96.5% | 2.5x | 通用平衡 |
| 5:1 | 3.15 | 94.1% | 3.8x | 效率优先 |
| 9:1 | 3.19 | 89.3% | 5.2x | 长文本生成 |
| 纯Mamba | 3.35 | 72.0% | 6.7x | 流式处理 |
除了混合比例,层的排列顺序也影响性能。常见策略包括:均匀交替(每k层1个Attention)、块状交替(连续m个Mamba后1个Attention)、首尾Attention(首尾各1个Attention中间全Mamba)。
未来方向包括自适应混合架构:根据输入特征动态选择使用SSM还是Attention。例如对需要精确检索的token使用Attention,对长程依赖的token使用SSM。这种动态路由可以同时获得两种架构的优势。
多模态场景中,不同模态可能适合不同架构:文本的长程依赖适合SSM,图像的局部模式适合卷积/SSM,结构化数据可能需要Attention。混合架构为多模态模型提供了更灵活的设计空间。
SSM的scan操作和Attention的矩阵乘法有不同的硬件特性。未来可能出现专门为混合架构设计的硬件加速器,同时优化两种计算模式。