This commit is contained in:
KingManiya
2026-04-19 02:05:59 +04:00
parent eaf820678d
commit a1271f4454
2 changed files with 12 additions and 17 deletions
+5 -13
View File
@@ -18,14 +18,6 @@ LLAMA_PERF_PREFIXES = (
"llama_perf_context_print:",
"common_perf_print:",
)
MAX_LLAMA_SEED = 2**32 - 1
INTERRUPT_POLL_SECONDS = 0.1
MEMORY_MODES = (
"auto",
"gpu_layers",
"cpu_moe_layers",
"gpu_and_cpu_moe_layers",
)
def tensor_to_temp_png(image) -> Path:
@@ -165,8 +157,8 @@ def run_llama_cli(
raise RuntimeError(
f"llama.cpp inference failed with exit code {result.returncode}:\n{stderr}"
)
response, thinking = extract_thinking(result.stdout)
perf = extract_perf(result.stderr)
response, thinking = _extract_thinking(result.stdout)
perf = _extract_perf(result.stderr)
return response, thinking, perf
@@ -194,12 +186,12 @@ def _communicate_with_interrupt(process: subprocess.Popen, timeout_seconds: int)
_stop_process(process)
raise TimeoutError(f"llama.cpp timed out after {timeout_seconds}s")
try:
return process.communicate(timeout=min(INTERRUPT_POLL_SECONDS, remaining))
return process.communicate(timeout=min(0.1, remaining))
except subprocess.TimeoutExpired:
continue
def extract_perf(stderr: str) -> str:
def _extract_perf(stderr: str) -> str:
lines = [
line.strip() for line in str(stderr or "").splitlines()
if any(prefix in line for prefix in LLAMA_PERF_PREFIXES)
@@ -207,7 +199,7 @@ def extract_perf(stderr: str) -> str:
return "\n".join(lines)
def extract_thinking(text: str) -> tuple[str, str]:
def _extract_thinking(text: str) -> tuple[str, str]:
text = str(text or "")
thinking = ""
+7 -4
View File
@@ -10,8 +10,6 @@ from .folder_registry import (
system_prompt_options,
)
from .llama_cli import (
MAX_LLAMA_SEED,
MEMORY_MODES,
build_command,
run_llama_cli,
split_extra_args,
@@ -79,7 +77,12 @@ class QwenGGUF:
"step": 512,
"tooltip": "llama.cpp context window size in tokens.",
}),
"memory_mode": (list(MEMORY_MODES), {
"memory_mode": ([
"auto",
"gpu_layers",
"cpu_moe_layers",
"gpu_and_cpu_moe_layers",
], {
"default": "auto",
"tooltip": "auto passes no layer flags; other modes pass GPU layers, CPU MoE layers, or both.",
"advanced": True,
@@ -101,7 +104,7 @@ class QwenGGUF:
"seed": ("INT", {
"default": 1,
"min": -1,
"max": MAX_LLAMA_SEED,
"max": 2**32 - 1, # MAX_LLAMA_SEED
"tooltip": "Random seed used by llama.cpp. Use -1 for a random seed.",
}),
"timeout_seconds": ("INT", {