从安装到训练

按下列步骤可在本仓库复现完整实验。建议先跑 analytical,再跑 genesis。

  1. 创建环境(Python 3.11)
    cd RL_Demo
    uv venv --python 3.11 .venv
    source .venv/bin/activate
    uv pip install torch --index-url https://download.pytorch.org/whl/cpu
    uv pip install -r requirements.txt
  2. 快速训练(分析动力学)
    python scripts/train.py --backend analytical --iterations 200
  3. Genesis 训练
    python scripts/train.py --backend genesis --num-envs 8 --iterations 100

    CPU 上 Genesis 较慢,可先减小 num_envs / iterations。

  4. 评估策略
    python scripts/evaluate.py --backend analytical
    python scripts/evaluate.py --backend genesis
  5. 打开本教学站
    python scripts/serve_website.py

训练循环伪代码

for iteration in range(N):
    for t in range(steps_per_env):
        a, logp, V = policy(obs)
        obs, r, done, info = env.step(a)
        buffer.store(...)
    advantages, returns = GAE(buffer)
    for epoch in range(K):
        for minibatch in buffer:
            update PPO clip loss

关键超参(见 configs/train_config.yaml)

参数默认含义
gamma0.99折扣
gae_lambda0.95GAE 平滑
clip_eps0.2PPO 裁剪
learning_rate3e-4Adam 学习率
steps_per_env128每次更新前采样长度
num_envs32并行环境