signsur4739379373 commited on
Commit
667e207
·
1 Parent(s): a5c81b6

Build only llama-server target with low parallelism to avoid OOM

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -195,9 +195,29 @@ def _push_cached_binary() -> None:
195
 
196
  def _build_llama_cpp() -> None:
197
  print("[enhancer] building llama.cpp from source...", flush=True)
198
- _run(["git", "clone", "--depth", "1", "https://github.com/ggml-org/llama.cpp.git", str(LLAMA_CPP_DIR)])
199
- _run(["cmake", "-B", "build", "-DGGML_CUDA=ON"], cwd=LLAMA_CPP_DIR)
200
- _run(["cmake", "--build", "build", "--config", "Release", "-j4"], cwd=LLAMA_CPP_DIR)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  if not LLAMA_SERVER_BIN.exists():
202
  raise RuntimeError("llama-server binary not found after build")
203
  print("[enhancer] llama.cpp built", flush=True)
 
195
 
196
  def _build_llama_cpp() -> None:
197
  print("[enhancer] building llama.cpp from source...", flush=True)
198
+ if not LLAMA_CPP_DIR.exists():
199
+ _run(["git", "clone", "--depth", "1", "https://github.com/ggml-org/llama.cpp.git", str(LLAMA_CPP_DIR)])
200
+ # Configure once. Only build the llama-server target to minimize the number
201
+ # of heavy CUDA compile units (full suite OOMs the constrained build box).
202
+ _run(
203
+ [
204
+ "cmake", "-B", "build",
205
+ "-DGGML_CUDA=ON",
206
+ "-DCMAKE_BUILD_TYPE=Release",
207
+ "-DLLAMA_BUILD_TESTS=OFF",
208
+ "-DLLAMA_BUILD_EXAMPLES=OFF",
209
+ "-DLLAMA_BUILD_TOOLS=ON",
210
+ "-DLLAMA_CURL=OFF",
211
+ ],
212
+ cwd=LLAMA_CPP_DIR,
213
+ )
214
+ # Low parallelism to cap peak memory; retry single-threaded on failure.
215
+ build_cmd = ["cmake", "--build", "build", "--config", "Release", "--target", "llama-server"]
216
+ try:
217
+ _run(build_cmd + ["-j2"], cwd=LLAMA_CPP_DIR)
218
+ except subprocess.CalledProcessError:
219
+ print("[enhancer] -j2 build failed, retrying with -j1", flush=True)
220
+ _run(build_cmd + ["-j1"], cwd=LLAMA_CPP_DIR)
221
  if not LLAMA_SERVER_BIN.exists():
222
  raise RuntimeError("llama-server binary not found after build")
223
  print("[enhancer] llama.cpp built", flush=True)