chore: initial commit — unified project repo
Merged code repo (CompanionGuard-RL) into single project-level git. Reorganized root: docs/, reference/, experiments/, tmp/active|archives/. Gitignored: data/, checkpoints/, .venv, experiment logs, tmp/archives. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
24
code/configs/data_generation.yaml
Normal file
24
code/configs/data_generation.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
api:
|
||||
type: "qwen" # "qwen" or "openai"
|
||||
model: "qwen-max"
|
||||
|
||||
generation:
|
||||
total_samples: 3000
|
||||
safe_ratio: 0.25 # 25% safe (y_risk=0) samples
|
||||
delay: 0.5 # seconds between API calls
|
||||
max_retries: 3 # retry attempts per failed generation
|
||||
|
||||
output:
|
||||
raw_dir: "data/raw"
|
||||
output_file: "data/raw/generated.jsonl"
|
||||
|
||||
annotation:
|
||||
judge_model: "qwen-max"
|
||||
output_file: "data/processed/annotated.jsonl"
|
||||
delay: 0.3
|
||||
|
||||
split:
|
||||
train: 0.8
|
||||
val: 0.1
|
||||
test: 0.1
|
||||
seed: 42
|
||||
51
code/configs/detector_config.yaml
Normal file
51
code/configs/detector_config.yaml
Normal file
@@ -0,0 +1,51 @@
|
||||
model:
|
||||
name: "hfl/chinese-macbert-large"
|
||||
hidden_size: 1024
|
||||
num_heads: 8
|
||||
dropout: 0.1
|
||||
use_lora: false
|
||||
|
||||
data:
|
||||
train_path: "data/processed/CompanionRisk-Bench/train.jsonl"
|
||||
val_path: "data/processed/CompanionRisk-Bench/dev.jsonl"
|
||||
test_path: "data/processed/CompanionRisk-Bench/test.jsonl"
|
||||
max_persona_len: 128
|
||||
max_context_len: 512
|
||||
max_response_len: 256
|
||||
max_history_turns: 5
|
||||
num_workers: 0 # 0 for Windows (avoids multiprocessing issues); set to 4 on Linux
|
||||
|
||||
training:
|
||||
epochs: 10
|
||||
per_gpu_batch_size: 16 # single GPU: 16; 4 GPUs: use 32 (effective 128)
|
||||
gradient_accumulation_steps: 2 # effective_batch = 16 × 1 GPU × 2 = 32
|
||||
lr: 2e-5
|
||||
warmup_steps: 100
|
||||
weight_decay: 0.01
|
||||
gradient_clip: 1.0
|
||||
eval_steps: 100 # global steps between validation runs
|
||||
mixed_precision: "bf16" # RTX 5090: bf16; RTX 30xx/40xx: fp16; CPU-only: no
|
||||
seed: 42
|
||||
|
||||
loss_weights:
|
||||
binary: 1.0
|
||||
level: 1.0
|
||||
primary: 1.0
|
||||
fine: 1.0 # 下次训练建议提升到 2.0,配合 fine_training 选项
|
||||
|
||||
# Fine-grained label training options(下次训练时开启,当前 best.pt 不受影响)
|
||||
fine_training:
|
||||
use_pos_weight: false # 改为 true 开启 pos_weight(下次训练)
|
||||
risky_only: false # 改为 true 开启(下次训练)
|
||||
|
||||
evaluation:
|
||||
binary_threshold: 0.5
|
||||
fine_threshold: 0.4
|
||||
|
||||
logging:
|
||||
project: "CompanionGuard-RL"
|
||||
run_name: "detector-macbert-v1"
|
||||
use_wandb: false # set true if wandb is configured
|
||||
|
||||
output:
|
||||
checkpoint_dir: "checkpoints/detector"
|
||||
54
code/configs/detector_config_server.yaml
Normal file
54
code/configs/detector_config_server.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
model:
|
||||
name: "/root/siton-data-740d234e02d749f08fe5347b0c74c49f/zsy/macbert-large"
|
||||
hidden_size: 1024
|
||||
num_heads: 8
|
||||
dropout: 0.1
|
||||
use_lora: false
|
||||
|
||||
data:
|
||||
train_path: "data/processed/CompanionRisk-Bench/train.jsonl"
|
||||
val_path: "data/processed/CompanionRisk-Bench/dev.jsonl"
|
||||
test_path: "data/processed/CompanionRisk-Bench/test.jsonl"
|
||||
max_persona_len: 128
|
||||
max_context_len: 512
|
||||
max_response_len: 256
|
||||
max_history_turns: 5
|
||||
num_workers: 4 # Linux server: 4 workers; Windows: use 0
|
||||
|
||||
training:
|
||||
epochs: 10
|
||||
per_gpu_batch_size: 16 # 4 GPUs × 16 × accum 2 = effective batch 128
|
||||
gradient_accumulation_steps: 2
|
||||
lr: 2e-5
|
||||
warmup_steps: 100
|
||||
weight_decay: 0.01
|
||||
gradient_clip: 1.0
|
||||
eval_steps: 100 # global steps between validation runs
|
||||
mixed_precision: "bf16" # RTX 5090 native bf16
|
||||
seed: 42
|
||||
|
||||
loss_weights:
|
||||
binary: 1.0
|
||||
level: 1.0
|
||||
primary: 1.0
|
||||
fine: 2.0 # ↑ 2.0: 加强细粒度标签损失权重(配合 fine_training 开启)
|
||||
|
||||
# Fine-grained label training options(下次训练时开启,当前 best.pt 不受影响)
|
||||
# 两项均开启可显著改善 fine_macro_f1:
|
||||
# use_pos_weight: 对 Romanticization/CoRumination 等稀有标签设置 ~25 倍正样本权重
|
||||
# risky_only: 只在 y_risk=1 的样本上计算 fine loss,避免 safe 样本教模型预测全负
|
||||
fine_training:
|
||||
use_pos_weight: true # ✓ 开启:对稀有 fine 标签设置 pos_weight(max 30)
|
||||
risky_only: true # ✓ 开启:只在 y_risk=1 样本上计算 fine loss
|
||||
|
||||
evaluation:
|
||||
binary_threshold: 0.5
|
||||
fine_threshold: 0.4
|
||||
|
||||
logging:
|
||||
project: "CompanionGuard-RL"
|
||||
run_name: "detector-macbert-4gpu"
|
||||
use_wandb: false
|
||||
|
||||
output:
|
||||
checkpoint_dir: "checkpoints/detector"
|
||||
49
code/configs/intervention_config.yaml
Normal file
49
code/configs/intervention_config.yaml
Normal file
@@ -0,0 +1,49 @@
|
||||
detector:
|
||||
checkpoint: "checkpoints/detector/best.pt"
|
||||
# Server 2 path — update this when running on server 2
|
||||
model_name: "/root/siton-data-740d234e02d749f08fe5347b0c74c49f/zsy/macbert-large"
|
||||
hidden_size: 1024
|
||||
|
||||
agent:
|
||||
state_hidden: 256
|
||||
dropout: 0.1
|
||||
|
||||
# Stage 1: Behavior cloning warm-up
|
||||
behavior_cloning:
|
||||
enabled: true
|
||||
epochs: 5
|
||||
per_gpu_batch_size: 256
|
||||
lr: 0.001
|
||||
mixed_precision: "bf16"
|
||||
|
||||
# Stage 2: PPO runs on GPU-0 only
|
||||
ppo:
|
||||
total_timesteps: 200000
|
||||
n_rollout_steps: 2048
|
||||
n_epochs: 4
|
||||
batch_size: 256
|
||||
lr: 0.0003
|
||||
clip_eps: 0.2
|
||||
entropy_coef: 0.01
|
||||
value_coef: 0.5
|
||||
max_grad_norm: 0.5
|
||||
gamma: 0.99
|
||||
gae_lambda: 0.95
|
||||
|
||||
environment:
|
||||
max_turns: 20
|
||||
|
||||
evaluation:
|
||||
binary_threshold: 0.5
|
||||
|
||||
preprocessing:
|
||||
per_gpu_batch_size: 64
|
||||
|
||||
logging:
|
||||
project: "CompanionGuard-RL"
|
||||
run_name: "intervention-v5-1gpu"
|
||||
use_wandb: false
|
||||
|
||||
output:
|
||||
checkpoint_dir: "checkpoints/intervention"
|
||||
save_interval: 10000
|
||||
Reference in New Issue
Block a user