diff --git a/trainer_web/start_web_ui.sh b/trainer_web/start_web_ui.sh new file mode 100755 index 0000000..9279e4a --- /dev/null +++ b/trainer_web/start_web_ui.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# 获取脚本所在目录 +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +cd "$SCRIPT_DIR" + +# 检查是否已经有实例在运行 +if [ -f "train_web_ui.pid" ]; then + pid=$(cat "train_web_ui.pid") + if ps -p "$pid" > /dev/null 2>&1; then + echo "Web UI 服务已经在运行 (PID: $pid)" + exit 1 + else + echo "删除旧的PID文件" + rm "train_web_ui.pid" + fi +fi + +# 创建日志目录 +LOG_DIR="../logfile" +mkdir -p "$LOG_DIR" + +# 生成时间戳 +TIMESTAMP=$(date +"%Y%m%d_%H%M%S") +LOG_FILE="$LOG_DIR/web_ui_$TIMESTAMP.log" + +echo "启动 MiniMind Web UI 服务..." +echo "日志文件: $LOG_FILE" + +# 使用nohup启动服务 +nohup python -u train_web_ui.py > "$LOG_FILE" 2>&1 & + +# 保存PID +echo $! > "train_web_ui.pid" + +sleep 2 + +echo "服务已启动! PID: $(cat "train_web_ui.pid")" +echo "访问地址: http://localhost:5000" +echo "停止命令: kill $(cat "train_web_ui.pid") or ./trainer_web/stop_web_ui.sh" \ No newline at end of file diff --git a/scripts/static/css/style.css b/trainer_web/static/css/style.css similarity index 100% rename from scripts/static/css/style.css rename to trainer_web/static/css/style.css diff --git a/scripts/static/images/logo2.png b/trainer_web/static/images/logo2.png similarity index 100% rename from scripts/static/images/logo2.png rename to trainer_web/static/images/logo2.png diff --git a/scripts/static/js/script.js b/trainer_web/static/js/script.js similarity index 96% rename from scripts/static/js/script.js rename to trainer_web/static/js/script.js index 287f7c0..6cfcf54 100644 --- a/scripts/static/js/script.js +++ b/trainer_web/static/js/script.js @@ -32,12 +32,19 @@ function openTab(evt, tabName) { document.getElementById('train_type').addEventListener('change', function() { const trainType = this.value; const pretrainSftFields = document.querySelectorAll('.pretrain-sft'); + const fromWeightFields = document.querySelectorAll('.from-weight'); const loraFields = document.querySelectorAll('.lora'); const dpoFields = document.querySelectorAll('.dpo'); const dpoParamCard = document.querySelector('.parameter-card.dpo'); + const ppoFields = document.querySelectorAll('.ppo'); + const ppoParamCard = document.querySelector('.parameter-card.ppo'); pretrainSftFields.forEach(field => { - field.style.display = (trainType === 'pretrain' || trainType === 'sft') ? 'block' : 'none'; + field.style.display = (trainType === 'pretrain' || trainType === 'sft' || trainType === 'dpo' || trainType === 'ppo') ? 'block' : 'none'; + }); + + fromWeightFields.forEach(field => { + field.style.display = (trainType !== 'ppo') ? 'block' : 'none'; }); loraFields.forEach(field => { @@ -48,10 +55,18 @@ document.getElementById('train_type').addEventListener('change', function() { field.style.display = trainType === 'dpo' ? 'block' : 'none'; }); + ppoFields.forEach(field => { + field.style.display = trainType === 'ppo' ? 'block' : 'none'; + }); + if (dpoParamCard) { dpoParamCard.style.display = trainType === 'dpo' ? 'block' : 'none'; } + if (ppoParamCard) { + ppoParamCard.style.display = trainType === 'ppo' ? 'block' : 'none'; + } + // 设置默认值 if (trainType === 'pretrain') { document.getElementById('save_dir').value = '../out'; @@ -114,6 +129,27 @@ document.getElementById('train_type').addEventListener('change', function() { document.getElementById('num_hidden_layers').value = '8'; document.getElementById('max_seq_len').value = '1024'; document.getElementById('use_moe').value = '0'; + } else if (trainType === 'ppo') { + document.getElementById('save_dir').value = '../out'; + document.getElementById('save_weight').value = 'ppo_actor'; + document.getElementById('epochs').value = '1'; + document.getElementById('batch_size').value = '2'; + document.getElementById('learning_rate').value = '8e-8'; + document.getElementById('data_path').value = '../dataset/rlaif-mini.jsonl'; + document.getElementById('log_interval').value = '1'; + document.getElementById('save_interval').value = '10'; + // PPO特有参数默认值 + document.getElementById('clip_epsilon').value = '0.1'; + document.getElementById('vf_coef').value = '0.5'; + document.getElementById('kl_coef').value = '0.02'; + document.getElementById('reasoning').value = '1'; + document.getElementById('update_old_actor_freq').value = '4'; + document.getElementById('reward_model_path').value = '../../internlm2-1_8b-reward'; + // 模型结构参数默认值 + document.getElementById('hidden_size').value = '512'; + document.getElementById('num_hidden_layers').value = '8'; + document.getElementById('max_seq_len').value = '66'; + document.getElementById('use_moe').value = '0'; } }); diff --git a/trainer_web/stop_web_ui.sh b/trainer_web/stop_web_ui.sh new file mode 100755 index 0000000..df01186 --- /dev/null +++ b/trainer_web/stop_web_ui.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") +cd "$SCRIPT_DIR" + +if [ -f "train_web_ui.pid" ]; then + pid=$(cat "train_web_ui.pid") + if ps -p "$pid" > /dev/null 2>&1; then + echo "正在停止 Web UI 服务 (PID: $pid)" + kill "$pid" + sleep 2 + # 检查是否成功停止 + if ps -p "$pid" > /dev/null 2>&1; then + echo "强制停止服务..." + kill -9 "$pid" + fi + echo "服务已停止" + else + echo "服务未运行,但存在PID文件,已删除" + rm "train_web_ui.pid" + fi +else + echo "服务未运行(未找到PID文件)" +fi \ No newline at end of file diff --git a/scripts/templates/index.html b/trainer_web/templates/index.html similarity index 84% rename from scripts/templates/index.html rename to trainer_web/templates/index.html index a49c4de..2da4064 100644 --- a/scripts/templates/index.html +++ b/trainer_web/templates/index.html @@ -33,6 +33,7 @@ +
@@ -60,7 +61,7 @@