Skip to content

feat(runtime): let Ollama download and store its own models - #13457

Merged
cv merged 1 commit into
v1from
feat/ollama-owns-models
Oct 19, 2026
Merged

cv merged 1 commit into
v1from
feat/ollama-owns-models

Conversation

@cv

@cv cv commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Closes #13452. Supersedes #13450 and #13451.

Failure

Managed Ollama downloaded models with NemoClaw's own client, wrote them into Ollama's private cache layout, and checked that layout. That tied NemoClaw to Ollama's internal file format. Ollama 0.40 changed it (manifests-v2), so the runtime couldn't move past 0.35.1, and every future layout change would have repeated the work.

Decision

Ollama owns its model storage; NemoClaw only checks what Ollama reports.

  • Startup: the runtime starts Ollama on the retained volume, then pull::ensure makes sure the pinned model is present:

    • If Ollama already reports the authored name and digest, nothing is pulled.
    • Otherwise Ollama pulls the model through /api/pull, and its progress becomes the runtime's status.
    • The digest Ollama then reports in /api/tags must match the authored one, or startup stops.
    • A model installed with another digest is refused without pulling.
  • Kept from the old downloader: the check that model parameters set only sampling, not runner or resource settings such as num_ctx. It now reads them from Ollama's /api/show. The 8-hour download limit also stays.

  • Trade-off: Ollama's pull takes no expected digest, so a tag that moved upstream is downloaded and then refused, rather than never downloaded. The runtime still never serves a model whose digest differs, and the readiness inventory check confirms it again before loading.

  • Removed (+37 −631 lines overall):

    • the Ollama downloader (registry.rs, model_source.rs) and the old startup recipe;
    • the Ollama cache compatibility test, with its nextest filter and live Docker setting.

    The shared snapshot downloader stays for vLLM until Let vLLM download models by revision #13453.

  • Ollama 0.40.6: both runtimes use it, pinned by its multi-platform digest. The LICENSE comes from the v0.40.6 commit; it's the same file, with the same SHA-256.

  • Docs and notices: docs/design/runtime.md, docs/contributing/live-tests.md and both runtime notices describe the new behavior. The notices also drop a history line.

Validation

  • New unit tests in pull.rs failed against a stub before the change and pass after. They cover:

    • an installed pinned model, which isn't pulled again;
    • an absent model, which is pulled and checked;
    • a pulled digest mismatch;
    • an installed digest mismatch, refused without pulling;
    • a pull error;
    • a model that sets runner or resource parameters.
  • cargo ci passes locally: 1,605 unit tests and 150 lifecycle tests.

  • Live, ARM64, on a DGX Spark:

    • The rebuilt runtime image ran Ollama 0.40.6.
    • A managed Docker deployment with qwen3:0.6b reported Ollama pulling the manifest and each layer itself, then passed readiness with the pinned digest.
    • A Hermes agent answered through the model in 20 seconds.
    • Destroy, plus removal of what the deployment retained, left nothing behind.

    The AMD64 runtime uses the same multi-platform digest but wasn't run.

Managed Ollama no longer downloads into Ollama's private cache layout. The
runtime starts Ollama, asks it to pull the pinned model when absent, and serves
only when Ollama reports the authored digest and the model sets only sampling
parameters. This removes NemoClaw's Ollama downloader and cache test, and both
runtimes move to Ollama 0.40.6, whose new cache layout no longer matters.
@cv
cv enabled auto-merge (squash) October 19, 2026 07:40
@github-actions

Copy link
Copy Markdown
Contributor

@cv
cv merged commit c2517bf into v1 Oct 19, 2026
@cv
cv deleted the feat/ollama-owns-models branch October 19, 2026 07:53
cv added a commit that referenced this pull request Oct 19, 2026
Closes #13453.

## Failure

Managed vLLM downloaded Hugging Face snapshots with NemoClaw's own
resumable, checksumming download client in `nemoclaw-runtime`. It was a
second model downloader to maintain, after the Ollama one #13457
removed. The design doc kept it because the Hugging Face client checks a
file's size only after writing it.

## Decision

Hugging Face's own client downloads, and NemoClaw keeps only what it
owns.

- **Kept:**
- Resolving the snapshot's manifest from Hugging Face's API, which is
metadata only. It still pins the commit revision, keeps only native
safetensors, tokenizer and configuration files, never repository code,
and drives memory planning and recipe pins.
  - Weight validation, recipe preparation, and the offline vLLM launch.
- **Changed:**
- A new `vllm::runtime::download` runs the image's `hf download <repo>
<manifest files> --revision <commit> --local-dir <dir>`. It keeps the
8-hour limit and cancellation, and disables telemetry. Hugging Face's
client resumes partial files and checks large files' SHA-256 as it
downloads.
- A new `snapshot::record` then checks each file's size and writes
NemoClaw's manifest with the files marked verified. Later starts still
compare modification times without downloading again.
- **Removed** (−783 +70 lines in the runtime crate):
  - NemoClaw's download, resume and per-file verification code;
  - the registry functions only the removed Ollama downloader used;
- the nine tests of that machinery, and the Hugging Face client
evaluation (`runtimes/vllm/test_download.py`) with its live-tests
section.

Three remaining tests now exercise `record`: unfinished files, symlinks,
and unsupported metadata.
- **Docs:** `docs/design/runtime.md` and `docs/models.md` describe the
new flow.

The trade-off the design doc named still applies: Hugging Face's client
can write past a file's expected size before rejecting it. NemoClaw's
checks only bounded that for the files Hugging Face's API listed. The
principle is to leave downloading to its owner.

## Validation

- **New tests:** `record`'s tests failed against a stub before the
change, and pass after.
- `cargo ci` passes locally: 1,598 unit tests and 150 lifecycle tests.
- **Live, ARM64, on a DGX Spark:** a rebuilt vLLM v0.32.0 runtime served
`Qwen/Qwen3-0.6B` at commit `c1899de`.
- The runtime reported "Hugging Face is downloading the selected model
snapshot".
  - NemoClaw's manifest recorded all eight files verified.
  - A Deep Agents agent answered through the model.
- After a container restart, the runtime reported "verifying selected
model snapshot" and didn't download again.

  The AMD64 runtime uses the same code but wasn't run.
@wscurran wscurran added area: providers Inference provider integrations and provider behavior area: security Security controls, permissions, secrets, or hardening feature PR adds or expands user-visible functionality provider: ollama Ollama local model provider behavior v1 NemoClaw v1 branch labels Oct 23, 2026
cv added a commit that referenced this pull request Nov 11, 2026
…14400)

Managed Ollama services now pass their per-GPU reserve to llama.cpp as
`LLAMA_ARG_FIT_TARGET` as well as to Ollama as `OLLAMA_GPU_OVERHEAD`,
and the docs say what each setting does and what NemoClaw enforces. This
follows up #14396 with its review fixes and the [amendment to decision
4](#14384 (comment)).

## Problem

#14396, as merged, overstates what `OLLAMA_GPU_OVERHEAD` does on Ollama
v0.40.14, the version the runtime image pins. Its docs and comments say
the reserve leaves no GPU more than the budget, but Ollama reads it only
for a log line (`server/sched.go:661-669`), the default context size
(`server/routes.go:2573`), and the MLX runner
(`mlxrunner/client.go:401`). GGUF layer fitting uses llama.cpp's `--fit`
with its own per-device margin, 1024 MiB by default, so the budget
wasn't applied while a model loaded, even on one GPU.

#14396 also added a per-GPU free-memory rule in `launch` that duplicates
`hardware_capacity::check_memory` and can't run with several GPUs yet.
And `inference.md` describes an Ollama weight-size check that no code
path has run since #13457.

Part of #14384, step 7. What's left:

- Step 4: `hardware_capacity::budget`, `serving_memory`, and
`check_memory` still read the single-GPU `Capacity::gpu_memory`, which
is unset with two or more GPUs, so a multi-GPU capacity stops there
before this code runs. The per-GPU fit check (every selected GPU has the
budget free) belongs there.
- Step 9: the runtime's `populate` still requires exactly one visible
GPU, and `container.gpuDevices` takes one entry. Its live run covers two
GPUs with a model between the per-GPU budget and 80% of one GPU's free
memory, reading per-GPU usage from `nvidia-smi`.

## Change

- `crates/nemoclaw-runtime/src/ollama/runtime/process.rs`:
- `gpu_limits` and its per-GPU free-memory rule are gone. `launch`
computes the reserve, the largest free memory among the GPUs in
`Capacity::gpus` minus the per-GPU budget, with the existing error when
it would be negative, and the readiness bound, the budget times the
number of GPUs. With one GPU, both equal the values before #14396.
- `LLAMA_ARG_FIT_TARGET` is the same reserve rounded up to whole MiB.
`ollama serve --help` documents it as the "Target free VRAM margin per
device for llama.cpp fit (MiB)", Ollama's `llama-server` inherits it
(`llm/llama_server.go:761-765`), and llama.cpp applies one value to
every device. When the reserve is below llama.cpp's 1024 MiB default
(`fit_params_target` in `common/common.h` at llama.cpp b11963, which
Ollama v0.40.14 pins), the runtime leaves the variable unset, so
NemoClaw never lowers llama.cpp's margin. Unified-memory GPUs report no
counters, get a reserve of 0, and keep llama.cpp's default.
- `OLLAMA_GPU_OVERHEAD` stays, as decision 4 chose, and
`OLLAMA_SCHED_SPREAD` stays unset; tests pin both.
  - The comments say what each setting does in v0.40.14.
- `docs/agents-inference/inference.md`: corrects what #14396 claimed. It
describes both settings, and says what NemoClaw does and doesn't
enforce. Ollama chooses its GPUs from raw free memory, so a model can
land on one GPU with part of it offloaded to the CPU instead of
spreading, and readiness then fails. NemoClaw enforces only the total,
after the load, through `/api/ps`, which reports one total and not each
GPU's share. The per-GPU budget is a margin llama.cpp keeps, not a
guarantee NemoClaw checks. The stale weight-size sentence is replaced by
what plan and readiness actually compare.

### For review: one-GPU behavior changes

- On a dedicated-memory GPU whose free memory exceeds the budget by at
least 1024 MiB, llama.cpp now fits the layers within the budget instead
of within free memory minus 1024 MiB. A model over budget is partly
offloaded to the CPU and fails readiness's `size_vram == size` check,
rather than loading fully on the GPU and failing its budget bound.
Either way, startup fails.
- With `LLAMA_ARG_FIT_TARGET` inherited, Ollama doesn't add its own
margin for a vision projector (`llm/llama_server.go:742-769`), so a
multimodal model gets NemoClaw's reserve without Ollama's projector
padding.

## Beyond CI

Unverified: Ollama on two or more GPUs, and the effect of
`LLAMA_ARG_FIT_TARGET` on a live load. The multi-GPU cases are tested
with fake GPU inventories only, because neither this host (one GB10,
unified memory, where the variable stays unset) nor CI has several GPUs,
and the runtime still requires one visible GPU. The Ollama and llama.cpp
behavior above comes from reading their sources at the pinned revisions,
not from a run.

Signed-off-by: Carlos Villela <cvillela@nvidia.com>
@cv cv added this to the Roadmap: GTC DC 2026 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: providers Inference provider integrations and provider behavior area: security Security controls, permissions, secrets, or hardening feature PR adds or expands user-visible functionality provider: ollama Ollama local model provider behavior v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants