| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| |
| |
| |
| |
|
|
| echo "==========================================" |
| echo "SpecRoute Setup for Kaggle/Colab" |
| echo "==========================================" |
|
|
| |
| if [[ -d /kaggle/working ]]; then |
| ENV_TYPE="kaggle" |
| elif [[ -d /content ]]; then |
| ENV_TYPE="colab" |
| else |
| ENV_TYPE="local" |
| fi |
|
|
| echo "[Env] Detected: ${ENV_TYPE}" |
|
|
| |
| USE_CONDA="${USE_CONDA:-0}" |
| if command -v conda >/dev/null 2>&1 && [[ "${USE_CONDA}" == "1" ]]; then |
| echo "[Setup] Using conda environment (USE_CONDA=1)" |
| CONDA_ENV_NAME="specroute" |
| conda env remove -n "${CONDA_ENV_NAME}" -y >/dev/null 2>&1 || true |
| conda create -n "${CONDA_ENV_NAME}" python=3.10 -y |
| PY_CMD="conda run -n ${CONDA_ENV_NAME} python" |
| PIP_CMD="conda run -n ${CONDA_ENV_NAME} python -m pip" |
| ACTIVATE_CMD="conda activate ${CONDA_ENV_NAME}" |
| else |
| echo "[Setup] Using current Python environment" |
| PY_CMD="python" |
| PIP_CMD="python -m pip" |
| fi |
|
|
| |
| ${PIP_CMD} install --upgrade pip setuptools wheel |
|
|
| echo "" |
| echo "[Remove] Uninstalling conflicting packages..." |
| |
| |
| |
| ${PIP_CMD} uninstall -y \ |
| torch torchvision torchaudio pytorch-cuda triton \ |
| cupy cupy-cuda12x flash-attn xformers bitsandbytes \ |
| transformers tokenizers datasets accelerate peft \ |
| sentence-transformers torchtune deepspeed apex \ |
| cudf-cu12 dask-cudf-cu12 cuml-cu12 cucim-cu12 \ |
| ydf grain umap-learn hdbscan textblob \ |
| opentelemetry-proto grpcio-status \ |
| protobuf \ |
| jax jaxlib \ |
| torchmetrics easyocr pytorch-lightning fastai \ |
| gymnax kaggle-environments dopamine-rl \ |
| flax optax orbax-checkpoint chex \ |
| nx-cugraph-cu12 pylibcugraph-cu12 \ |
| opencv-contrib-python opencv-python opencv-python-headless \ |
| shap rasterio tobler cesium pytensor \ |
| tensorflow-decision-forests \ |
| a2a-sdk bigframes google-adk gcsfs \ |
| 2>/dev/null || true |
|
|
| echo "" |
| echo "[Install] Core CUDA stack (PyTorch cu121)..." |
| |
| |
| |
| |
| |
| |
| ${PIP_CMD} install --no-cache-dir -q \ |
| "numpy==1.26.4" "protobuf==5.29.3" 2>&1 | grep -v "which is not installed\|which is incompatible\|dependency resolver" || true |
| ${PIP_CMD} install --no-cache-dir -q \ |
| torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 \ |
| --index-url https://download.pytorch.org/whl/cu121 2>&1 | grep -v "which is not installed\|which is incompatible\|dependency resolver" || true |
|
|
| |
| TORCH_VER=$(${PY_CMD} -c "import torch; print(torch.__version__)" 2>/dev/null || echo "NONE") |
| echo "[Check] torch version after install: ${TORCH_VER}" |
| if [[ "${TORCH_VER}" != 2.5.1* ]]; then |
| echo "[WARN] torch ${TORCH_VER} != 2.5.1 β forcing pip uninstall+reinstall..." |
| ${PIP_CMD} uninstall -y torch torchvision torchaudio 2>/dev/null || true |
| ${PIP_CMD} install --no-cache-dir -q --no-deps \ |
| torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 \ |
| --index-url https://download.pytorch.org/whl/cu121 |
| TORCH_VER=$(${PY_CMD} -c "import torch; print(torch.__version__)" 2>/dev/null || echo "NONE") |
| echo "[Check] torch version after force: ${TORCH_VER}" |
| if [[ "${TORCH_VER}" != 2.5.1* ]]; then |
| echo "[ERROR] Cannot install torch 2.5.1. Aborting." |
| exit 1 |
| fi |
| fi |
|
|
| echo "[Install] Project dependencies..." |
| ${PIP_CMD} install --no-cache-dir -q \ |
| "numpy==1.26.4" "scipy==1.14.1" \ |
| transformers==4.40.2 tokenizers==0.19.1 \ |
| "datasets==2.21.0" accelerate==0.34.2 \ |
| loralib==0.1.2 sentencepiece==0.2.0 ipdb==0.13.13 \ |
| nltk==3.9.1 scikit-learn==1.6.1 pandas==2.2.2 \ |
| "pyarrow==17.0.0" "protobuf==5.29.3" tqdm==4.67.1 \ |
| "fsspec==2024.6.1" pynvml==11.5.3 \ |
| 2>&1 | grep -v "which is not installed\|which is incompatible\|dependency resolver" || true |
|
|
| echo "[Install] CuPy (with fallback for Python/CUDA compatibility)..." |
| if ! ${PIP_CMD} install --no-cache-dir -q cupy-cuda12x==13.6.0; then |
| ${PIP_CMD} install --no-cache-dir -q 'cupy-cuda12x>=13.0,<15.0' |
| fi |
|
|
| echo "[Cache] Clearing stale HuggingFace dataset module cache..." |
| rm -rf ~/.cache/huggingface/modules/datasets_modules/ 2>/dev/null || true |
| echo "[Cache] HF dataset module cache cleared" |
|
|
| echo "[Symlink] Creating config directory aliases..." |
| |
| if [ -d configs/gen_script_long_order3_t5_configs ] && [ ! -e configs/Long_Sequence ]; then |
| ln -s gen_script_long_order3_t5_configs configs/Long_Sequence |
| echo " Created symlink: configs/Long_Sequence -> gen_script_long_order3_t5_configs" |
| fi |
| if [ -d configs/gen_script_superni_order1_t5_configs ] && [ ! -e configs/SuperNI ]; then |
| ln -s gen_script_superni_order1_t5_configs configs/SuperNI |
| echo " Created symlink: configs/SuperNI -> gen_script_superni_order1_t5_configs" |
| fi |
| echo "[Cache] HF dataset module cache cleared" |
|
|
| echo "" |
| echo "[Check] Verifying installation..." |
| ${PY_CMD} - <<'PY' |
| import sys |
| try: |
| import torch |
| import transformers |
| import datasets |
| import cupy |
| print(f'β python {sys.version.split()[0]}') |
| print(f'β torch {torch.__version__}') |
| print(f'β cuda available: {torch.cuda.is_available()}') |
| if torch.cuda.is_available(): |
| print(f'β gpu count: {torch.cuda.device_count()}') |
| for i in range(torch.cuda.device_count()): |
| print(f' - GPU {i}: {torch.cuda.get_device_name(i)} ({torch.cuda.get_device_properties(i).total_memory / 1e9:.1f} GB)') |
| print(f'β transformers {transformers.__version__}') |
| print(f'β datasets {datasets.__version__}') |
| print(f'β cupy {cupy.__version__}') |
| print('\n[Success] All packages installed correctly!') |
| except Exception as e: |
| print(f'[Error] {e}', file=sys.stderr) |
| sys.exit(1) |
| PY |
|
|
| echo "" |
| echo "==========================================" |
| if [[ -n "${ACTIVATE_CMD:-}" ]]; then |
| echo "[Ready] Run: ${ACTIVATE_CMD}" |
| else |
| echo "[Ready] Environment is ready to use" |
| fi |
| echo "==========================================" |
|
|