agora.fleet.vram

VRAM pre-flight check.

Probes the system’s free GPU VRAM and the model’s estimated memory footprint, then decides whether the model will fit. Runs asynchronously via asyncio.create_subprocess_exec so it never blocks the event loop.

Failure modes (probe returns None) are treated as “unknown” rather than “fits” — callers log and skip unless the user has opted out of the check.

Functions

check_model_fits(model, base_url[, ...])

Decide whether model will fit in the system's free VRAM.

estimate_model_size_mib(model)

Heuristic model-size estimate when Ollama has no better answer.

get_model_size_mib(model, base_url)

Query Ollama for the model's on-disk size; fall back to the heuristic.

probe_free_vram_mib([device_index])

Return free VRAM in MiB, or None if no probe worked.

raise_if_wont_fit(check, model)

Raise AgoraError when a check proved the model will not fit.

warmup(model, base_url[, deadline_seconds, ...])

Load the model into VRAM before the real timeout clock starts.

Classes

VRAMCheck

Verdict of the pre-flight free-VRAM probe.

class agora.fleet.vram.VRAMCheck[source]

Bases: object

Verdict of the pre-flight free-VRAM probe. fits is the go/no-go; free_mib is None when the probe could not read the device (in which case the caller decides whether to proceed), and reason is a human-readable explanation for the log/error path.

fits: bool
free_mib: int | None
required_mib: int
reason: str
__init__(fits, free_mib, required_mib, reason)
async agora.fleet.vram.probe_free_vram_mib(device_index=None)[source]

Return free VRAM in MiB, or None if no probe worked.

device_index (when set) restricts the query to that single GPU — used when _resolve_target_device() has identified the device Ollama is using. When None (device unknown), the fallback sums free VRAM across all visible devices rather than taking the min(): “all visible devices, summed” is a less-wrong default than “the device with the least free”, which on a two-GPU box reports the wrong card whenever the other one is fuller (the June 30 09:58 false-rejection).

agora.fleet.vram.estimate_model_size_mib(model)[source]

Heuristic model-size estimate when Ollama has no better answer.

async agora.fleet.vram.get_model_size_mib(model, base_url)[source]

Query Ollama for the model’s on-disk size; fall back to the heuristic.

async agora.fleet.vram.check_model_fits(model, base_url, safety_margin_mib=512)[source]

Decide whether model will fit in the system’s free VRAM.

fits=True when we can prove it fits. fits=True with free_mib=None when the probe failed (we do not block on unknown). fits=False only when we can prove it will not fit.

Special case: if model is already loaded into VRAM (visible in /api/ps), no fresh allocation is needed — we return fits=True without demanding more free VRAM. This avoids a false negative when a previous run or warmup left the model resident.

agora.fleet.vram.raise_if_wont_fit(check, model)[source]

Raise AgoraError when a check proved the model will not fit.

async agora.fleet.vram.warmup(model, base_url, deadline_seconds=600.0, keep_alive='30m')[source]

Load the model into VRAM before the real timeout clock starts.

Sends a tiny /api/generate request with the supplied keep_alive (default 30m) so the model stays resident for the duration of the run. The keep_alive value should match whatever the runtime adapter uses — otherwise the model can evict between warm-up and the first real turn. The timeout here is independent from llm_timeout_seconds — model loading can legitimately take minutes on cold disks, but we don’t want that budget to eat the actual generation time on the first real turn.

Raises AgoraError on timeout or HTTP error so the orchestrator fails fast before creating identity rooms.