Cnass commited on
Commit
ec89792
·
verified ·
1 Parent(s): 8fcf4cf

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +31 -4
entrypoint.sh CHANGED
@@ -3,9 +3,13 @@ set -euo pipefail
3
 
4
  MODEL_PATH="${MODEL_DIR}/${MODEL_FILE}"
5
 
 
 
6
  if [ ! -f "$MODEL_PATH" ]; then
7
  echo "[entrypoint] Downloading ${MODEL_FILE} from ${MODEL_REPO} ..."
8
- python -c "
 
 
9
  from huggingface_hub import hf_hub_download
10
  hf_hub_download(repo_id='${MODEL_REPO}', filename='${MODEL_FILE}', local_dir='${MODEL_DIR}')
11
  "
@@ -13,22 +17,45 @@ else
13
  echo "[entrypoint] Found cached model at ${MODEL_PATH}"
14
  fi
15
 
16
- echo "[entrypoint] Starting llama-server (threads=${THREADS}, parallel=${PARALLEL_SLOTS}, ctx=${CTX_SIZE}) ..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  /app/llama-server \
18
  --model "$MODEL_PATH" \
19
  --host "${LLAMA_SERVER_HOST}" \
20
  --port "${LLAMA_SERVER_PORT}" \
 
21
  --threads "${THREADS}" \
22
  --threads-batch "${THREADS}" \
23
  --ctx-size "${CTX_SIZE}" \
24
  --parallel "${PARALLEL_SLOTS}" \
25
  --cont-batching \
26
  --jinja \
 
27
  --no-webui &
28
  LLAMA_PID=$!
29
 
 
 
30
  echo "[entrypoint] Waiting for llama-server to become healthy ..."
31
- for _ in $(seq 1 150); do
32
  if curl -sf "http://${LLAMA_SERVER_HOST}:${LLAMA_SERVER_PORT}/health" >/dev/null 2>&1; then
33
  echo "[entrypoint] llama-server is ready."
34
  break
@@ -41,7 +68,7 @@ for _ in $(seq 1 150); do
41
  done
42
 
43
  echo "[entrypoint] Starting API gateway on port ${PORT} ..."
44
- uvicorn app.main:app --host 0.0.0.0 --port "${PORT}" &
45
  API_PID=$!
46
 
47
  wait -n "$LLAMA_PID" "$API_PID"
 
3
 
4
  MODEL_PATH="${MODEL_DIR}/${MODEL_FILE}"
5
 
6
+ # python3, not python: the CUDA base image is Ubuntu and ships no `python`
7
+ # alias. Same reason the gateway is started with `python3 -m uvicorn` below.
8
  if [ ! -f "$MODEL_PATH" ]; then
9
  echo "[entrypoint] Downloading ${MODEL_FILE} from ${MODEL_REPO} ..."
10
+ echo "[entrypoint] (several GB - enable persistent storage on the Space so"
11
+ echo "[entrypoint] this does not repeat, on GPU time, at every cold start)"
12
+ python3 -c "
13
  from huggingface_hub import hf_hub_download
14
  hf_hub_download(repo_id='${MODEL_REPO}', filename='${MODEL_FILE}', local_dir='${MODEL_DIR}')
15
  "
 
17
  echo "[entrypoint] Found cached model at ${MODEL_PATH}"
18
  fi
19
 
20
+ # Rosetta's own embedded template uses a Jinja filter llama.cpp's minja engine
21
+ # does not implement, and llama-server refuses to start rather than degrade -
22
+ # so that family gets the bundled, minja-compatible rewrite instead. Hy-MT2
23
+ # uses the template inside its GGUF.
24
+ # Same inference rule as app/config.py, so setting MODEL_REPO alone keeps the
25
+ # server flags and the prompt builder agreed on the format.
26
+ RESOLVED_FORMAT="${PROMPT_FORMAT:-}"
27
+ if [ -z "$RESOLVED_FORMAT" ]; then
28
+ case "$(echo "$MODEL_REPO" | tr '[:upper:]' '[:lower:]')" in
29
+ *rosetta*) RESOLVED_FORMAT="rosetta" ;;
30
+ *) RESOLVED_FORMAT="hy-mt2" ;;
31
+ esac
32
+ fi
33
+
34
+ TEMPLATE_ARGS=()
35
+ case "$RESOLVED_FORMAT" in
36
+ rosetta) TEMPLATE_ARGS=(--chat-template-file /app/chat-template-rosetta.jinja) ;;
37
+ esac
38
+
39
+ echo "[entrypoint] Starting llama-server (gpu-layers=${GPU_LAYERS:-all}, threads=${THREADS}, parallel=${PARALLEL_SLOTS}, ctx=${CTX_SIZE}) ..."
40
  /app/llama-server \
41
  --model "$MODEL_PATH" \
42
  --host "${LLAMA_SERVER_HOST}" \
43
  --port "${LLAMA_SERVER_PORT}" \
44
+ --gpu-layers "${GPU_LAYERS:-all}" \
45
  --threads "${THREADS}" \
46
  --threads-batch "${THREADS}" \
47
  --ctx-size "${CTX_SIZE}" \
48
  --parallel "${PARALLEL_SLOTS}" \
49
  --cont-batching \
50
  --jinja \
51
+ "${TEMPLATE_ARGS[@]}" \
52
  --no-webui &
53
  LLAMA_PID=$!
54
 
55
+ # Generous ceiling: on a T4 the first load also JIT-compiles the PTX shipped
56
+ # for sm_75, which the driver then caches.
57
  echo "[entrypoint] Waiting for llama-server to become healthy ..."
58
+ for _ in $(seq 1 300); do
59
  if curl -sf "http://${LLAMA_SERVER_HOST}:${LLAMA_SERVER_PORT}/health" >/dev/null 2>&1; then
60
  echo "[entrypoint] llama-server is ready."
61
  break
 
68
  done
69
 
70
  echo "[entrypoint] Starting API gateway on port ${PORT} ..."
71
+ python3 -m uvicorn app.main:app --host 0.0.0.0 --port "${PORT}" &
72
  API_PID=$!
73
 
74
  wait -n "$LLAMA_PID" "$API_PID"