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
+78
View File
@@ -0,0 +1,78 @@
param(
[int]$Steps = 100000,
[int]$EvalInterval = 500,
[int]$CheckpointInterval = 5000,
[int]$GpuMemoryGb = 9
)
$ErrorActionPreference = 'Stop'
$Python = 'C:\Users\Administrator\miniconda3\envs\LLM\python.exe'
$WorkDir = 'H:\Memory'
$OutputDir = 'H:\Memory\V2_dpskw\checkpoints\natural_memory_v2_router_512'
$FeatureCacheDir = 'H:\Memory\V2_dpskw\checkpoints\natural_memory_v2_router_v3\feature_cache'
$TrainFile = 'V2_dpskw/data/router_training_v3/train.jsonl'
$EvalFile = 'V2_dpskw/data/router_training_v3/eval.jsonl'
if (-not (Test-Path -LiteralPath $Python)) {
throw "Python executable not found: $Python"
}
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir $TrainFile))) {
throw "Training file not found: $TrainFile"
}
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir $EvalFile))) {
throw "Evaluation file not found: $EvalFile"
}
if (-not (Test-Path -LiteralPath $FeatureCacheDir)) {
throw "Feature cache not found: $FeatureCacheDir"
}
if ($Steps -lt 1) { throw 'Steps must be positive.' }
if ($EvalInterval -ne 500) { throw 'This production protocol requires EvalInterval=500.' }
if ($CheckpointInterval -lt 1) { throw 'CheckpointInterval must be positive.' }
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
$existing = Get-CimInstance Win32_Process | Where-Object {
$_.Name -eq 'python.exe' -and
$_.CommandLine -match 'train_memory_router_large' -and
$_.CommandLine -match 'natural_memory_v2_router_512'
}
if ($existing) {
throw "A 512d router training process is already running: $($existing.ProcessId -join ', ')"
}
$stdout = Join-Path $OutputDir 'training_stdout.log'
$stderr = Join-Path $OutputDir 'training_stderr.log'
$argumentLine = @(
'-m V2_dpskw.train_memory_router_large',
'--train-file V2_dpskw/data/router_training_v3/train.jsonl',
'--eval-file V2_dpskw/data/router_training_v3/eval.jsonl',
'--model-path V2_dpskw/qwen3_5_4b_natural_memory_v2',
'--output-dir V2_dpskw/checkpoints/natural_memory_v2_router_512',
'--feature-cache-dir V2_dpskw/checkpoints/natural_memory_v2_router_v3/feature_cache',
'--router-dim 512',
'--num-heads 8',
'--max-hops 3',
'--gpu-memory-gb ' + $GpuMemoryGb,
'--encode-batch-size 1',
'--steps ' + $Steps,
'--batch-size 64',
'--eval-batch-size 128',
'--eval-interval ' + $EvalInterval,
'--checkpoint-interval ' + $CheckpointInterval
) -join ' '
$process = Start-Process -FilePath $Python -WorkingDirectory $WorkDir `
-ArgumentList $argumentLine -RedirectStandardOutput $stdout `
-RedirectStandardError $stderr -WindowStyle Hidden -PassThru
[pscustomobject]@{
pid = $process.Id
router_dim = 512
router_parameters = 4741902
steps = $Steps
eval_interval = $EvalInterval
checkpoint_interval = $CheckpointInterval
output_dir = $OutputDir
feature_cache = $FeatureCacheDir
} | ConvertTo-Json -Compress