<!DOCTYPE html><html lang="zh"><head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>RWKV模型深度研究报告 | 2026年2月</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#1e293b',
secondary: '#64748b',
accent: '#0f172a',
neutral: '#f8fafc',
'base-100': '#ffffff',
'base-200': '#f1f5f9',
'base-300': '#e2e8f0'
},
fontFamily: {
'sans': ['Inter', 'system-ui', 'sans-serif'],
'display': ['Playfair Display', 'serif'],
'mono': ['JetBrains Mono', 'monospace']
}
}
}
}
</script>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400;1,600&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10.6.1/dist/mermaid.min.js"></script>
<style>
.gradient-overlay {
background: linear-gradient(135deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.7) 100%);
}
.text-shadow {
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.hero-pattern {
background-image:
radial-gradient(circle at 25% 25%, rgba(100, 116, 139, 0.1) 0%, transparent 50%),
radial-gradient(circle at 75% 75%, rgba(100, 116, 139, 0.05) 0%, transparent 50%);
}
.mermaid-container {
display: flex;
justify-content: center;
min-height: 100px;
max-height: 800px;
background: #ffffff;
border: 2px solid #e5e7eb;
border-radius: 12px;
padding: 30px;
margin: 30px 0;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
position: relative;
overflow: hidden;
}
.mermaid-container .mermaid {
width: 100%;
max-width: 100%;
height: 100%;
cursor: grab;
transition: transform 0.3s ease;
transform-origin: center center;
display: flex;
justify-content: center;
align-items: center;
touch-action: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.mermaid-container .mermaid svg {
max-width: 100%;
height: 100%;
display: block;
margin: 0 auto;
}
.mermaid-container .mermaid:active {
cursor: grabbing;
}
.mermaid-container.zoomed .mermaid {
height: 100%;
width: 100%;
cursor: grab;
}
.mermaid-controls {
position: absolute;
top: 15px;
right: 15px;
display: flex;
gap: 10px;
z-index: 20;
background: rgba(255, 255, 255, 0.95);
padding: 8px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.mermaid-control-btn {
background: #ffffff;
border: 1px solid #d1d5db;
border-radius: 6px;
padding: 10px;
cursor: pointer;
transition: all 0.2s ease;
color: #374151;
font-size: 14px;
min-width: 36px;
height: 36px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.mermaid-control-btn:hover {
background: #f8fafc;
border-color: #3b82f6;
color: #3b82f6;
transform: translateY(-1px);
}
.mermaid-control-btn:active {
transform: scale(0.95);
}
/* Mermaid node styling for better contrast */
.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon {
stroke-width: 2px !important;
stroke: #475569 !important;
}
.mermaid .node .label {
color: #334155 !important;
font-weight: 500 !important;
font-size: 13px !important;
text-shadow: none !important;
}
.mermaid .edgePath .path {
stroke: #64748b !important;
stroke-width: 2px !important;
}
.mermaid .edgeLabel {
background-color: rgba(255, 255, 255, 0.9) !important;
color: #475569 !important;
font-size: 11px !important;
font-weight: 500 !important;
padding: 2px 6px !important;
border-radius: 4px !important;
}
/* Ensure text readability in all mermaid elements */
.mermaid text {
font-family: 'Inter', system-ui, sans-serif !important;
text-shadow: none !important;
}
/* Enhanced contrast for different node colors */
.mermaid .node[style*="fill:#e3f2fd"] .label,
.mermaid .node[style*="fill:#e8f5e8"] .label,
.mermaid .node[style*="fill:#f3e5f5"] .label,
.mermaid .node[style*="fill:#fff3e0"] .label,
.mermaid .node[style*="fill:#e0f2f1"] .label,
.mermaid .node[style*="fill:#f1f8e9"] .label,
.mermaid .node[style*="fill:#fbe9e7"] .label {
color: #1e293b !important;
font-weight: 600 !important;
}
/* Prevent horizontal overflow on small screens */
<span class="mention-invalid">@media</span> (max-width: 767px) {
body {
overflow-x: hidden;
}
.mermaid-container {
padding: 15px;
}
}
</style>
<base target="_blank">
</head>
<body class="bg-base-100 text-primary font-sans leading-relaxed">
<!-- Main Content -->
<div class="max-w-6xl mx-auto px-4 md:px-8 py-16">
<!-- Backdrop for mobile TOC -->
<div id="toc-backdrop" class="fixed inset-0 bg-black/50 z-40 hidden lg:hidden"></div>
<!-- Mobile TOC Toggle -->
<button id="mobile-toc-toggle" class="fixed top-4 left-4 z-50 lg:hidden bg-primary text-white p-3 rounded-full shadow-lg">
<i class="fas fa-bars"></i>
</button>
<!-- Executive Summary -->
<section id="executive-summary" class="mb-20">
<div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-2xl p-4 md:p-8 border border-blue-100">
<h2 class="font-display text-3xl font-bold text-primary mb-6">执行摘要</h2>
<div class="prose prose-lg max-w-none">
<p class="text-lg text-secondary leading-relaxed mb-6">
RWKV是一种创新的RNN-Transformer混合架构,通过线性注意力机制实现了<strong>O(n)的时间复杂度</strong>和<strong>O(1)的内存占用</strong>。截至2026年1月,RWKV-7-G1系列在保持同等模型质量水平的同时,相比传统Transformer架构展现出数量级的效率优势。
</p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mt-8">
<div class="bg-white rounded-lg p-6 shadow-sm border border-blue-100">
<div class="text-xl font-semibold text-primary mb-2">架构突破</div>
<p class="text-sm text-secondary">完全摒弃O(n²)自注意力机制,采用线性递归状态更新</p>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-blue-100">
<div class="text-xl font-semibold text-primary mb-2">性能优势</div>
<p class="text-sm text-secondary">RTX 4090上115+ tokens/s,显存占用低至2.4GB</p>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-blue-100">
<div class="text-xl font-semibold text-primary mb-2">应用前景</div>
<p class="text-sm text-secondary">特别适合长文档处理、实时交互和边缘部署场景</p>
</div>
</div>
</div>
</div>
</section>
<!-- Model Architecture -->
<section id="architecture" class="mb-20">
<h2 class="font-display text-4xl font-bold text-primary mb-12">模型架构与技术原理</h2>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">核心架构设计</h3>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-12 mb-12">
<div>
<h4 class="text-xl font-semibold text-primary mb-4">RNN-Transformer混合架构</h4>
<p class="text-secondary mb-6 leading-relaxed">
RWKV(Receptance Weighted Key Value)通过线性注意力机制替代传统多头注意力,成功融合了RNN的高效推理特性与Transformer的并行训练优势。该架构由Bo Peng及其领导的RWKV开源社区开发,自2023年加入Linux基金会以来,已发展成为备受关注的非盈利开源项目。
</p>
<div class="bg-blue-50 border-l-4 border-blue-400 p-4 rounded-r-lg">
<p class="text-sm text-blue-800">
<strong>关键创新:</strong>完全摒弃O(n²)自注意力机制,采用递归状态更新机制,将复杂度降至O(n)线性级别
</p>
</div>
</div>
<div>
<img src="https://kimi-web-img.moonshot.cn/img/pic4.zhimg.com/4127ed9565616dc5def74c2948a81c9a59ca1732.webp" alt="RNN和Transformer混合神经网络结构示意图" class="w-full rounded-lg shadow-md" size="medium" aspect="wide" style="linedrawing" query="RNN Transformer 混合架构" referrerpolicy="no-referrer" data-modified="1" data-score="0.00"/>
</div>
</div>
<!-- Mermaid Diagram -->
<div class="mermaid-container">
<div class="mermaid-controls">
<button class="mermaid-control-btn zoom-in" title="放大">
<i class="fas fa-search-plus"></i>
</button>
<button class="mermaid-control-btn zoom-out" title="缩小">
<i class="fas fa-search-minus"></i>
</button>
<button class="mermaid-control-btn reset-zoom" title="重置">
<i class="fas fa-expand-arrows-alt"></i>
</button>
<button class="mermaid-control-btn fullscreen" title="全屏查看">
<i class="fas fa-expand"></i>
</button>
</div>
<div class="mermaid">
graph TD
A["Input Sequence"] --> B["Token Embedding"]
B --> C["Time-Mixing Block"]
B --> D["Channel-Mixing Block"]
C --> E["Receptance Gate R"]
C --> F["Weight Decay W"]
C --> G["Key K & Value V"]
E --> H["State Update"]
F --> H
G --> H
H --> I["Next Layer"]
D --> J["Feature Transformation"]
J --> I
style A fill:#e3f2fd,stroke:#1976d2,stroke-width:2px,color:#1e293b
style B fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#1e293b
style C fill:#e8f5e8,stroke:#388e3c,stroke-width:2px,color:#1e293b
style D fill:#fff3e0,stroke:#f57c00,stroke-width:2px,color:#1e293b
style H fill:#fce4ec,stroke:#c2185b,stroke-width:3px,color:#1e293b
style I fill:#f1f8e9,stroke:#689f38,stroke-width:2px,color:#1e293b
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h5 class="font-semibold text-primary mb-4">Time-Mixing Block</h5>
<p class="text-secondary text-sm mb-4">
负责处理时序信息交互,通过RWKV机制实现历史信息的递归聚合。引入Token Shift机制增强局部上下文敏感性。
</p>
<ul class="text-sm text-secondary space-y-2">
<li>• Receptance门控历史信息</li>
<li>• Weighted时间衰减机制</li>
<li>• Key-Value信息传递</li>
</ul>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h5 class="font-semibold text-primary mb-4">Channel-Mixing Block</h5>
<p class="text-secondary text-sm mb-4">
负责特征维度的非线性变换,功能类似Transformer的前馈网络,但完全并行化,不影响推理效率。
</p>
<ul class="text-sm text-secondary space-y-2">
<li>• 特征空间线性变换</li>
<li>• SiLU/GeLU激活函数</li>
<li>• 时间步独立处理</li>
</ul>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">计算效率优势</h3>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-12">
<div class="bg-green-50 rounded-lg p-6 border border-green-200">
<div class="flex items-center mb-4">
<i class="fas fa-clock text-green-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">线性时间复杂度</h4>
</div>
<p class="text-sm text-secondary mb-4">
O(n) vs Transformer的O(n²),处理10K token时效率提升可达三个数量级
</p>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded">
每token处理时间恒定,不受序列长度影响
</div>
</div>
<div class="bg-blue-50 rounded-lg p-6 border border-blue-200">
<div class="flex items-center mb-4">
<i class="fas fa-memory text-blue-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">常数级内存</h4>
</div>
<p class="text-sm text-secondary mb-4">
状态内存仅400KB,与序列长度无关,相比Transformer提升超100万倍
</p>
<div class="text-xs text-blue-700 bg-blue-100 p-2 rounded">
无需KV-Cache,内存占用与序列长度零相关
</div>
</div>
<div class="bg-purple-50 rounded-lg p-6 border border-purple-200">
<div class="flex items-center mb-4">
<i class="fas fa-microchip text-purple-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">硬件友好</h4>
</div>
<p class="text-sm text-secondary mb-4">
规则化内存访问模式,充分利用GPU计算单元,避免内存带宽瓶颈
</p>
<div class="text-xs text-purple-700 bg-purple-100 p-2 rounded">
消费级GPU即可实现高性能推理
</div>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">架构演进历程</h3>
<div class="overflow-x-auto">
<table class="w-full bg-white rounded-lg shadow-sm border border-base-300">
<thead class="bg-base-200">
<tr>
<th class="px-6 py-4 text-left font-semibold text-primary">版本</th>
<th class="px-6 py-4 text-left font-semibold text-primary">代号</th>
<th class="px-6 py-4 text-left font-semibold text-primary">核心创新</th>
<th class="px-6 py-4 text-left font-semibold text-primary">最大参数</th>
</tr>
</thead>
<tbody class="divide-y divide-base-300">
<tr>
<td class="px-6 py-4 text-sm">RWKV-4</td>
<td class="px-6 py-4 text-sm">基础版</td>
<td class="px-6 py-4 text-sm">验证混合架构可行性</td>
<td class="px-6 py-4 text-sm">14B</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">RWKV-5/6</td>
<td class="px-6 py-4 text-sm">Eagle & Finch</td>
<td class="px-6 py-4 text-sm">矩阵值状态表示</td>
<td class="px-6 py-4 text-sm">7B</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">RWKV-7</td>
<td class="px-6 py-4 text-sm">Goose</td>
<td class="px-6 py-4 text-sm">动态状态演化、广义Delta规则</td>
<td class="px-6 py-4 text-sm">13B</td>
</tr>
<tr class="bg-blue-50">
<td class="px-6 py-4 text-sm font-semibold">RWKV-7-G1</td>
<td class="px-6 py-4 text-sm font-semibold">GooseOne</td>
<td class="px-6 py-4 text-sm">推理专用优化版本</td>
<td class="px-6 py-4 text-sm font-semibold">2.9B-13B</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- Performance Analysis -->
<section id="performance" class="mb-20">
<h2 class="font-display text-4xl font-bold text-primary mb-12">推理性能深度分析</h2>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">消费级GPU性能实测</h3>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-12">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h4 class="font-semibold text-primary mb-4">RTX 4090平台</h4>
<div class="space-y-4">
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">FP16精度</span>
<span class="font-mono text-sm font-semibold">95.98 t/s</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">INT8精度</span>
<span class="font-mono text-sm font-semibold text-blue-600">108.22 t/s</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">NF4精度</span>
<span class="font-mono text-sm font-semibold text-green-600">115.46 t/s</span>
</div>
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h4 class="font-semibold text-primary mb-4">RTX 4060 Ti 8GB</h4>
<div class="space-y-4">
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">FP16精度</span>
<span class="font-mono text-sm font-semibold">43.92 t/s</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">INT8精度</span>
<span class="font-mono text-sm font-semibold text-blue-600">62.93 t/s</span>
</div>
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">NF4精度</span>
<span class="font-mono text-sm font-semibold text-green-600">86.03 t/s</span>
</div>
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h4 class="font-semibold text-primary mb-4">AMD RX 7900 XTX</h4>
<div class="space-y-4">
<div class="flex justify-between items-center">
<span class="text-sm text-secondary">INT8精度</span>
<span class="font-mono text-sm font-semibold text-green-600">137.36 t/s</span>
</div>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded mt-4">
比RTX 4090同配置快27%,展现优秀硬件无关性
</div>
</div>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">量化技术效果分析</h3>
<div class="bg-gradient-to-r from-yellow-50 to-orange-50 rounded-lg p-8 border border-yellow-200 mb-8">
<h4 class="font-semibold text-primary mb-4">精度-速度-显存权衡</h4>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="text-center">
<div class="text-2xl font-bold text-blue-600 mb-2">INT8</div>
<div class="text-sm text-secondary">速度+12.8%,显存-33.9%</div>
<div class="text-xs text-blue-700 mt-2">质量与FP16相当</div>
</div>
<div class="text-center">
<div class="text-2xl font-bold text-green-600 mb-2">NF4</div>
<div class="text-sm text-secondary">速度+20.3%,显存-59.3%</div>
<div class="text-xs text-green-700 mt-2">推荐用于资源受限场景</div>
</div>
<div class="text-center">
<div class="text-2xl font-bold text-purple-600 mb-2">FP16</div>
<div class="text-sm text-secondary">最高质量,无精度损失</div>
<div class="text-xs text-purple-700 mt-2">质量敏感场景首选</div>
</div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full bg-white rounded-lg shadow-sm border border-base-300">
<thead class="bg-base-200">
<tr>
<th class="px-6 py-4 text-left font-semibold text-primary">推理引擎</th>
<th class="px-6 py-4 text-left font-semibold text-primary">支持精度</th>
<th class="px-6 py-4 text-left font-semibold text-primary">平台覆盖</th>
<th class="px-6 py-4 text-left font-semibold text-primary">核心特点</th>
</tr>
</thead>
<tbody class="divide-y divide-base-300">
<tr class="bg-blue-50">
<td class="px-6 py-4 text-sm font-semibold">web-rwkv</td>
<td class="px-6 py-4 text-sm">FP16/INT8/NF4</td>
<td class="px-6 py-4 text-sm">NVIDIA/AMD/Intel</td>
<td class="px-6 py-4 text-sm">推荐方案,跨平台高性能</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">llama.cpp</td>
<td class="px-6 py-4 text-sm">Q4_0-Q8_0等GGUF</td>
<td class="px-6 py-4 text-sm">跨平台</td>
<td class="px-6 py-4 text-sm">生态成熟,格式丰富</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">RWKV pip</td>
<td class="px-6 py-4 text-sm">FP16/INT8(有限)</td>
<td class="px-6 py-4 text-sm">NVIDIA (CUDA)</td>
<td class="px-6 py-4 text-sm">官方实现,易用性高</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">Ai00 Server</td>
<td class="px-6 py-4 text-sm">INT8/NF4</td>
<td class="px-6 py-4 text-sm">跨平台</td>
<td class="px-6 py-4 text-sm">开箱即用API服务器</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">长序列处理能力</h3>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-12">
<div>
<h4 class="text-xl font-semibold text-primary mb-6">理论无限上下文支持</h4>
<p class="text-secondary mb-6 leading-relaxed">
RWKV采用递归状态机制而非KV缓存,处理序列的内存占用与序列长度完全无关。无论是100 token还是100万token,所需的状态内存都是固定的约400KB。
</p>
<div class="bg-blue-50 border-l-4 border-blue-400 p-4 rounded-r-lg mb-6">
<p class="text-sm text-blue-800">
<strong>架构层面原生能力:</strong>"无限上下文"无需特殊技巧即可实现,而非通过滑动窗口等近似方法
</p>
</div>
<img src="https://kimi-web-img.moonshot.cn/img/www.rwkv.cn/139587058ebcb66896f4985e95cc11292b1ed46f" alt="RWKV模型状态内存固定示意图" class="w-full rounded-lg shadow-md" size="medium" aspect="wide" query="RWKV模型状态内存固定" referrerpolicy="no-referrer" data-modified="1" data-score="0.00"/>
</div>
<div>
<h4 class="text-xl font-semibold text-primary mb-6">实际部署限制</h4>
<div class="space-y-4">
<div class="bg-white rounded-lg p-4 shadow-sm border border-base-300">
<h5 class="font-semibold text-primary mb-2">训练上下文限制</h5>
<p class="text-sm text-secondary">模型在特定长度上训练,超出范围性能可能衰减,但可通过微调扩展</p>
</div>
<div class="bg-white rounded-lg p-4 shadow-sm border border-base-300">
<h5 class="font-semibold text-primary mb-2">数值稳定性</h5>
<p class="text-sm text-secondary">极长序列递归计算可能累积数值误差,需要特定处理策略</p>
</div>
<div class="bg-white rounded-lg p-4 shadow-sm border border-base-300">
<h5 class="font-semibold text-primary mb-2">应用层设计</h5>
<p class="text-sm text-secondary">大多数应用不需要真正无限上下文,RWKV的能力更多作为安全网</p>
</div>
</div>
<div class="mt-8 bg-yellow-50 rounded-lg p-4 border border-yellow-200">
<h5 class="font-semibold text-yellow-800 mb-2">性能对比(100K token)</h5>
<div class="text-sm text-yellow-700">
<div class="flex justify-between mb-1">
<span>RWKV:</span>
<span class="font-mono">~400KB</span>
</div>
<div class="flex justify-between mb-2">
<span>Transformer:</span>
<span class="font-mono">~20GB+</span>
</div>
<div class="text-xs font-semibold">内存效率优势超过50,000倍</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Benchmarks -->
<section id="benchmarks" class="mb-20">
<h2 class="font-display text-4xl font-bold text-primary mb-12">基准测试与模型对比</h2>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">标准学术基准测试</h3>
<div class="bg-orange-50 border-l-4 border-orange-400 p-6 rounded-r-lg mb-8">
<h4 class="font-semibold text-orange-800 mb-2">数据可用性说明</h4>
<p class="text-orange-700 text-sm">
截至2026年1月,RWKV在MMLU、HellaSwag、GSM8K等标准学术基准上的公开评估数据存在显著缺口。与Llama、Mistral等主流模型不同,RWKV项目未系统发布完整的基准测试报告。
</p>
</div>
<div class="overflow-x-auto mb-8">
<table class="w-full bg-white rounded-lg shadow-sm border border-base-300">
<thead class="bg-base-200">
<tr>
<th class="px-6 py-4 text-left font-semibold text-primary">模型</th>
<th class="px-6 py-4 text-left font-semibold text-primary">参数</th>
<th class="px-6 py-4 text-left font-semibold text-primary">MMLU</th>
<th class="px-6 py-4 text-left font-semibold text-primary">HellaSwag</th>
<th class="px-6 py-4 text-left font-semibold text-primary">GSM8K</th>
<th class="px-6 py-4 text-left font-semibold text-primary">训练数据</th>
</tr>
</thead>
<tbody class="divide-y divide-base-300">
<tr>
<td class="px-6 py-4 text-sm">Llama-2-7B</td>
<td class="px-6 py-4 text-sm font-mono">7B</td>
<td class="px-6 py-4 text-sm">~45%</td>
<td class="px-6 py-4 text-sm">~75%</td>
<td class="px-6 py-4 text-sm">~15%</td>
<td class="px-6 py-4 text-sm">2T tokens</td>
</tr>
<tr class="bg-blue-50">
<td class="px-6 py-4 text-sm font-semibold">Mistral-7B-v0.1</td>
<td class="px-6 py-4 text-sm font-mono">7B</td>
<td class="px-6 py-4 text-sm">~60%</td>
<td class="px-6 py-4 text-sm">~80%</td>
<td class="px-6 py-4 text-sm">~37%</td>
<td class="px-6 py-4 text-sm">~2T+ tokens</td>
</tr>
<tr class="bg-green-50">
<td class="px-6 py-4 text-sm font-semibold">Llama-3-8B</td>
<td class="px-6 py-4 text-sm font-mono">8B</td>
<td class="px-6 py-4 text-sm">~68%</td>
<td class="px-6 py-4 text-sm">~78%</td>
<td class="px-6 py-4 text-sm">~46%</td>
<td class="px-6 py-4 text-sm">15T+ tokens</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm">Gemma-2-9B</td>
<td class="px-6 py-4 text-sm font-mono">9B</td>
<td class="px-6 py-4 text-sm">~65%</td>
<td class="px-6 py-4 text-sm">~82%</td>
<td class="px-6 py-4 text-sm">~50%</td>
<td class="px-6 py-4 text-sm">6T tokens</td>
</tr>
<tr class="bg-yellow-50">
<td class="px-6 py-4 text-sm font-semibold">RWKV-5/6 (估计)</td>
<td class="px-6 py-4 text-sm font-mono">7B</td>
<td class="px-6 py-4 text-sm">55-65%?</td>
<td class="px-6 py-4 text-sm">?</td>
<td class="px-6 py-4 text-sm">?</td>
<td class="px-6 py-4 text-sm">2.25T tokens</td>
</tr>
</tbody>
</table>
</div>
<div class="bg-blue-50 rounded-lg p-6 border border-blue-200">
<h4 class="font-semibold text-blue-800 mb-3">开发者报告的性能定位</h4>
<p class="text-blue-700 text-sm mb-4">
RWKV官方博客报告EagleX v2(RWKV-v5,14B,2.25T tokens)<strong>"明显超过了训练了2万亿token的Llama-2-7B,并且接近Mistral-7B-v0.1和Llama-3-8B"</strong>
</p>
<div class="text-xs text-blue-600">
数据来源:<a href="https://blog.rwkv.com/p/eaglex-v2-soaring-past-llama2-7b" class="underline hover:text-blue-800">RWKV官方博客</a>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">实际任务表现</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-code text-green-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">代码生成</h4>
</div>
<p class="text-sm text-secondary mb-4">
RWKV-7-G1系列明确强化了代码和数学能力。递归状态机制有助于维护语法结构的长期一致性。
</p>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded">
社区已开发专用代码补全模型
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-comments text-blue-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">多轮对话</h4>
</div>
<p class="text-sm text-secondary mb-4">
恒定每步延迟确保对话长度增加时响应时间稳定,不会出现Transformer中常见的"对话越久越慢"现象。
</p>
<div class="text-xs text-blue-700 bg-blue-100 p-2 rounded">
支持真正的"无限记忆"助手
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-stream text-purple-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">流式生成</h4>
</div>
<p class="text-sm text-secondary mb-4">
明确推荐用于"real-time streaming, chaining short prompts"场景,特别适合语音助手、实时翻译应用。
</p>
<div class="text-xs text-purple-700 bg-purple-100 p-2 rounded">
状态机制天然支持高效提示链接
</div>
</div>
</div>
</div>
</section>
<!-- Applications -->
<section id="applications" class="mb-20">
<h2 class="font-display text-4xl font-bold text-primary mb-12">应用场景与部署实践</h2>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">核心应用场景</h3>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-12 mb-12">
<div class="space-y-6">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-file-alt text-green-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">长文档处理</h4>
</div>
<p class="text-sm text-secondary mb-4">
法律合同审查、学术论文综述、金融报告摘要等需要处理数万至数十万token的场景。
</p>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded">
完整摄入文档,保持全局连贯理解,无需分段截断
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-robot text-blue-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">实时交互系统</h4>
</div>
<p class="text-sm text-secondary mb-4">
聊天机器人、虚拟助手等需要低延迟响应的应用场景。
</p>
<div class="text-xs text-blue-700 bg-blue-100 p-2 rounded">
恒定每token推理时间,确保无论对话历史多长,生成速度稳定
</div>
</div>
</div>
<div class="space-y-6">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-mobile-alt text-purple-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">边缘与端侧部署</h4>
</div>
<p class="text-sm text-secondary mb-4">
量化后的轻量级推理需求,适合资源受限环境。
</p>
<div class="text-xs text-purple-700 bg-purple-100 p-2 rounded">
骁龙8 Gen 3平台A16W4配置达到31.3 tokens/s
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-stream text-orange-600 text-xl mr-3"></i>
<h4 class="font-semibold text-primary">流式内容生成</h4>
</div>
<p class="text-sm text-secondary mb-4">
连续短提示的链式处理,Agent系统、工作流自动化等应用。
</p>
<div class="text-xs text-orange-700 bg-orange-100 p-2 rounded">
避免注意力矩阵爆炸,状态向量作为紧凑上下文表示
</div>
</div>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">模型版本选择指南</h3>
<div class="overflow-x-auto">
<table class="w-full bg-white rounded-lg shadow-sm border border-base-300">
<thead class="bg-base-200">
<tr>
<th class="px-6 py-4 text-left font-semibold text-primary">显存预算</th>
<th class="px-6 py-4 text-left font-semibold text-primary">推荐配置</th>
<th class="px-6 py-4 text-left font-semibold text-primary">预期性能</th>
<th class="px-6 py-4 text-left font-semibold text-primary">典型应用</th>
</tr>
</thead>
<tbody class="divide-y divide-base-300">
<tr>
<td class="px-6 py-4 text-sm font-semibold text-red-600"><4GB</td>
<td class="px-6 py-4 text-sm">RWKV7-G1-2.9B <strong>nf4</strong></td>
<td class="px-6 py-4 text-sm">20-40 t/s (GPU), 可用 (CPU)</td>
<td class="px-6 py-4 text-sm">边缘设备,轻量助手,离线处理</td>
</tr>
<tr class="bg-blue-50">
<td class="px-6 py-4 text-sm font-semibold text-blue-600">8GB</td>
<td class="px-6 py-4 text-sm">RWKV7-G1-2.9B <strong>int8</strong> 或 RWKV-6 7B nf4</td>
<td class="px-6 py-4 text-sm">60-110 t/s</td>
<td class="px-6 py-4 text-sm font-semibold">标准部署,日常对话,文档处理</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm font-semibold text-green-600">16GB</td>
<td class="px-6 py-4 text-sm">RWKV-6/7 7B int8 或 14B nf4</td>
<td class="px-6 py-4 text-sm">40-80 t/s</td>
<td class="px-6 py-4 text-sm">高性能应用,长文本,代码生成</td>
</tr>
<tr>
<td class="px-6 py-4 text-sm font-semibold text-purple-600">24GB+</td>
<td class="px-6 py-4 text-sm">RWKV-6/7 14B <strong>fp16/int8</strong></td>
<td class="px-6 py-4 text-sm">30-60 t/s</td>
<td class="px-6 py-4 text-sm">服务器部署,质量优先,研究用途</td>
</tr>
<tr class="bg-yellow-50">
<td class="px-6 py-4 text-sm font-semibold text-yellow-600">推理专用</td>
<td class="px-6 py-4 text-sm font-semibold">RWKV-7-G1系列</td>
<td class="px-6 py-4 text-sm">依配置</td>
<td class="px-6 py-4 text-sm">数学推理,代码生成,多步思考</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">部署工具与教程</h3>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h4 class="font-semibold text-primary mb-4 flex items-center">
<i class="fas fa-cog text-green-600 mr-2"></i>
web-rwkv引擎(推荐方案)
</h4>
<div class="text-sm text-secondary mb-4">
<strong>环境依赖:</strong>Rust工具链(cargo)、Vulkan驱动,无需CUDA Toolkit或PyTorch
</div>
<div class="bg-gray-100 rounded p-4 mb-4">
<div class="text-xs font-mono text-gray-700 mb-2"># 安装命令</div>
<code class="text-xs">
git clone https://github.com/cryscan/web-rwkv<br/>
cd web-rwkv && cargo build --release
</code>
</div>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded">
支持策略:"cuda fp16"(全精度)、"cuda int8"(推荐平衡)、"cuda nf4"(极致效率)
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<h4 class="font-semibold text-primary mb-4 flex items-center">
<i class="fas fa-terminal text-blue-600 mr-2"></i>
llama.cpp生态
</h4>
<div class="text-sm text-secondary mb-4">
<strong>优势:</strong>生态成熟,格式丰富,工具链统一,跨平台支持
</div>
<div class="bg-gray-100 rounded p-4 mb-4">
<div class="text-xs font-mono text-gray-700 mb-2"># 转换与量化</div>
<code class="text-xs">
python convert-rwkv-to-gguf.py --input model.pth<br/>
./quantize model.gguf model-Q8_0.gguf Q8_0
</code>
</div>
<div class="text-xs text-blue-700 bg-blue-100 p-2 rounded">
支持多种GGUF格式,从Q4_0到Q8_0不等
</div>
</div>
</div>
<div class="mt-8 bg-blue-50 rounded-lg p-6 border border-blue-200">
<h4 class="font-semibold text-blue-800 mb-4">其他部署方案</h4>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
<div>
<strong class="text-blue-800">RWKV pip</strong>
<br/>
<span class="text-blue-700">pip install rwkv,适合快速原型</span>
</div>
<div>
<strong class="text-blue-800">Ai00 Server</strong>
<br/>
<span class="text-blue-700">开箱即用API服务器,无PyTorch依赖</span>
</div>
<div>
<strong class="text-blue-800">云端Docker</strong>
<br/>
<span class="text-blue-700">容器化web-rwkv服务,配合FastAPI或Triton</span>
</div>
</div>
</div>
</div>
</section>
<!-- Advantages and Future -->
<section id="advantages" class="mb-20">
<h2 class="font-display text-4xl font-bold text-primary mb-12">竞争优势与发展展望</h2>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">核心差异化优势</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8 mb-12">
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-balance-scale text-green-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">效率与性能平衡</h4>
</div>
<p class="text-sm text-secondary mb-4">
重新定义效率与性能的权衡边界,在线性复杂度下仍可实现competitive的模型质量。
</p>
<div class="text-xs text-green-700 bg-green-100 p-2 rounded">
为AI能力的普惠化提供技术基础
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-desktop text-blue-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">硬件友好性</h4>
</div>
<p class="text-sm text-secondary mb-4">
消费级GPU上的卓越推理效率,RTX 4060 Ti即可流畅运行7B级别模型。
</p>
<div class="text-xs text-blue-700 bg-blue-100 p-2 rounded">
使高质量语言模型真正accessible到普通用户
</div>
</div>
<div class="bg-white rounded-lg p-6 shadow-sm border border-base-300">
<div class="flex items-center mb-4">
<i class="fas fa-code text-purple-600 text-2xl mr-3"></i>
<h4 class="font-semibold text-primary">架构简洁性</h4>
</div>
<p class="text-sm text-secondary mb-4">
无KV-Cache设计大幅简化推理引擎实现,核心代码可数百行内完成。
</p>
<div class="text-xs text-purple-700 bg-purple-100 p-2 rounded">
便于审计、定制和移植到新型硬件
</div>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">当前局限性与挑战</h3>
<div class="bg-red-50 rounded-lg p-8 border border-red-200 mb-8">
<h4 class="font-semibold text-red-800 mb-6">主要挑战领域</h4>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-white rounded-lg p-4 border border-red-100">
<h5 class="font-semibold text-red-700 mb-2">生态系统成熟度</h5>
<p class="text-sm text-red-600 mb-3">
微调模型、应用案例、社区规模落后于Llama/Mistral
</p>
<div class="text-xs text-red-500">
缓解:持续开源,社区建设
</div>
</div>
<div class="bg-white rounded-lg p-4 border border-red-100">
<h5 class="font-semibold text-red-700 mb-2">工具链完善度</h5>
<p class="text-sm text-red-600 mb-3">
RLHF微调、多模态扩展、企业级工具待完善
</p>
<div class="text-xs text-red-500">
缓解:重点投入,生态合作
</div>
</div>
<div class="bg-white rounded-lg p-4 border border-red-100">
<h5 class="font-semibold text-red-700 mb-2">基准测试透明度</h5>
<p class="text-sm text-red-600 mb-3">
缺乏系统的MMLU/HellaSwag/GSM8K公开报告
</p>
<div class="text-xs text-red-500">
缓解:第三方评估,学术合作
</div>
</div>
</div>
</div>
</div>
<div class="mb-16">
<h3 class="font-display text-2xl font-semibold text-primary mb-8">技术演进方向</h3>
<div class="space-y-8">
<div class="bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg p-8 border border-blue-200">
<h4 class="font-semibold text-primary mb-4 flex items-center">
<i class="fas fa-rocket text-blue-600 mr-3"></i>
RWKV-7及后续版本
</h4>
<p class="text-secondary mb-4">
动态状态演化机制为复杂推理、规划、工具使用奠定基础,能力边界持续拓展。
</p>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
<div class="bg-white rounded p-3">
<strong class="text-blue-700">广义Delta规则</strong>
<br/>
<span class="text-blue-600">突破TC⁰复杂度限制</span>
</div>
<div class="bg-white rounded p-3">
<strong class="text-blue-700">动态状态演化</strong>
<br/>
<span class="text-blue-600">输入依赖的状态更新</span>
</div>
</div>
</div>
<div class="bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg p-8 border border-green-200">
<h4 class="font-semibold text-primary mb-4 flex items-center">
<i class="fas fa-eye text-green-600 mr-3"></i>
多模态扩展
</h4>
<p class="text-secondary mb-4">
VisualRWKV等视觉-语言融合方向,将架构优势延伸至跨模态场景。
</p>
<div class="bg-white rounded p-4">
<div class="text-sm text-green-700">
<strong>核心思路:</strong>将线性复杂度优势从文本扩展到图像、音频等多模态数据处理
</div>
</div>
</div>
<div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-lg p-8 border border-purple-200">
<h4 class="font-semibold text-primary mb-4 flex items-center">
<i class="fas fa-brain text-purple-600 mr-3"></i>
推理能力强化
</h4>
<p class="text-secondary mb-4">
GooseOne等专用版本的迭代,针对数学、代码、科学推理等任务深度优化。
</p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
<div class="bg-white rounded p-3 text-center">
<div class="text-purple-700 font-semibold">数学推理</div>
<div class="text-purple-600">符号计算、定理证明</div>
</div>
<div class="bg-white rounded p-3 text-center">
<div class="text-purple-700 font-semibold">代码生成</div>
<div class="text-purple-600">结构化编程、调试</div>
</div>
<div class="bg-white rounded p-3 text-center">
<div class="text-purple-700 font-semibold">科学推理</div>
<div class="text-purple-600">实验设计、数据分析</div>
</div>
</div>
</div>
</div>
</div>
<div class="bg-gradient-to-r from-slate-50 to-gray-50 rounded-2xl p-8 border border-slate-200">
<h3 class="font-display text-2xl font-semibold text-primary mb-6 text-center">长期愿景</h3>
<div class="text-center mb-6">
<p class="text-lg text-secondary mb-4">
RWKV的长期愿景是成为<strong class="text-primary">高效AI的默认选择</strong>
</p>
<div class="text-sm text-secondary">
当应用场景对效率敏感时,开发者首先考虑RWKV架构
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="text-center">
<div class="bg-blue-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
<i class="fas fa-cogs text-blue-600 text-xl"></i>
</div>
<div class="font-semibold text-primary mb-2">技术创新</div>
<div class="text-sm text-secondary">持续架构优化,能力边界拓展</div>
</div>
<div class="text-center">
<div class="bg-green-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
<i class="fas fa-users text-green-600 text-xl"></i>
</div>
<div class="font-semibold text-primary mb-2">生态建设</div>
<div class="text-sm text-secondary">工具链完善,社区规模扩大</div>
</div>
<div class="text-center">
<div class="bg-purple-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
<i class="fas fa-seedling text-purple-600 text-xl"></i>
</div>
<div class="font-semibold text-primary mb-2">社区培育</div>
<div class="text-sm text-secondary">开发者支持,应用场景丰富</div>
</div>
</div>
</div>
</section>
</div>
<!-- Footer -->
<footer class="bg-primary text-white py-12">
<div class="max-w-6xl mx-auto px-8">
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<div>
<h4 class="font-display text-xl font-semibold mb-4">RWKV资源</h4>
<ul class="space-y-2 text-sm text-gray-300">
<li>
<a href="https://github.com/BlinkDL/RWKV-LM" class="hover:text-white transition-colors">GitHub仓库</a>
</li>
<li>
<a href="https://wiki.rwkv.com" class="hover:text-white transition-colors">技术文档</a>
</li>
<li>
<a href="https://blog.rwkv.com" class="hover:text-white transition-colors">官方博客</a>
</li>
<li>
<a href="https://www.rwkv.cn" class="hover:text-white transition-colors">中文社区</a>
</li>
</ul>
</div>
<div>
<h4 class="font-display text-xl font-semibold mb-4">性能数据参考</h4>
<ul class="space-y-2 text-sm text-gray-300">
<li>
<a href="https://wiki.rwkv.com/basic/rwkv-performance-data.html" class="hover:text-white transition-colors">性能基准测试</a>
</li>
<li>
<a href="https://wiki.rwkv.com/basic/how-to-play.html" class="hover:text-white transition-colors">部署指南</a>
</li>
<li>
<a href="https://blog.rwkv.com/p/eaglex-v2-soaring-past-llama2-7b" class="hover:text-white transition-colors">EagleX v2评估</a>
</li>
</ul>
</div>
<div>
<h4 class="font-display text-xl font-semibold mb-4">研究参考</h4>
<ul class="space-y-2 text-sm text-gray-300">
<li>
<a href="https://deepfa.ir/en/blog/rwkv-architecture-rnn-transformer-hybrid" class="hover:text-white transition-colors">架构深度解析</a>
</li>
<li>
<a href="https://www.techradar.com/pro/100x-less-compute-with-gpt-level-llm-performance" class="hover:text-white transition-colors">TechRadar报道</a>
</li>
<li>
<a href="https://wiki.rwkv.com/basic/architecture.html" class="hover:text-white transition-colors">架构演进</a>
</li>
</ul>
</div>
</div>
<div class="border-t border-gray-700 mt-8 pt-8 text-center text-sm text-gray-400">
<p>本报告基于截至2026年1月的公开信息整理,所有数据来源均已标注引用链接。</p>
</div>
</div>
</footer>
<script>
// Mermaid configuration
mermaid.initialize({
startOnLoad: true,
theme: 'base',
themeVariables: {
primaryColor: '#e3f2fd',
primaryTextColor: '#1e293b',
primaryBorderColor: '#475569',
lineColor: '#64748b',
secondaryColor: '#f8fafc',
tertiaryColor: '#f1f5f9',
background: '#ffffff',
mainBkg: '#ffffff',
secondBkg: '#f8fafc',
tertiaryBkg: '#f1f5f9',
nodeBorder: '#475569',
clusterBkg: '#f8fafc',
defaultLinkColor: '#64748b',
titleColor: '#1e293b',
edgeLabelBackground: 'rgba(255, 255, 255, 0.9)',
nodeTextColor: '#1e293b',
// Enhanced contrast colors
cScale0: '#e3f2fd',
cScale1: '#f3e5f5',
cScale2: '#e8f5e8',
cScale3: '#fff3e0',
cScale4: '#fce4ec',
cScale5: '#f1f8e9',
cScale6: '#e0f2f1',
cScale7: '#fbe9e7'
},
flowchart: {
useMaxWidth: true,
htmlLabels: true,
curve: 'basis',
padding: 20
},
fontSize: 13,
fontFamily: 'Inter, system-ui, sans-serif'
});
// Initialize Mermaid Controls for zoom and pan
function initializeMermaidControls() {
const containers = document.querySelectorAll('.mermaid-container');
containers.forEach(container => {
const mermaidElement = container.querySelector('.mermaid');
let scale = 1;
let isDragging = false;
let startX, startY, translateX = 0, translateY = 0;
// 触摸相关状态
let isTouch = false;
let touchStartTime = 0;
let initialDistance = 0;
let initialScale = 1;
let isPinching = false;
// Zoom controls
const zoomInBtn = container.querySelector('.zoom-in');
const zoomOutBtn = container.querySelector('.zoom-out');
const resetBtn = container.querySelector('.reset-zoom');
const fullscreenBtn = container.querySelector('.fullscreen');
function updateTransform() {
mermaidElement.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scale})`;
if (scale > 1) {
container.classList.add('zoomed');
} else {
container.classList.remove('zoomed');
}
mermaidElement.style.cursor = isDragging ? 'grabbing' : 'grab';
}
if (zoomInBtn) {
zoomInBtn.addEventListener('click', () => {
scale = Math.min(scale * 1.25, 4);
updateTransform();
});
}
if (zoomOutBtn) {
zoomOutBtn.addEventListener('click', () => {
scale = Math.max(scale / 1.25, 0.3);
if (scale <= 1) {
translateX = 0;
translateY = 0;
}
updateTransform();
});
}
if (resetBtn) {
resetBtn.addEventListener('click', () => {
scale = 1;
translateX = 0;
translateY = 0;
updateTransform();
});
}
if (fullscreenBtn) {
fullscreenBtn.addEventListener('click', () => {
if (container.requestFullscreen) {
container.requestFullscreen();
} else if (container.webkitRequestFullscreen) {
container.webkitRequestFullscreen();
} else if (container.msRequestFullscreen) {
container.msRequestFullscreen();
}
});
}
// Mouse Events
mermaidElement.addEventListener('mousedown', (e) => {
if (isTouch) return; // 如果是触摸设备,忽略鼠标事件
isDragging = true;
startX = e.clientX - translateX;
startY = e.clientY - translateY;
mermaidElement.style.cursor = 'grabbing';
updateTransform();
e.preventDefault();
});
document.addEventListener('mousemove', (e) => {
if (isDragging && !isTouch) {
translateX = e.clientX - startX;
translateY = e.clientY - startY;
updateTransform();
}
});
document.addEventListener('mouseup', () => {
if (isDragging && !isTouch) {
isDragging = false;
mermaidElement.style.cursor = 'grab';
updateTransform();
}
});
document.addEventListener('mouseleave', () => {
if (isDragging && !isTouch) {
isDragging = false;
mermaidElement.style.cursor = 'grab';
updateTransform();
}
});
// 获取两点之间的距离
function getTouchDistance(touch1, touch2) {
return Math.hypot(
touch2.clientX - touch1.clientX,
touch2.clientY - touch1.clientY
);
}
// Touch Events - 触摸事件处理
mermaidElement.addEventListener('touchstart', (e) => {
isTouch = true;
touchStartTime = Date.now();
if (e.touches.length === 1) {
// 单指拖动
isPinching = false;
isDragging = true;
const touch = e.touches[0];
startX = touch.clientX - translateX;
startY = touch.clientY - translateY;
} else if (e.touches.length === 2) {
// 双指缩放
isPinching = true;
isDragging = false;
const touch1 = e.touches[0];
const touch2 = e.touches[1];
initialDistance = getTouchDistance(touch1, touch2);
initialScale = scale;
}
e.preventDefault();
}, { passive: false });
mermaidElement.addEventListener('touchmove', (e) => {
if (e.touches.length === 1 && isDragging && !isPinching) {
// 单指拖动
const touch = e.touches[0];
translateX = touch.clientX - startX;
translateY = touch.clientY - startY;
updateTransform();
} else if (e.touches.length === 2 && isPinching) {
// 双指缩放
const touch1 = e.touches[0];
const touch2 = e.touches[1];
const currentDistance = getTouchDistance(touch1, touch2);
if (initialDistance > 0) {
const newScale = Math.min(Math.max(
initialScale * (currentDistance / initialDistance),
0.3
), 4);
scale = newScale;
updateTransform();
}
}
e.preventDefault();
}, { passive: false });
mermaidElement.addEventListener('touchend', (e) => {
// 重置状态
if (e.touches.length === 0) {
isDragging = false;
isPinching = false;
initialDistance = 0;
// 延迟重置isTouch,避免鼠标事件立即触发
setTimeout(() => {
isTouch = false;
}, 100);
} else if (e.touches.length === 1 && isPinching) {
// 从双指变为单指,切换为拖动模式
isPinching = false;
isDragging = true;
const touch = e.touches[0];
startX = touch.clientX - translateX;
startY = touch.clientY - translateY;
}
updateTransform();
});
mermaidElement.addEventListener('touchcancel', (e) => {
isDragging = false;
isPinching = false;
initialDistance = 0;
setTimeout(() => {
isTouch = false;
}, 100);
updateTransform();
});
// Enhanced wheel zoom with better center point handling
container.addEventListener('wheel', (e) => {
e.preventDefault();
const rect = container.getBoundingClientRect();
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const delta = e.deltaY > 0 ? 0.9 : 1.1;
const newScale = Math.min(Math.max(scale * delta, 0.3), 4);
// Adjust translation to zoom towards center
if (newScale !== scale) {
const scaleDiff = newScale / scale;
translateX = translateX * scaleDiff;
translateY = translateY * scaleDiff;
scale = newScale;
if (scale <= 1) {
translateX = 0;
translateY = 0;
}
updateTransform();
}
});
// Initialize display
updateTransform();
});
}
// Initialize mermaid controls after page loads
document.addEventListener('DOMContentLoaded', function() {
initializeMermaidControls();
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Highlight active section in TOC
const sections = document.querySelectorAll('section[id]');
const tocLinks = document.querySelectorAll('#toc a[href^="#"]');
function highlightTOC() {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
if (scrollY >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
tocLinks.forEach(link => {
link.classList.remove('bg-blue-100', 'text-blue-800', 'font-semibold');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('bg-blue-100', 'text-blue-800', 'font-semibold');
}
});
}
window.addEventListener('scroll', highlightTOC);
// Mobile TOC toggle
const mobileToggle = document.getElementById('mobile-toc-toggle');
const toc = document.getElementById('toc');
const tocBackdrop = document.getElementById('toc-backdrop');
const tocClose = document.getElementById('toc-toggle');
function openToc() {
toc.classList.remove('-translate-x-full');
tocBackdrop.classList.remove('hidden');
document.body.classList.add('overflow-hidden');
}
function closeToc() {
toc.classList.add('-translate-x-full');
tocBackdrop.classList.add('hidden');
document.body.classList.remove('overflow-hidden');
}
mobileToggle.addEventListener('click', openToc);
tocClose.addEventListener('click', closeToc);
tocBackdrop.addEventListener('click', closeToc);
// Close TOC when clicking on links
tocLinks.forEach(link => {
link.addEventListener('click', closeToc);
});
// Reset TOC on window resize
window.addEventListener('resize', () => {
if (window.innerWidth >= 1024) {
closeToc();
}
});
</script>
</body></html>
登录后可参与表态