Files
ModelHub XC 6d5fbe99d4 初始化项目,由ModelHub XC社区提供模型
Model: keepsloading/icml_repro_scratch
Source: Original Platform
2026-11-14 03:56:19 +08:00

93 lines
3.0 KiB
Bash

#!/usr/bin/env bash
set -u
echo "=== STAGE 0: Setup ==="
echo "Installing huggingface_hub..."
pip install huggingface_hub || exit 1
echo "Downloading code and weights from scratch repository..."
python -c 'from huggingface_hub import snapshot_download; snapshot_download(repo_id="keepsloading/icml_repro_scratch", repo_type="model", local_dir="/workspace")' || exit 1
echo "Installing dependencies..."
cd /workspace
pip install -r recipe/requirements.txt || exit 1
echo "Patching lm_eval dtype argument bug..."
python -c "
import lm_eval
from pathlib import Path
hf_py = Path(lm_eval.__file__).parent / 'models' / 'huggingface.py'
content = hf_py.read_text(encoding='utf-8')
if 'dtype=get_dtype(dtype),' in content:
patched = content.replace('dtype=get_dtype(dtype),', 'torch_dtype=get_dtype(dtype),')
hf_py.write_text(patched, encoding='utf-8')
print('lm_eval patched successfully!')
else:
print('lm_eval already patched or target not found.')
qa_py = Path(lm_eval.__file__).parent / 'tasks' / 'ruler' / 'qa_utils.py'
content = qa_py.read_text(encoding='utf-8')
old_url = 'http://curtis.ml.cmu.edu/datasets/hotpot/hotpot_dev_distractor_v1.json'
new_url = 'https://huggingface.co/datasets/namlh2004/hotpotqa/resolve/main/hotpot_dev_distractor_v1.json'
if old_url in content:
patched = content.replace(old_url, new_url)
qa_py.write_text(patched, encoding='utf-8')
print('qa_utils patched successfully!')
else:
print('qa_utils already patched or target not found.')
"
echo "Downloading NLTK requirements..."
python -c "import nltk; nltk.download('punkt', quiet=True); nltk.download('punkt_tab', quiet=True)"
echo "Making scripts executable..."
chmod +x /workspace/recipe/scripts/*.sh || exit 1
echo "Downloading previous outputs from Hugging Face Hub (resumability)..."
python -c '
from huggingface_hub import snapshot_download
import os
try:
snapshot_download(
repo_id="keepsloading/icml_repro_scratch",
allow_patterns="outputs/*",
local_dir="/workspace"
)
print("Previous outputs downloaded successfully!")
except Exception as e:
print("Could not download previous outputs:", e)
'
repro_status=0
echo "=== STAGE 1 & 2: SFT Training (L2A-Style) ==="
# Launch L2A-style training (Stage 1 + Stage 2 SFT)
bash recipe/scripts/train_l2a_only.sh || repro_status=$?
if [[ "$repro_status" -eq 0 ]]; then
echo "=== STAGE 3: Evaluation Sweep ==="
# Launch evaluation sweep across RULER, BabiLong, HELMET, and MRCR
bash -x recipe/scripts/eval_sweep.sh || repro_status=$?
fi
echo "=== STAGE 4: Uploading Outputs back to HF Hub ==="
python -c '
import os
from huggingface_hub import HfApi
api = HfApi()
repo_id = "keepsloading/icml_repro_scratch"
print("Uploading outputs directory back to HF Hub...")
if os.path.exists("/workspace/outputs"):
api.upload_folder(
folder_path="/workspace/outputs",
repo_id=repo_id,
repo_type="model",
path_in_repo="outputs"
)
print("Upload completed successfully!")
else:
print("Warning: outputs directory not found!")
'
exit "$repro_status"