Natural Memory NM2.1: 记忆路由器分叉、数据集缺陷修复与全轴评测证据

- 引入 MemoryRouterXL 与 v5/v6 流式多线程训练/编码管线
- 修复 prepare_memory_router_dataset 候选池重建缺陷(mega 家族 3568x 加速,输出逐字节相同)
- 修复 v5 被破坏的拒答与多跳标签(train 未知样本 319 -> 16319,multi_hop 平均正例 1.00 -> 2.00)
- 同存储预算下 V2-128 v6 逐轴 22/22 通过:Top-1 41.12% -> 94.62%,未知拒答 0.00% -> 100.00%
- 记录三条被实测推翻的显然优化(logits_to_keep=1 反而慢 55%、XL 容量未带来收益)
- 记忆手术跨架构可移植性 14/14,读写关闭时与原生模型逐位相同
This commit is contained in:
WpyQwq
2026-09-19 11:11:31 +08:00
commit 643e22ecb9
484 changed files with 306821 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
# Train the 128-dim routers (deployed production geometry) and score everything.
#
# Why: the 512-dim routers lost the cost axes only against the *deployed* router,
# which stores 512 bytes per record against their 2048. That is a different
# storage budget, not a better router. Training at 128 dims makes the comparison
# like-for-like: identical address size, identical ~2.0M parameter class, and the
# question becomes whether the new data/labels dominate the shipped router.
param(
[int]$Steps = 100000,
[string[]]$Configs = @('v2_128_v6', 'xl128_v6')
)
$ErrorActionPreference = 'Stop'
$Python = 'C:\Users\Administrator\miniconda3\envs\LLM\python.exe'
$ForkRoot = 'H:\Memory\V2_dpskw'
$CacheDir = 'H:\Memory\nm_cache\nm_router_v6\feature_cache'
$env:PYTHONPATH = 'H:\Memory'
Set-Location $ForkRoot
$verification = & $Python -m V2_dpskw.verify_feature_bank --cache-dir $CacheDir --no-update-manifest 2>&1 | Out-String
if ($verification -notmatch '"complete": true') {
throw "feature bank is not complete; refusing to train:`n$verification"
}
Write-Output 'feature bank: COMPLETE (verified by full scan)'
& (Join-Path $ForkRoot 'run_router_v6.ps1') -Steps $Steps -Configs $Configs
if ($LASTEXITCODE -ne 0) { throw "128-dim training failed with exit code $LASTEXITCODE" }
$old = 'H:\Memory\dynamic_memory_lab\checkpoints'
& $Python -m V2_dpskw.eval_router_v5 `
--train-file data/router_training_v6/train.jsonl `
--eval-file data/router_training_v6/eval.jsonl `
--feature-cache $CacheDir `
--run "V2-128 deployed(v3)=$old\natural_memory_v2_qwen_router_entities\memory_router_v2.pt" `
--run "V2-128 v6 best=$ForkRoot\checkpoints\router_v6_v2_128\router_best.pt" `
--run "V2-128 v6 final=$ForkRoot\checkpoints\router_v6_v2_128\memory_router_v2.pt" `
--run "XL-128 v6 best=$ForkRoot\checkpoints\router_v6_xl128\router_best.pt" `
--run "XL-128 v6 final=$ForkRoot\checkpoints\router_v6_xl128\memory_router_xl.pt" `
--run "XL-512 v6 best=$ForkRoot\checkpoints\router_v6_xl512\router_best.pt" `
--run "V2-512 v6 best=$ForkRoot\checkpoints\router_v6_v2_512\router_best.pt" `
--output router_scorecard_v6_128.json --markdown router_scorecard_v6_128.md
if ($LASTEXITCODE -ne 0) { throw "scorecard failed with exit code $LASTEXITCODE" }
& $Python -m V2_dpskw.verdict_router_v6 `
--scorecard router_scorecard_v6_128.json `
--candidate "V2-128 v6 best" --candidate "V2-128 v6 final" `
--candidate "XL-128 v6 best" --candidate "XL-128 v6 final" `
--baseline-prefix "V2-128 deployed" `
--output router_verdict_v6_128.json --markdown router_verdict_v6_128.md
Write-Output ("verdict exit code: {0} (0 = complete dominance vs the deployed router, 2 = some axis failed)" -f $LASTEXITCODE)
Write-Output ("[{0}] 128-dim train+score complete" -f (Get-Date -Format 'HH:mm:ss'))