Download monet_code/script_examples/sft_no_text.sh from RuoliuYang/monet-qwen3vl-code: direct link, hf CLI and curl.
- Browser
- Download file 4.05 kB
-
https://huggingface.co/datasets/RuoliuYang/monet-qwen3vl-code/resolve/main/monet_code/script_examples/sft_no_text.sh
- Command line
-
hf download hf://datasets/RuoliuYang/monet-qwen3vl-code/monet_code/script_examples/sft_no_text.sh
-
curl -L -o sft_no_text.sh https://huggingface.co/datasets/RuoliuYang/monet-qwen3vl-code/resolve/main/monet_code/script_examples/sft_no_text.sh
4.05 kB
| set -euo pipefail | |
| if command -v conda >/dev/null 2>&1; then | |
| CONDA_BASE=$(conda info --base 2>/dev/null || true) | |
| if [ -n "${CONDA_BASE}" ] && [ -f "${CONDA_BASE}/etc/profile.d/conda.sh" ]; then | |
| source "${CONDA_BASE}/etc/profile.d/conda.sh" | |
| if conda env list | awk '{print $1}' | grep -qx "monet"; then | |
| conda activate monet | |
| fi | |
| fi | |
| fi | |
| REPO_DIR=${REPO_DIR:-/raid/yrl/Monet} | |
| cd "${REPO_DIR}" | |
| DATA_ROOT=${DATA_ROOT:-/raid/yrl/dataset_v1_60k/full_no_tool_paper_strict_v1} | |
| TRAIN_JSON=${TRAIN_JSON:-/raid/yrl/dataset_v1_60k/full_no_tool_paper_strict_v1/no_text/train.jsonl} | |
| BASE_MODEL=${BASE_MODEL:-/raid/yrl/hf_models/Qwen2.5-VL-7B-Instruct} | |
| CKPT_ROOT=${CKPT_ROOT:-/raid/yrl/Monet_no_text_ckpts} | |
| TORCHRUN=${TORCHRUN:-/raid/yrl/.envs/lvr/bin/torchrun} | |
| CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-0,1,2,3,4,5,6,7} | |
| NPROC=${NPROC:-8} | |
| LATENT_SIZE=8 | |
| TOTAL_SAMPLES=${TOTAL_SAMPLES:-53106} | |
| WAIT_SECONDS=${WAIT_SECONDS:-300} | |
| export CUDA_VISIBLE_DEVICES | |
| count_teacher_reps() { | |
| find "${CKPT_ROOT}/teacher_reps_pooled" -maxdepth 1 -type f -name 'rep_*.pt' 2>/dev/null | wc -l | |
| } | |
| wait_for_existing_teacher_reps_job() { | |
| while pgrep -f "src.precompute_teacher_reps.*${CKPT_ROOT}/teacher_reps_pooled" >/dev/null; do | |
| cur=$(count_teacher_reps) | |
| echo "[wait] existing teacher reps job running: ${cur}/${TOTAL_SAMPLES}" | |
| sleep "${WAIT_SECONDS}" | |
| done | |
| } | |
| mkdir -p "${CKPT_ROOT}" | |
| wait_for_existing_teacher_reps_job | |
| # Step 1: precompute pooled aux-image teacher representations from the base model. | |
| mkdir -p "${CKPT_ROOT}/teacher_reps_pooled" | |
| if [ "$(count_teacher_reps)" -lt "${TOTAL_SAMPLES}" ]; then | |
| "${TORCHRUN}" --nproc-per-node=${NPROC} -m src.precompute_teacher_reps \ | |
| --bsz 1 \ | |
| --data_path ${TRAIN_JSON} \ | |
| --load_model_path ${BASE_MODEL} \ | |
| --save_model_path ${CKPT_ROOT}/teacher_reps_pooled \ | |
| --dataset_root ${DATA_ROOT} \ | |
| --latent_size ${LATENT_SIZE} \ | |
| --output_hidden_states \ | |
| --alignment_layer all_layers \ | |
| --allow_no_observation \ | |
| --resume | |
| fi | |
| # Step 2: SFT Stage 2 trains the latent body from the base model. | |
| CE_EMPHASIZE_FACTOR=4.0 | |
| ALIGNMENT_WEIGHT=2.0 | |
| EMPHASIZE_LATENT_WEIGHT=2.0 | |
| SAVE=stage2_notext_latent${LATENT_SIZE}_ce${CE_EMPHASIZE_FACTOR}_al${ALIGNMENT_WEIGHT}_emph${EMPHASIZE_LATENT_WEIGHT} | |
| "${TORCHRUN}" --nproc-per-node=${NPROC} -m src.main \ | |
| --epochs 2 --bsz 1 --grad_accum_steps 16 \ | |
| --stage sft_stage2 \ | |
| --data_path ${TRAIN_JSON} \ | |
| --load_model_path ${BASE_MODEL} \ | |
| --save_model_path ${CKPT_ROOT}/${SAVE} \ | |
| --dataset_root ${DATA_ROOT} \ | |
| --deepspeed ./deepspeed/ds_zero2_gpu.json \ | |
| --latent_size ${LATENT_SIZE} \ | |
| --alignment_weight ${ALIGNMENT_WEIGHT} \ | |
| --emphasize_latent_weight ${EMPHASIZE_LATENT_WEIGHT} \ | |
| --ce_emphasize_factor ${CE_EMPHASIZE_FACTOR} \ | |
| --teacher_reps_dir ${CKPT_ROOT}/teacher_reps_pooled \ | |
| --alignment_layer all_layers \ | |
| --allow_no_observation | |
| # Step 3: dump Stage 2 teacher latents. | |
| STAGE2=${CKPT_ROOT}/${SAVE} | |
| "${TORCHRUN}" --nproc-per-node=${NPROC} -m src.precompute_teacher_latents \ | |
| --bsz 1 \ | |
| --data_path ${TRAIN_JSON} \ | |
| --load_model_path ${STAGE2} \ | |
| --save_model_path ${CKPT_ROOT}/teacher_latents \ | |
| --dataset_root ${DATA_ROOT} \ | |
| --latent_size ${LATENT_SIZE} \ | |
| --output_hidden_states \ | |
| --allow_no_observation \ | |
| --resume | |
| # Step 4: SFT Stage 3 distills no-aux-image student latents from the base model. | |
| CE_EMPHASIZE_FACTOR=4.0 | |
| ALIGNMENT_WEIGHT=2.0 | |
| SAVE=stage3_notext_latent${LATENT_SIZE}_ce${CE_EMPHASIZE_FACTOR}_al${ALIGNMENT_WEIGHT} | |
| "${TORCHRUN}" --nproc-per-node=${NPROC} -m src.main \ | |
| --epochs 2 --bsz 1 --grad_accum_steps 16 \ | |
| --stage sft_stage3 \ | |
| --data_path ${TRAIN_JSON} \ | |
| --load_model_path ${BASE_MODEL} \ | |
| --save_model_path ${CKPT_ROOT}/${SAVE} \ | |
| --dataset_root ${DATA_ROOT} \ | |
| --deepspeed ./deepspeed/ds_zero2_gpu.json \ | |
| --latent_size ${LATENT_SIZE} \ | |
| --alignment_weight ${ALIGNMENT_WEIGHT} \ | |
| --ce_emphasize_factor ${CE_EMPHASIZE_FACTOR} \ | |
| --teacher_latent_dir ${CKPT_ROOT}/teacher_latents \ | |
| --alignment_layer all_layers \ | |
| --allow_no_observation | |