Skip to content
Tomomom259Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

PLUG(离线最小可运行版)

本仓库目标:不扩展功能,只保证正确、完整、可离线运行。
当前流程覆盖:

  • Phase 1:CPT/LAPT
  • Phase 2:Direct SFT / PLUG-SFT
  • 从 Phase 1 checkpoint 接到 Phase 2(G3/G4)

所有模型与数据均从本地路径读取;不需要 HF 登录、wandb 登录、OpenAI API。


0. 环境与依赖(离线)

python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

依赖说明见 requirements.txt,已包含训练/评测所需最小包(Transformers + Datasets + PEFT + PyTorch)。


1. 准备本地模型与数据

1.1 本地模型目录(手动下载后放置)

示例:

  • /data/models/Qwen3.5-4B-Instruct

目录内应至少包含:config.json、tokenizer 文件、权重文件。

1.2 数据

  • Phase 1(CPT/LAPT):.txt 或 .jsonl(字段 text)
  • Phase 2 Direct SFT:JSONL,原始字段可映射到 instruction/input/output
  • Phase 2 PLUG:JSONL,原始字段可映射到 instruction_target/pivot_instruction/pivot_response/target_response

2. 数据转换(离线)

2.1 Direct SFT 转 Phase 2

python scripts/convert_direct_sft_to_phase2.py \
  --input-file /data/raw/direct_train.jsonl \
  --output-file /data/phase2/direct_sft_ug.jsonl

2.2 PLUG 转 Phase 2

python scripts/convert_plug_to_phase2.py \
  --input-file /data/raw/plug_train_ug_en.jsonl \
  --output-file /data/phase2/plug_sft_ug_en.jsonl

3. Step 1:Phase 1 CPT/LAPT

编辑 configs/cpt_qwen35_4b_ug.yaml:

  • model_name_or_path = 本地基座模型路径
  • tokenizer_name_or_path = 本地 tokenizer 路径
  • train_data = CPT 数据路径(可文件或目录)
  • output_dir = CPT 输出目录

运行:

bash scripts/run_cpt_ug.sh configs/cpt_qwen35_4b_ug.yaml

产物:<CPT_OUTPUT_DIR>(可作为 G3/G4 的 cpt_checkpoint)。


4. Step 2:G1 Direct SFT

编辑 configs/sft_direct_ug.yaml:

  • model_name_or_path / tokenizer_name_or_path = 本地模型路径
  • train_data = /data/phase2/direct_sft_ug.jsonl
  • output_dir = G1 输出目录
  • cpt_checkpoint: null

运行:

CONFIG_PATH=configs/sft_direct_ug.yaml NUM_GPUS=1 bash scripts/run_sft_direct_ug.sh

5. Step 3:G2 Direct PLUG-SFT

编辑 configs/sft_plug_ug_en.yaml(或 TR 版本):

  • model_name_or_path / tokenizer_name_or_path = 本地模型路径
  • train_data = /data/phase2/plug_sft_ug_en.jsonl
  • output_dir = G2 输出目录
  • cpt_checkpoint: null

运行:

CONFIG_PATH=configs/sft_plug_ug_en.yaml NUM_GPUS=1 bash scripts/run_sft_plug_ug_en.sh

6. Step 4:G3/G4 从 CPT checkpoint 继续

6.1 G3 = CPT -> Direct SFT

在 configs/sft_direct_ug.yaml 设置:

cpt_checkpoint: /path/to/cpt_output

然后运行:

CONFIG_PATH=configs/sft_direct_ug.yaml NUM_GPUS=1 bash scripts/run_sft_direct_ug.sh

6.2 G4 = CPT -> PLUG-SFT

在 configs/sft_plug_ug_en.yaml(或 TR)设置:

cpt_checkpoint: /path/to/cpt_output

然后运行:

CONFIG_PATH=configs/sft_plug_ug_en.yaml NUM_GPUS=1 bash scripts/run_sft_plug_ug_en.sh

7. 推理 + 提取

python src/model/inference.py \
  --model-path /path/to/sft_or_plug_output \
  --tokenizer-path /data/models/Qwen3.5-4B-Instruct \
  --input-file /data/eval.jsonl \
  --output-file /data/preds.jsonl \
  --mode plug_full \
  --offline

python src/model/extract_response_from_bilingual_output.py \
  --input-file /data/preds.jsonl \
  --output-file /data/target_only.jsonl

8. 离线约束(已落实)

  • 训练脚本默认 local_files_only: true
  • 运行脚本设置:HF_HUB_OFFLINE=1、TRANSFORMERS_OFFLINE=1、HF_DATASETS_OFFLINE=1
  • 禁用 wandb:WANDB_DISABLED=true / report_to: none
  • 无 OpenAI API、无 GPT-4 评测依赖

9. 快速自检清单

  1. 配置里的模型/数据路径都改成真实本地绝对路径。
  2. configs/eval_ug.yaml 不为空且可直接评测。
  3. 所有训练命令都指向真实存在的 Python 入口。
  4. G3/G4 的 cpt_checkpoint 指向 Step 1 输出目录。
  5. 不依赖任何联网下载。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages