|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2026 FlagOS Contributors |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Provision models on the host-mounted /data volume. Images must not contain |
| 17 | +# model weights; every platform test refers to the same host path convention. |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +export FL_MODEL_BASE_PATH="${FL_MODEL_BASE_PATH:-/data/models}" |
| 21 | +export HF_ENDPOINT="${HF_ENDPOINT:-https://hf-mirror.com}" |
| 22 | + |
| 23 | +QWEN_ROOT="${FL_MODEL_BASE_PATH}/Qwen" |
| 24 | +HF_MODEL_ID="Qwen/Qwen3-0.6B" |
| 25 | +MODELSCOPE_MODEL_IDS=( |
| 26 | + "Qwen/Qwen3.6-27B" |
| 27 | + "Qwen/Qwen3.6-35B-A3B" |
| 28 | +) |
| 29 | + |
| 30 | +mkdir -p "${QWEN_ROOT}" |
| 31 | + |
| 32 | +MODEL_DIR="${QWEN_ROOT}/${HF_MODEL_ID#Qwen/}" |
| 33 | +if [[ -f "${MODEL_DIR}/config.json" ]]; then |
| 34 | + echo "Model already available: ${MODEL_DIR}" |
| 35 | +else |
| 36 | + export MODEL_ID="${HF_MODEL_ID}" MODEL_DIR |
| 37 | + echo "Downloading ${MODEL_ID} from ${HF_ENDPOINT} to ${MODEL_DIR}" |
| 38 | + python - <<'PY' |
| 39 | +import os |
| 40 | +
|
| 41 | +from huggingface_hub import snapshot_download |
| 42 | +
|
| 43 | +
|
| 44 | +snapshot_download( |
| 45 | + repo_id=os.environ["MODEL_ID"], |
| 46 | + local_dir=os.environ["MODEL_DIR"], |
| 47 | + endpoint=os.environ["HF_ENDPOINT"], |
| 48 | +) |
| 49 | +PY |
| 50 | + test -f "${MODEL_DIR}/config.json" |
| 51 | + echo "Model ready: ${MODEL_DIR}" |
| 52 | +fi |
| 53 | + |
| 54 | +if ! command -v modelscope >/dev/null 2>&1; then |
| 55 | + pip install modelscope --break-system-packages |
| 56 | +fi |
| 57 | + |
| 58 | +for MODEL_ID in "${MODELSCOPE_MODEL_IDS[@]}"; do |
| 59 | + MODEL_DIR="${QWEN_ROOT}/${MODEL_ID#Qwen/}" |
| 60 | + if [[ -f "${MODEL_DIR}/config.json" ]]; then |
| 61 | + echo "Model already available: ${MODEL_DIR}" |
| 62 | + continue |
| 63 | + fi |
| 64 | + |
| 65 | + echo "Downloading ${MODEL_ID} from ModelScope to ${MODEL_DIR}" |
| 66 | + modelscope download --model "${MODEL_ID}" --local_dir "${MODEL_DIR}" |
| 67 | + test -f "${MODEL_DIR}/config.json" |
| 68 | + echo "Model ready: ${MODEL_DIR}" |
| 69 | +done |
0 commit comments