#!/usr/bin/env bash set -euo pipefail DEPS_MARKER="/workspace/.f13-deps-installed" WHEEL_DIR="/workspace/.f13-wheels" HF_WHEEL_REPO="f13rnd/custom-wheels" hf_download() { hf download "$@" ${HF_TOKEN:+--token "${HF_TOKEN}"} } hf_upload() { hf upload "$@" ${HF_TOKEN:+--token "${HF_TOKEN}"} } install_from_hf_or_build() { local pkg_name="$1" pip_spec="$2" local glob="${pkg_name}-*.whl" mkdir -p "${WHEEL_DIR}" local whl whl=$(ls "${WHEEL_DIR}"/${glob} 2>/dev/null | head -1) if [ -n "${whl}" ]; then echo "[slim] Installing ${pkg_name} from cached wheel" pip install --no-cache-dir "${whl}" && return 0 fi echo "[slim] Trying to download ${pkg_name} wheel from HF..." hf_download "${HF_WHEEL_REPO}" \ --repo-type dataset \ --include "${glob}" \ --local-dir "${WHEEL_DIR}" 2>/dev/null || true whl=$(ls "${WHEEL_DIR}"/${glob} 2>/dev/null | head -1) if [ -n "${whl}" ]; then echo "[slim] Installing ${pkg_name} from HF wheel" pip install --no-cache-dir "${whl}" && return 0 fi echo "[slim] No prebuilt wheel found — building ${pkg_name} from source..." TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST:-9.0}" \ MAX_JOBS="${MAX_JOBS:-2}" \ NVCC_THREADS="${NVCC_THREADS:-1}" \ pip wheel ${pip_spec} --no-build-isolation --no-deps --wheel-dir "${WHEEL_DIR}" whl=$(ls "${WHEEL_DIR}"/${glob} 2>/dev/null | head -1) pip install --no-cache-dir "${whl}" echo "[slim] Uploading ${pkg_name} wheel to HF for future use..." hf_upload "${HF_WHEEL_REPO}" \ "${whl}" "$(basename "${whl}")" \ --repo-type dataset 2>/dev/null \ || echo "[slim] WARN: failed to upload ${pkg_name} wheel to HF (non-fatal)" } if [ -f "${DEPS_MARKER}" ]; then echo "[slim] Deps already installed" else echo "[slim] Installing training deps (first boot)..." pip install --no-cache-dir \ "ms-swift>=4.0.2" \ accelerate \ deepspeed \ "qwen_vl_utils>=0.0.14" \ decord \ torchvision \ fastapi \ "uvicorn[standard]" \ python-multipart \ wandb \ huggingface_hub pip install --no-cache-dir "transformers>=5.3.0,<5.4.0" pip install --no-cache-dir --no-deps "datasets>=4.7.0" install_from_hf_or_build "flash_attn" "flash-attn" \ || echo "[slim] WARN: flash-attn install failed" install_from_hf_or_build "causal_conv1d" "causal-conv1d" \ || echo "[slim] WARN: causal-conv1d install failed" pip install --no-cache-dir \ "flash-linear-attention @ git+https://github.com/fla-org/flash-linear-attention" \ || echo "[slim] WARN: flash-linear-attention install failed" pip install --no-cache-dir "dlrover[torch]" || true touch "${DEPS_MARKER}" echo "[slim] Deps installed" fi exec /opt/f13/scripts/entrypoint.sh "$@"