Enhance Ollama model management and performance tuning

- Updated the `provision_llm` function to utilize the `/api/tags` endpoint for verifying available models, improving accuracy in model management.
- Introduced a new `already_have_ollama_tag` function to ensure exact tag matching, preventing mismatches during model checks.
- Enhanced the `pull_stream` function to require a successful status from the API before proceeding, ensuring reliable model downloads.
- Added logic to handle unwritten blob files, improving the robustness of the model pulling process.
- Updated documentation and tests to reflect these changes, ensuring clarity and reliability in Ollama model operations.
This commit is contained in:
Leonid Pershin
2026-08-21 14:20:06 +03:00
parent f437cd0373
commit 5832c5cf75
14 changed files with 626 additions and 54 deletions
+56 -1
View File
@@ -188,4 +188,59 @@ def test_stack_probe_requires_ollama_models():
assert "/api/tags" in _REMOTE_STACK_PROBE
assert "0 models" in _REMOTE_STACK_PROBE
assert 'payload.get("models")' in _REMOTE_STACK_PROBE
assert "WANT_OLLAMA_MODELS" in _REMOTE_STACK_PROBE
assert "retry" in _REMOTE_STACK_PROBE
assert ".gpu-rent-ollama-pulling" in _REMOTE_STACK_PROBE
assert "WARN 0 models" in _REMOTE_STACK_PROBE
assert "GPU не гасим" in _REMOTE_STACK_PROBE
def test_verify_stack_zero_models_does_not_fail_up(monkeypatch):
from gpu_rent.ready import ServiceCheck, verify_stack_on_vm
class C:
enable_swarmui = True
llm_runtime = "ollama"
def fake_probe(_cfg, _host):
return [
ServiceCheck("swarmui", True, "ok", "vm", retry=False),
ServiceCheck(
"ollama",
True,
"WARN 0 models — Assistent empty (GPU не гасим)",
"vm",
retry=False,
),
]
monkeypatch.setattr("gpu_rent.ready._probe_vm_once", fake_probe)
out = verify_stack_on_vm(C(), "1.2.3.4", [].append, timeout=5.0, poll_every=0.01)
assert all(c.ok for c in out)
def test_verify_stack_retries_while_pulling(monkeypatch):
from gpu_rent.ready import ServiceCheck, verify_stack_on_vm
class C:
enable_swarmui = False
llm_runtime = "ollama"
n = {"i": 0}
def fake_probe(_cfg, _host):
n["i"] += 1
if n["i"] == 1:
return [
ServiceCheck(
"ollama", False, "0 models — pull идёт (12s)", "vm", retry=True
)
]
return [ServiceCheck("ollama", True, "1 models (qwen)", "vm", retry=False)]
monkeypatch.setattr("gpu_rent.ready._probe_vm_once", fake_probe)
out = verify_stack_on_vm(
C(), "1.2.3.4", [].append, timeout=5.0, poll_every=0.01
)
assert out[0].ok
assert n["i"] == 2