cazyundee commited on
Commit
8ef48d6
·
verified ·
1 Parent(s): 3fdbf36

Probe llama CPU process state

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -360,6 +360,41 @@ def _run_cpu_smoke(model_filter):
360
  return result
361
 
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  def _run_cpu_diagnose(model_filter):
364
  import subprocess
365
  from huggingface_hub import hf_hub_download
@@ -424,6 +459,10 @@ def _run_benchmark_job(job_id, kind, model_filter=None, force=False):
424
  with _BENCH_LOCK:
425
  result = _run_cpu_diagnose(model_filter)
426
  payload = {"status": "complete", "result": result}
 
 
 
 
427
  else:
428
  if force:
429
  global _BENCH_RESULTS
@@ -522,6 +561,11 @@ def _patched_create_app(blocks, **kwargs):
522
  try: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))
523
  except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)
524
 
 
 
 
 
 
525
  @fa_app.get("/respite/benchmark/diagnose")
526
  def _diagnose(model: str="TinyLlama 1.1B (control)", job_id: str=""):
527
  if job_id:
 
360
  return result
361
 
362
 
363
+ def _run_cpu_process_probe(model_filter):
364
+ import subprocess
365
+ from huggingface_hub import hf_hub_download
366
+
367
+ model = next((m for m in _BENCH_MODELS if m["name"] == model_filter), None)
368
+ if model is None:
369
+ raise ValueError(f"Unknown model: {model_filter}")
370
+ cli = _ensure_llama()
371
+ path = hf_hub_download(repo_id=model["repo"], filename=model["file"], cache_dir=_BENCH_CACHE)
372
+ env = os.environ.copy()
373
+ env["LD_LIBRARY_PATH"] = os.path.dirname(cli)
374
+ env["CUDA_VISIBLE_DEVICES"] = ""
375
+ env["GGML_CUDA"] = "0"
376
+ command = [cli, "-m", path, "-t", "1", "-ngl", "0", "-c", "256", "-n", "1", "-p", "Say hi.", "--no-display-prompt", "--no-warmup", "-fa", "0"]
377
+ started = time.time()
378
+ child = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env)
379
+ time.sleep(8)
380
+ probe = {"pid": child.pid, "elapsed_sec": round(time.time() - started, 2), "command": command, "gpu_layers": 0}
381
+ try:
382
+ probe["ps"] = subprocess.run(["ps", "-o", "pid,stat,pcpu,pmem,rss,wchan:40,cmd", "-p", str(child.pid)], capture_output=True, text=True, timeout=5).stdout
383
+ with open(f"/proc/{child.pid}/io", "r", encoding="utf-8") as f:
384
+ probe["io"] = f.read()
385
+ with open(f"/proc/{child.pid}/status", "r", encoding="utf-8") as f:
386
+ probe["status"] = "\n".join(line for line in f if line.startswith(("State:", "VmRSS:", "Threads:")))
387
+ except Exception as exc:
388
+ probe["probe_error"] = str(exc)
389
+ finally:
390
+ child.kill()
391
+ stdout, stderr = child.communicate(timeout=10)
392
+ probe["stdout"] = stdout[-2000:]
393
+ probe["stderr"] = stderr[-4000:]
394
+ probe["returncode"] = child.returncode
395
+ return probe
396
+
397
+
398
  def _run_cpu_diagnose(model_filter):
399
  import subprocess
400
  from huggingface_hub import hf_hub_download
 
459
  with _BENCH_LOCK:
460
  result = _run_cpu_diagnose(model_filter)
461
  payload = {"status": "complete", "result": result}
462
+ elif kind == "probe":
463
+ with _BENCH_LOCK:
464
+ result = _run_cpu_process_probe(model_filter)
465
+ payload = {"status": "complete", "result": result}
466
  else:
467
  if force:
468
  global _BENCH_RESULTS
 
561
  try: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))
562
  except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)
563
 
564
+ @fa_app.get("/respite/benchmark/probe")
565
+ def _probe(model: str="TinyLlama 1.1B (control)"):
566
+ job = _start_benchmark_job("probe", model.strip())
567
+ return JSONResponse({"status": "accepted", "job_id": job, "poll": "/respite/benchmark/diagnose?job_id=" + job}, status_code=202)
568
+
569
  @fa_app.get("/respite/benchmark/diagnose")
570
  def _diagnose(model: str="TinyLlama 1.1B (control)", job_id: str=""):
571
  if job_id: