Spaces:
Running on Zero
Running on Zero
Probe llama CPU process state
Browse files359 unmodified lines36036136236336436558 unmodified lines42442542642742842992 unmodified lines522523524525526527359 unmodified linesreturn resultdef _run_cpu_diagnose(model_filter):import subprocessfrom huggingface_hub import hf_hub_download58 unmodified lineswith _BENCH_LOCK:result = _run_cpu_diagnose(model_filter)payload = {"status": "complete", "result": result}else:if force:global _BENCH_RESULTS92 unmodified linestry: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)@fa_app.get("/respite/benchmark/diagnose")def _diagnose(model: str="TinyLlama 1.1B (control)", job_id: str=""):if job_id:359 unmodified lines36036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940058 unmodified lines45946046146246346446546646746892 unmodified lines561562563564565566567568569570571359 unmodified linesreturn resultdef _run_cpu_process_probe(model_filter):import subprocessfrom huggingface_hub import hf_hub_downloadmodel = next((m for m in _BENCH_MODELS if m["name"] == model_filter), None)if model is None:raise ValueError(f"Unknown model: {model_filter}")cli = _ensure_llama()path = hf_hub_download(repo_id=model["repo"], filename=model["file"], cache_dir=_BENCH_CACHE)env = os.environ.copy()env["LD_LIBRARY_PATH"] = os.path.dirname(cli)env["CUDA_VISIBLE_DEVICES"] = ""env["GGML_CUDA"] = "0"command = [cli, "-m", path, "-t", "1", "-ngl", "0", "-c", "256", "-n", "1", "-p", "Say hi.", "--no-display-prompt", "--no-warmup", "-fa", "0"]started = time.time()child = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env)time.sleep(8)probe = {"pid": child.pid, "elapsed_sec": round(time.time() - started, 2), "command": command, "gpu_layers": 0}try: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).stdoutwith open(f"/proc/{child.pid}/io", "r", encoding="utf-8") as f:probe["io"] = f.read()with open(f"/proc/{child.pid}/status", "r", encoding="utf-8") as f:probe["status"] = "\n".join(line for line in f if line.startswith(("State:", "VmRSS:", "Threads:")))except Exception as exc:probe["probe_error"] = str(exc)finally:child.kill()stdout, stderr = child.communicate(timeout=10)probe["stdout"] = stdout[-2000:]probe["stderr"] = stderr[-4000:]probe["returncode"] = child.returncodereturn probedef _run_cpu_diagnose(model_filter):import subprocessfrom huggingface_hub import hf_hub_download58 unmodified lineswith _BENCH_LOCK:result = _run_cpu_diagnose(model_filter)payload = {"status": "complete", "result": result}elif kind == "probe":with _BENCH_LOCK:result = _run_cpu_process_probe(model_filter)payload = {"status": "complete", "result": result}else:if force:global _BENCH_RESULTS92 unmodified linestry: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)@fa_app.get("/respite/benchmark/probe")def _probe(model: str="TinyLlama 1.1B (control)"):job = _start_benchmark_job("probe", model.strip())return JSONResponse({"status": "accepted", "job_id": job, "poll": "/respite/benchmark/diagnose?job_id=" + job}, status_code=202)@fa_app.get("/respite/benchmark/diagnose")def _diagnose(model: str="TinyLlama 1.1B (control)", job_id: str=""):if job_id:
app.py+44