0xarchit commited on
Commit
3a9ad3f
·
1 Parent(s): 0c43530

fix flash attention

Browse files
Files changed (2) hide show
  1. README.md +3 -0
  2. start.sh +13 -3
README.md CHANGED
@@ -37,6 +37,8 @@ Optional tuning variables:
37
  - `ENABLE_TOOLS`: set to `1` to enable llama.cpp shell tool support when `LANGSEARCH_API_KEY` is present, default `0`
38
  - `HTTP_THREADS`: HTTP server worker threads, default `1` for personal single-request inference
39
  - `LOG_VERBOSITY`: llama.cpp log verbosity, default `1` to reduce runtime logging overhead
 
 
40
  - `NO_WARMUP`: set to `1` to skip model warmup and save startup time
41
  - `PORT`: listen port, default `7860`
42
 
@@ -71,6 +73,7 @@ For small 2B models on CPU-only inference (~2-4 t/s baseline), optimize these se
71
  - `CACHE_TYPE_K`, `CACHE_TYPE_V`: Try `q4_0` instead of `f16` to reduce KV cache bandwidth and memory use at longer contexts
72
  - `ENABLE_TOOLS`: Leave as `0` unless you need tool calling. Built-in shell tools add prompt/tool overhead and should not be exposed publicly.
73
  - `MODEL_FILE`: If the repo has multiple GGUFs, test a lighter quant such as `Q4_0`, `Q4_K_S`, or `Q3_K_M` for speed/quality tradeoffs.
 
74
 
75
  **Example for 2B model (CPU-only):**
76
  ```
 
37
  - `ENABLE_TOOLS`: set to `1` to enable llama.cpp shell tool support when `LANGSEARCH_API_KEY` is present, default `0`
38
  - `HTTP_THREADS`: HTTP server worker threads, default `1` for personal single-request inference
39
  - `LOG_VERBOSITY`: llama.cpp log verbosity, default `1` to reduce runtime logging overhead
40
+ - `MMAP`: set to `1` to use memory-mapped model loading, default `0`
41
+ - `FLASH_ATTN`: set to `0` to disable flash attention if a model hangs or fails during startup, default `1`
42
  - `NO_WARMUP`: set to `1` to skip model warmup and save startup time
43
  - `PORT`: listen port, default `7860`
44
 
 
73
  - `CACHE_TYPE_K`, `CACHE_TYPE_V`: Try `q4_0` instead of `f16` to reduce KV cache bandwidth and memory use at longer contexts
74
  - `ENABLE_TOOLS`: Leave as `0` unless you need tool calling. Built-in shell tools add prompt/tool overhead and should not be exposed publicly.
75
  - `MODEL_FILE`: If the repo has multiple GGUFs, test a lighter quant such as `Q4_0`, `Q4_K_S`, or `Q3_K_M` for speed/quality tradeoffs.
76
+ - Compatibility: if a GGUF hangs during startup, try `FLASH_ATTN=0`, `CACHE_TYPE_K=f16`, `CACHE_TYPE_V=f16`, and then `MMAP=1`.
77
 
78
  **Example for 2B model (CPU-only):**
79
  ```
start.sh CHANGED
@@ -93,6 +93,8 @@ export TOOLS="${TOOLS:-}"
93
  export ENABLE_TOOLS="${ENABLE_TOOLS:-0}"
94
  export HTTP_THREADS="${HTTP_THREADS:-1}"
95
  export LOG_VERBOSITY="${LOG_VERBOSITY:-1}"
 
 
96
  export NO_WARMUP="${NO_WARMUP:-0}"
97
  export LANGSEARCH_API_KEY="${LANGSEARCH_API_KEY:-}"
98
 
@@ -169,7 +171,7 @@ CACHE_TYPE_V="$(normalize_arg_value "${REQUESTED_CACHE_TYPE_V:-f16}")"
169
  PARALLEL=1
170
 
171
  echo "effective threads: $THREADS (host=$HOST_THREADS, quota=$QUOTA_THREADS)"
172
- echo "effective llama profile: perf=$PERF_PROFILE single_request=1 ctx=$CTX_SIZE batch=${BATCH_SIZE:-$DEFAULT_BATCH} ubatch=${UBATCH_SIZE:-$DEFAULT_UBATCH} http_threads=$HTTP_THREADS log_verbosity=$LOG_VERBOSITY"
173
 
174
  export CACHE_TYPE_K CACHE_TYPE_V CTX_SIZE PARALLEL
175
 
@@ -178,7 +180,6 @@ server_args=(
178
  --host 0.0.0.0
179
  --port "${PORT:-7860}"
180
  --api-key "$API_PASSWORD"
181
- --no-mmap
182
  -ngl 0
183
  -t "$THREADS"
184
  --threads-batch "${THREADS_BATCH:-$DEFAULT_THREADS_BATCH}"
@@ -188,11 +189,20 @@ server_args=(
188
  --ctx-size "${CTX_SIZE:-4096}"
189
  --cache-type-k "${CACHE_TYPE_K}"
190
  --cache-type-v "${CACHE_TYPE_V}"
191
- --flash-attn on
192
  --metrics
193
  -lv "$LOG_VERBOSITY"
194
  )
195
 
 
 
 
 
 
 
 
 
 
 
196
  if [ "${NO_WARMUP}" = "1" ]; then
197
  server_args+=(--no-warmup)
198
  fi
 
93
  export ENABLE_TOOLS="${ENABLE_TOOLS:-0}"
94
  export HTTP_THREADS="${HTTP_THREADS:-1}"
95
  export LOG_VERBOSITY="${LOG_VERBOSITY:-1}"
96
+ export MMAP="${MMAP:-0}"
97
+ export FLASH_ATTN="${FLASH_ATTN:-1}"
98
  export NO_WARMUP="${NO_WARMUP:-0}"
99
  export LANGSEARCH_API_KEY="${LANGSEARCH_API_KEY:-}"
100
 
 
171
  PARALLEL=1
172
 
173
  echo "effective threads: $THREADS (host=$HOST_THREADS, quota=$QUOTA_THREADS)"
174
+ echo "effective llama profile: perf=$PERF_PROFILE single_request=1 ctx=$CTX_SIZE batch=${BATCH_SIZE:-$DEFAULT_BATCH} ubatch=${UBATCH_SIZE:-$DEFAULT_UBATCH} http_threads=$HTTP_THREADS log_verbosity=$LOG_VERBOSITY mmap=$MMAP flash_attn=$FLASH_ATTN"
175
 
176
  export CACHE_TYPE_K CACHE_TYPE_V CTX_SIZE PARALLEL
177
 
 
180
  --host 0.0.0.0
181
  --port "${PORT:-7860}"
182
  --api-key "$API_PASSWORD"
 
183
  -ngl 0
184
  -t "$THREADS"
185
  --threads-batch "${THREADS_BATCH:-$DEFAULT_THREADS_BATCH}"
 
189
  --ctx-size "${CTX_SIZE:-4096}"
190
  --cache-type-k "${CACHE_TYPE_K}"
191
  --cache-type-v "${CACHE_TYPE_V}"
 
192
  --metrics
193
  -lv "$LOG_VERBOSITY"
194
  )
195
 
196
+ if [ "$MMAP" = "1" ]; then
197
+ server_args+=(--mmap)
198
+ else
199
+ server_args+=(--no-mmap)
200
+ fi
201
+
202
+ if [ "$FLASH_ATTN" = "1" ]; then
203
+ server_args+=(--flash-attn on)
204
+ fi
205
+
206
  if [ "${NO_WARMUP}" = "1" ]; then
207
  server_args+=(--no-warmup)
208
  fi