From a1271f445443662ed8bec6b2bb8b66feebb0f4db Mon Sep 17 00:00:00 2001 From: KingManiya Date: Sun, 19 Apr 2026 02:05:59 +0400 Subject: [PATCH] refactor --- llama_cli.py | 18 +++++------------- nodes.py | 11 +++++++---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/llama_cli.py b/llama_cli.py index 1fa3f84..7338c71 100644 --- a/llama_cli.py +++ b/llama_cli.py @@ -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 = "" diff --git a/nodes.py b/nodes.py index c941917..58e05bc 100644 --- a/nodes.py +++ b/nodes.py @@ -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", {