File size: 2,382 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
# 迁移到 Linux (虚拟机重装)

## 迁移前 (旧 Windows 系统, 关机前)

从 `C:\Users\l1064\Desktop\tianxuan` 拷出 2 个目录 (总 ~102MB):

| 资产 | 位置 | 大小 |
|---|---|---|
| Transformer 检查点 (批 2310, loss≈3.9, 含 Adam 优化器状态) | `sandbox/data/checkpoints-tf/` | 66MB |
| 真实语料 (11 部古典小说, 1.873M 汉字, 续训必需) | `data/raw/` | 53MB |

其余源码/文档/脚本已在 Hugging Face (`masterofthestars/tianxuan`); 旧 GitHub `l1064709321/tianxuan` 不再作为主仓库。

## 迁移后 (VM Linux, 有网后)

```bash
# 1. 装 Node ≥ 18
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt install -y nodejs   # Debian/Ubuntu
#    或: sudo dnf install nodejs   # CentOS/RHEL

# 2. 克隆代码 (源码不靠拷贝, 走 Hugging Face 主仓库)
git clone https://huggingface.co/masterofthestars/tianxuan.git
cd tianxuan
npm install

# 3. 把拷出来的 2 个目录放进仓库
mkdir -p sandbox/data
cp -r /path/to/checkpoints-tf sandbox/data/checkpoints-tf
mkdir -p data
cp -r /path/to/raw data/raw

# 4. 编译 (outDir 必须是 sandbox/dist)
npx tsc --outDir sandbox/dist

# 5. 续训 (接断点, 2M 真实语料, 2 epochs)
node sandbox/dist/ml/train.js --resume sandbox/data/checkpoints-tf \
  --transformer 1 --nlayers 4 --nhead 4 --emb 128 --ctx 32 --bptt 32 \
  --epochs 2 --realTokens 2000000 --out sandbox/data/checkpoints-tf

# 6. 评估 (loss / top-1 / ppl)
cd sandbox && node eval-tf-now.js
```

## 训练监控

```bash
# 看最近日志
tail -f sandbox/data/checkpoints-tf/../../logs/train.log   # 或看 console 输出
# 续训中想加速: 检查点保存默认每 10 批, 可加 --ckpt 500 降低开销 (单 epoch 约 7196 批)
```

## 可选: 推 HuggingFace (VM 能通 huggingface.co 时)

```bash
export HF_TOKEN=hf_你的token          # 旧 token 已在聊天暴露, 建议先去 settings 撤销重发
export UPLOAD_DATA=1                  # 要连 data/ 大检查点一起传就设 1 (默认 0 排除)
bash scripts/upload-to-hf.sh          # 详见 docs/HF-UPLOAD.md
```

## 宪章提醒 (AGENTS.md)

- 验证/训练/生成一律在 `sandbox/`, 生产 `data/` 只读
- 续训命令带 `--out sandbox/data/checkpoints-tf`, 不要漏 (默认 outDir 是生产 `data/checkpoints`)
- 代码零外部依赖 (纯 TS 数值内核), `npm install` 只装 node_modules 基础包