192.168.31.31 —— RTX 5060 Ti 16GB VRAM + 64GB RAM(内存 2026-10-16 到货)+ SATA SSD--yes(交给 setup 自动推荐),没有显式指定。到底该开多少?<14GB → 32K、14–20GB → 64K、>20GB → 128K。setup.py:6237:
small = min(x["vram_gb"] for x in chosen) # 本机 = 16
rec_ctx = 32768 if small < 14 else 65536 if small < 20 else 131072
if budget is not None: # 仅 Unsloth UD-Q4_K_XL 那条线
rec_ctx = 8192 if small < 14 else 32768
rec_ctx = min(rec_ctx, ram_ctx(model, ram, low_ram)) # 再受内存规则约束
CONTEXTS):8K / 32K / 64K / 128K / 200K / 256K / 384K / 512Krec_ctx = 65536(64K)为什么不能按显存拉满 —— setup 自己的提示原话:
"Longer needs more VRAM for it, so fewer experts fit on the GPU"
KV 缓存与专家缓存抢同一块显存。上下文越长 → VRAM 里能缓存的专家越少 → CPU 承担的计算越多 → 解码越慢。
引擎 0.1.5 起:从 64K 开始,setup 把 KV 缓存放进内存,显存只保留 --kv-resident 32768(32K 常读窗口),省下来的显存全给专家缓存。
官方实测(DETAILS.md):
Q2_0 at 262K: 50.9 → 62.6 tokens/s(显存内专家 1,589 → 3,872);128K 时约 +6%
注意关键是:attention 读的数值完全一样,只是 KV 的存放位置变了。
kv_streaming_wanted):
ctx >= 65536 and ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1--kv-streaming on|off;WSL 下永不 streaming--kv-resident N推论:只要内存够,上下文拉长后速度可能反而变快。
kv_streaming_ram_gb 的换算基准:8-bit ≈ 13.7 KB/token、K8V4 ≈ 10.6 KB/token、4-bit ≈ 7.5 KB/token(12 个 QSA 层 + draft 层)。
| 上下文 | int8(默认) | K8V4(省 23%) | q4_0(省约一半) |
|---|---|---|---|
| 64K | ~0.9 GB | ~0.7 GB | ~0.5 GB |
| 128K | 1.7 GB | 1.3 GB | 1.0 GB |
| 256K | ~3.6 GB | ~2.8 GB | ~2.0 GB |
| 格式 | 收益 | 代价 | 建议 |
|---|---|---|---|
int8(默认) | 基准 | — | ✅ 默认就用它 |
k8v4 | KV 内存省 23%,长文档表现优于 4-bit;3090 上 Coder @198K:99 vs 85 tok/s | 预填慢 2–5% | ✅ 想给专家缓存多腾显存时值得开 |
q4_0 | KV 内存减半,128K 下快约 4% | 长文档困惑度 +8~12%(needle 仍过) | ❌ 不划算,不建议 |
模型内存需求(setup.py 的 MODELS 表):
| 档位 | download_gb | ram_gb | arena_gb(专家) |
|---|---|---|---|
| Q2_0 | 66.4 | 48 | 34.0 |
| IQ2_XS | 68.0 | 48 | 35.5 |
| IQ3_XXS | 75.8 | 60 | 42.9 |
| IQ3_S | 83.6 | 62 | 50.3 |
| Coder IQ1_M | 58.4 | 32 | 23.4 |
按 streaming 判定式 ram_gb + KV(256K) + 1 ≤ 64:
| 档位 | 256K 判定 | 结论 |
|---|---|---|
| Q2_0 | 48 + 3.6 + 1 = 52.6 ≤ 64 ✓ | ✅ 可拉满 256K |
| IQ2_XS | 48 + 3.6 + 1 = 52.6 ≤ 64 ✓ | ✅ 可拉满 256K |
| IQ3_XXS | 60 + 3.6 + 1 = 64.6 > 64 ✗ | ⚠️ 建议 128K |
| IQ3_S | 62 + 3.6 + 1 = 66.6 > 64 ✗ | ❌ 官方只推荐到 128K |
官方对 IQ3_XXS/IQ3_S @262K 的原话:
"IQ3_XXS and IQ3_S at 262K are not measured: with their 43 / 50 GB of experts, a 260K-token context brings a 64 GB PC to its memory limit by setup's estimate (the experts + the context's KV cache + 24 GB), so setup recommends up to 128K"
(注:社区有用户在 64GB 上把 IQ3_S 跑到 256K 且内存有余 —— issue #406。所以 128K 是「官方保守推荐」,不是硬上限。)
→ 这就是「选 IQ2_XS」的第三个理由:它是 64GB 机器上能跑满 256K 原生窗口的档位之一。
不要只信文档转述 —— 原生上下文长度写在模型文件自己的元数据里。从 ModelScope 取 IQ2_XS 分片 1 的前 64MB 解析 GGUF 头部得到:
qwen4exp.context_length = 262144 ← 原生窗口
qwen4exp.rope.freq_base = 10000000.0 ← 1e7,与训练一致
qwen4exp.embedding_length = 2560
qwen4exp.attention.head_count = 24
qwen4exp.attention.head_count_kv = 2 ← GQA 12:1
qwen4exp.attention.key_length = 256
qwen4exp.attention.value_length = 256
qwen4exp.full_attention_interval = 4 ← 48 层里 12 层全注意力
qwen4exp.attention.indexer.head_count = 4 ← Qwen 稀疏注意力(QSA)索引器
qwen4exp.attention.indexer.key_length = 128
qwen4exp.attention.indexer.top_k = 2048
qwen4exp.attention.compress_ratios = <array 48> ← 逐层 KV 压缩比
qwen4exp.embedding_length_per_layer_input = 160 ← PLE
「256K」与「262K」是同一个数的两种口径:262144 ÷ 1024 = 256(二进制,STRATA 菜单显示「256K tokens」);262144 ÷ 1000 ≈ 262.1(十进制,STRATA 文档写「262K」)。
12 个全注意力层 × 2 个 KV head × (256 K维 + 256 V维) × 1 byte(8-bit)
= 12 × 2 × 512 = 12,288 B ≈ 12.3 KB/token
+ draft 层 → ≈ 13.7 KB/token
与 docs/DETAILS.md 写的 "~13.7 KB of RAM per context token (8-bit)" 完全一致,也印证了 full_attention_interval = 4 对应文档所说「12 QSA layers」。
| 上下文 | 状态 |
|---|---|
| ≤ 262,144 | 原生:用训练时的 rope base 1e7,无额外处理 |
| 393,216 / 524,288 | 超出训练范围,必须开 rope scaling(实验性 yarn/linear),RAM 检查可能降回 |
--rope-scaling linear|yarn,实验性,默认关)none建议:不要为了「更大数字」上 384K/512K。 262K 是原生窗口,质量与速度都最稳。
说法属实,但对本机不可行。 分三层看:
docs/DETAILS.md:
长文档问答在 yarn 2 @ 421K 和 yarn 4 @ 714K 上成功(各 8/8),并且 "a 1M-token
yarn4 run read end to end"
另有贡献者的独立测量用 --max-context 1048576(yarn factor 4)。源码 resolve_rope 会自动按 最终上下文 ÷ 262144 推导 factor(1M → 4),且超过 262144 时拒绝 --rope-scaling none(不会静默给出超范围配置)。
官方原文强调「the numbers come from one machine and one quant」,且关键限制:
"Needle tests do not tell the arms apart: the unscaled model also finds a needle at 413K."
即「长上下文找得到针」无法证明扩展有效。真正的质量证据只有 293K 处 yarn 2 把 NLL 降 0.18 nats(噪声的 3–4 倍);714K / 1M 只有「读通了」的容量证据,零质量数据。
KV 开销:~13.7 KB/token(8-bit)、~10.6 KB(K8V4);另有 rope 表 ~0.26 KB/token。 streaming 触发条件:ram ≥ 模型RAM + KV + 1GB(IQ2_XS 的 ram_gb = 48)。
| 上下文 | KV (k8v4) | 所需总内存 | 64GB 下 |
|---|---|---|---|
| 262144(原生) | 2.8 GB | 51.8 | ✅ 宽裕 |
| 524288(512K) | 5.6 GB | 54.6 | ✅ 可行 |
| 1048576(1M) | 11.1 GB | 60.1 | ⚠️ 临界 |
| 1048576(8-bit KV) | 14.4 GB | 63.4 | ❌ 超出 |
1M 的两条死路:
结论:16GB VRAM + 64GB RAM 的天花板是 512K,不是 1M。
512K 恰好落在证据最扎实的点位:YaRN factor = 524288/262144 = 2,而 factor 2 正是唯一有正向量化质量证据的设置(293K 下 NLL −0.18 nats;421K 长文档 8/8)。1M 需要 factor 4,只有容量证据。
升级命令(无需重新下载模型):
./setup.sh --setup --context 524288 --yes # 自动带 yarn factor 2
建议路径:先按 262144 原生跑通 → 内存到齐后实测 → 再决定是否升 512K。
max_tokens 会越过上下文,同样报 400 —— 除非在 strata-<model>.json 加 "fit_max_tokens": true,它会自动把输出收到剩余空间。跑 Agent 建议加这一项。cd ~/Strata
./setup.sh --setup --source modelscope --model IQ2_XS \
--context 262144 --kv k8v4 \
--low-ram off --no-start --yes \
--experimental-speed-projection on \
--port 8090 --host 0.0.0.0 --api-key <KEY>
内存到货后:
./setup.sh --setup --yes # 按 64GB 实测重新校准,然后启动
保守替代方案:先 --context 131072 --kv int8 跑稳,日后再用 --setup 升到 256K —— 模型文件已装,改上下文不需要重新下载。
strata-iq2_xs.json)| 键 | 值 | 用途 |
|---|---|---|
"fit_max_tokens": true | — | 输出自动收到剩余上下文,避免 400 |
"reasoning_close_retry": true | — | 修「思考完不输出正文」的已知问题(#1053) |
"reasoning_effort" | "low"/"medium"/"high"/"xhigh" | 思考档位 |
"reasoning_budget_tokens" | 数字 | 限制思考长度(否则可能想几万 token) |
"expert_profile_save" | "expert-profile-learned.bin" | 学习型专家画像,跨重启保留热点专家 |
setup.py:CONTEXTS(381)、ctx_ram_need(4224)、ram_ctx(4233)、kv_streaming_ram_gb(4056)、kv_streaming_wanted(4062)、主路径 rec_ctx(6237)、MODELS 表(243)docs/DETAILS.md:KV streaming / 4-bit KV / K8V4 三节(78–95)、上下文行为(909)、rope scaling 与上下文扩展(1402–1424)、IQ3 在 262K 的限制(72–75)