SlowGuess's picture
Upload Abforge training code snapshot
1ce6f9b verified
Raw
History Blame Contribute Delete
3.43 kB
#!/bin/bash
# Rebuild the ABForge training conda env on PERSISTENT disk from the frozen spec,
# so it survives the scratch purge. Target: py3.10 / torch2.6.0+cu124 / vllm0.8.5.post1
# / flash_attn2.8.3 / verl0.2.0.dev0 (bundled verl_proj).
#
# Usage: bash scripts/build_repro_env.sh [env_prefix]
# no `set -u` — conda gcc/gxx activate hooks reference unbound vars (CONDA_BACKUP_CXX).
set -o pipefail
CODE=/gpfs/radev/project/cohan/yz979/xucai/Abforge_Training
FROZEN=$CODE/docs/env_abforge_vllm_frozen.txt
CONDA_HOME=/gpfs/radev/pi/cohan/yz979/environment/miniconda3
ENVP=${1:-$CONDA_HOME/envs/abforge_repro}
CU_INDEX=https://download.pytorch.org/whl/cu124
FA_WHL=https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu12torch2.6cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
echo "==== building $ENVP ===="
source "$CONDA_HOME/etc/profile.d/conda.sh" 2>/dev/null || { module load miniconda; source "$(conda info --base)/etc/profile.d/conda.sh"; }
# 1) env skeleton
if [ ! -x "$ENVP/bin/python" ]; then
conda create -y -p "$ENVP" python=3.10 || exit 1
fi
conda activate "$ENVP"
python -m pip install -U pip wheel setuptools || exit 1
# 2) anchor the torch trio from the cu124 index (locks torch before vllm/xformers)
python -m pip install --index-url $CU_INDEX \
torch==2.6.0+cu124 torchvision==0.21.0 torchaudio==2.6.0 || exit 1
# 3) full frozen set minus the specials (verl from source, flash_attn separately)
REQ=$(mktemp)
grep -vE '^\s*#|^\s*$' "$FROZEN" | grep -ivE '^(verl|flash[_-]attn|torch|torchvision|torchaudio)==' > "$REQ"
python -m pip install --extra-index-url $CU_INDEX -r "$REQ" || { echo "RETRY without strict resolver"; python -m pip install --no-deps --extra-index-url $CU_INDEX -r "$REQ"; }
rm -f "$REQ"
# 4) flash-attn 2.8.3. The release wheels need glibc>=2.32 but Misha is RHEL8 (glibc 2.28),
# so they install but fail to IMPORT. Try the wheel, verify import, and build from source
# (against the node's glibc) if the import fails.
if ! python -c 'import flash_attn' 2>/dev/null; then
python -m pip install "$FA_WHL" || true
if ! python -c 'import flash_attn' 2>/dev/null; then
echo "wheel unusable (glibc); building flash-attn 2.8.3 from source (needs nvcc)"
python -m pip uninstall -y flash-attn flash_attn 2>/dev/null || true
python -m pip install -U ninja packaging
module load CUDA/12.4.1 2>/dev/null || true
export CUDA_HOME=$(dirname $(dirname $(which nvcc)))
# RHEL8 system gcc is 8.5 but PyTorch 2.6 needs gcc>=9. Install gcc/gxx 12 (<=13 for
# CUDA 12.4) into the env so compile + runtime libstdc++ are self-contained.
conda install -y -c conda-forge 'gxx_linux-64=12.*' 'gcc_linux-64=12.*'
export CC=$ENVP/bin/x86_64-conda-linux-gnu-gcc
export CXX=$ENVP/bin/x86_64-conda-linux-gnu-g++
export NVCC_PREPEND_FLAGS="-ccbin $CXX"
# FORCE_BUILD=TRUE stops setup.py from fetching the glibc-2.32 prebuilt wheel and
# actually compiles against the node's glibc. Limit archs to the cluster's GPUs.
export FLASH_ATTENTION_FORCE_BUILD=TRUE
export TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0"
MAX_JOBS=4 python -m pip install flash-attn==2.8.3 --no-build-isolation --no-cache-dir
fi
fi
# 5) bundled verl (editable, deps already satisfied above)
python -m pip install -e "$CODE/verl_proj" --no-deps || exit 1
echo "==== installed; pip check ===="
python -m pip check || true
echo "BUILD_DONE $ENVP"