File size: 3,731 Bytes
db7bc06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 * 天玄一键启用所有模块脚本
 * 
 * 用法:
 *   node scripts/start-all.js              # 从头训练
 *   node scripts/start-all.js --resume=path # 从 checkpoint 续训
 *   node scripts/start-all.js --test        # 仅测试生成
 */

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const args = process.argv.slice(2);
const resumeArg = args.find(a => a.startsWith('--resume='));
const resumeDir = resumeArg ? resumeArg.split('=')[1] : null;
const testOnly = args.includes('--test');

console.log(`
╔═══════════════════════════════════════════════════════════╗
║           天玄 TianXuan - 一键启用所有模块                ║
╠═══════════════════════════════════════════════════════════╣
║  多神经协同 | MoE | Titans | STDP | STDA | 重放          ║
╚═══════════════════════════════════════════════════════════╝
`);

// 1. 编译
console.log('📦 编译中...');
try {
  execSync('npm run build', { stdio: 'inherit' });
  console.log('✅ 编译成功\n');
} catch (e) {
  console.error('❌ 编译失败');
  process.exit(1);
}

// 2. 检查数据
const rawDir = 'data/raw';
if (fs.existsSync(rawDir)) {
  const files = fs.readdirSync(rawDir).filter(f => f.endsWith('.txt'));
  let totalBytes = 0;
  for (const f of files) {
    totalBytes += fs.statSync(path.join(rawDir, f)).size;
  }
  console.log(`📊 训练数据: ${files.length} 个文件, ${totalBytes.toLocaleString()} 字节\n`);
}

// 3. 训练或测试
if (testOnly) {
  console.log('🧪 测试模式: 仅生成示例');
  const checkpoint = resumeDir || 'sandbox/ck-prod-3ep';
  if (!fs.existsSync(checkpoint)) {
    console.error(`❌ Checkpoint not found: ${checkpoint}`);
    process.exit(1);
  }
  try {
    execSync(`node sandbox/dist/ml/generate.js --checkpoint=${checkpoint} --prompt=小明 --len=30 --temp=0.3 --topk=5`, { stdio: 'inherit' });
  } catch (e) {
    console.error('❌ 生成失败');
  }
} else {
  const checkpoint = resumeDir || 'sandbox/ck-prod-3ep';
  const resumeFlag = resumeDir ? `--resume=${checkpoint}` : '';
  
  console.log(`🚀 开始训练${resumeDir ? ' (续训)' : ' (新训练)'}...`);
  console.log(`   Checkpoint: ${checkpoint}`);
  console.log(`   预计时间: ~30 分钟 (CPU)\n`);
  
  try {
    execSync(`npm run train -- --epochs=10 --realcorpus=1 --realTokens=1000000 --out=${checkpoint} --ckpt=100 ${resumeFlag}`, { 
      stdio: 'inherit',
      timeout: 3600000 // 60分钟超时
    });
    console.log('\n✅ 训练完成!');
  } catch (e) {
    console.log('\n⚠️ 训练超时或中断,但 checkpoint 已保存');
  }
  
  // 4. 验证
  console.log('\n🔍 验证在线学习机制...');
  try {
    execSync(`node sandbox/dist/ml/verify-online-learning.js ${checkpoint}`, { stdio: 'inherit' });
  } catch (e) {
    console.error('❌ 验证失败');
  }
  
  // 5. 生成测试
  console.log('\n📝 生成质量测试...');
  try {
    execSync(`node sandbox/dist/ml/generate.js --checkpoint=${checkpoint} --prompt=小明 --len=50 --temp=0.3 --topk=5`, { stdio: 'inherit' });
  } catch (e) {
    console.error('❌ 生成测试失败');
  }
}

console.log('\n✨ 完成!');
const finalCheckpoint = resumeDir || 'sandbox/ck-prod-3ep';
console.log(`\n📁 Checkpoint: ${finalCheckpoint}`);
console.log('📊 报告: docs/FINAL-REPORT.md');