File size: 2,910 Bytes
01ed052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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 "$@"