Skip to content

fix(studio): accept Ollama OCI manifest reference layers - #18075

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
bezabyte:codex/issue-18058-ollama-manifest-layer
Nov 19, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
bezabyte:codex/issue-18058-ollama-manifest-layer

Conversation

@bezabyte

@bezabyte bezabyte commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Verification

  • python -m pytest -q studio/backend/tests/test_ollama_manifest_load_resolution.py: 28 passed
  • python -m pytest -q studio/backend/tests/test_ollama_api_catalog.py studio/backend/tests/test_local_model_format.py -k ollama: 13 passed
  • python -m py_compile studio/backend/hub/services/models/ollama.py studio/backend/tests/test_ollama_manifest_load_resolution.py: passed
  • git diff --check: passed

Maintainer follow-up

Checked against a current Ollama build (from ollama/ollama main) pulling real models into a scratch store:

  • ollama pull now writes a manifests-v2 entry plus a legacy "downgrade anchor" (manifest.WriteLegacyAnchor) that lists its manifest blobs as extra layers. A plain pull (smollm2:135m) adds application/vnd.docker.distribution.manifest.v2+json; a manifest-list pull (qwen3.5:0.8b, gemma4:e2b, ...) adds that and application/vnd.ollama.manifest.list.v2+json. The first commit admitted only the former, so list-published models stayed hidden. Both are admitted now.
  • Once these tags are listed, Studio's delete had to learn the new layout: it removed the legacy file and every blob no other legacy manifest used, leaving the manifests-v2 entry dangling (Ollama then logs "corrupt manifests detected, skipping prune") and deleting blobs an ollama cp alias (v2-only) still needs. Delete now drops the tag from both trees and keeps any blob a remaining manifest (legacy or v2, through list children) references. After deleting both models from Studio, the store is byte-identical to ollama rm of the same two models.
before (merge base) this PR
smollm2:135m (plain pull) in picker hidden listed, loads in llama.cpp
qwen3.5:0.8b (manifest-list pull) in picker hidden listed, loads in llama.cpp
delete smollm2:135m with an ollama cp alias present n/a (not listed) alias still runs, no dangling v2 entry

Picker, on-device models filtered to 0.8b, same Ollama store on both sides:

picker before/after

@danielhanchen danielhanchen self-assigned this Nov 17, 2026
Newer Ollama appends both downgrade-anchor layer types to a pulled legacy
manifest (manifest.v2+json for the child, manifest.list.v2+json for the
list), so admit both. Now that anchored tags are listed, delete also drops
the tag's manifests-v2 entry and keeps blobs any other manifests-v2 entry
(an ollama cp alias) still references.

[skip ci]
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T09:35:32.241023Z 6739135 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 0e3f283cd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
…g path

Count inline manifest-list children (resolveLocalManifestReference accepts
them) toward retention, let a failed child stat abort retention instead of
reading as missing, and only unlink a manifests-v2 tag whose parent resolves
inside manifests-v2. The lease retag test now spells the Windows separator
escape too (%5C), so it no longer fails on Windows.

[skip ci]
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Nov 17, 2026
… fixed 0.1 s sleep (#18103)

`studio/backend/tests/test_anthropic_admission.py` fails intermittently
in the Studio `a-f` shard on unrelated PRs (#18045, #18006, #18069,
#18075):

```
test_non_streaming_queued_then_admitted
E   AssertionError: assert 0 == 1
E    +  where 0 = LlamaAdmissionSnapshot(..., capacity=1, active=1, queued=0, ...).queued
test_capacity_enforced_from_effective_parallel_slots
E   AssertionError: assert (3 == 3 and 3 == 3 and 0 == 1)
```

## Cause

Each of these tests occupies every slot, starts a request as a task,
sleeps a fixed 0.1 s and then expects the request to be in the admission
queue. On a loaded runner the handler sometimes has not reached the
queue within 0.1 s, so the snapshot still shows `queued=0`. The
admission code is not at fault; the test raced it.

## Fix

`_until_queued(task)` polls the queue snapshot every 10 ms until the
request is queued, for up to 5 s. It still fails if the request finishes
without ever queueing (`task.done()`) or never queues within the
deadline, so a request that skips admission is still caught. It replaces
the fixed sleep at all five sites that assert `queued == 1` right after
starting the task. The assertions themselves are unchanged.

## Verification

- `tests/test_anthropic_admission.py`: 39 passed, twice.
- Slow handler simulated locally (`await asyncio.sleep(0.25)` at the top
of `anthropic_messages`, not committed):
- main: the five queued checks fail (plus
`test_uncontended_hot_path_is_fast`, which is meant to catch a slow
handler).
  - this branch: only `test_uncontended_hot_path_is_fast` fails.
…or but missing

Python 3.14's Path.is_file returns False for every OSError, so an EIO on a
retained child read as "not downloaded" and its blobs could be deleted.
stat() now suppresses only FileNotFoundError / NotADirectoryError.

[skip ci]
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Retention candidates went through _safe_is_file, so an EIO / EACCES on a
remaining tag read as "not a file" and its blobs could be deleted. One
helper now treats only a missing path as absent, for tags and children.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Nov 17, 2026
…oth.kernels loaded on CPU since #18111) (#18117)

Two CPU-backend tests fail on main in the CPU `rest` shard since #18111
(seen on the staging runs of #18075 and #18076):

```
tests/test_cpu_backend_init.py::test_no_accelerator_loads_the_cpu_backend
tests/test_cpu_backend_tiled_mlp.py::test_cpu_backend_loader_tiles_like_the_gpu_loaders
E   AssertionError: assert ['unsloth.kernels', ...] == []
```

## Cause

#18111 added, at the end of `unsloth/__init__.py`:

```python
from .kernels.triton_launch import sync_compile_cache_tag_to_workers as _sync_tag
```

It runs for every backend. On a machine with no accelerator, `import
unsloth` now loads `unsloth.kernels` (and everything its package
`__init__` pulls in, 87 modules) even though the CPU backend
deliberately never loads GPU kernels; the tests above guard exactly
that.

The sync itself is right, but it only matters where kernels add tags to
`torch.compiler.config.cache_key_tag`, i.e. the GPU backend, which has
already imported `unsloth.kernels` by then. On the CPU backend there is
no tag to hand to compile workers.

## Fix

Run the sync only when the GPU backend was selected (`_IS_CPU_BACKEND`
is False). The MLX branch never defines `_IS_CPU_BACKEND`, so it is
skipped there too.

## Verification

- `tests/test_cpu_backend_init.py`,
`tests/test_cpu_backend_tiled_mlp.py`: 2 failed on main, pass here.
- `tests/test_compile_cache_tag_workers.py` (#18111's own tests): 6
passed.
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…ys fp32 (red since #18099) (#18118)

`tests/test_attention_dispatch_compiled_block.py::test_rerouted_xformers_keeps_the_fp32_downcast`
fails on main in the CPU `rest` shard since #18099 (seen on the staging
runs of #18075 and #18076):

```
E   assert torch.float32 == torch.bfloat16
```

## Cause

#18099 made fp32 Q/K/V with autocast off stay fp32 (rerouted to SDPA)
instead of being downcast to bf16 for xformers / flash, because that is
a genuine fp32 model. The DoRA downcast still applies under autocast,
which is how DoRA reaches this code in training. #18099 moved its own
DoRA tests under autocast, but this compiled-path test in another file
still called the reroute with plain fp32 inputs and no autocast, so it
now sees the intended fp32 result.

The behaviour change is correct; the test predates it.

## Fix

- `test_rerouted_xformers_keeps_the_fp32_downcast` now takes the
autocast decision (`_keeps_fp32_attention` returns False), so it still
checks the DoRA downcast through the compiled reroute. CPU CI cannot
enter CUDA autocast, and faking `torch.is_autocast_enabled` trips
dynamo's global autocast guard ("Global autocast state changed while
dynamo tracing"), so the decision is patched directly.
- New `test_rerouted_xformers_keeps_an_fp32_model_in_fp32` covers the
other half under `fullgraph` compile: without autocast the reroute
returns fp32 and matches the fp32 SDPA reference.

## Verification

- main: `test_rerouted_xformers_keeps_the_fp32_downcast` fails.
- this branch: `tests/test_attention_dispatch_compiled_block.py` and
`tests/utils/test_attention_dispatch_dora_dtype.py` 19 passed, 2
skipped.
- Sabotage: with `_keeps_fp32_attention` forced to False (the pre-#18099
behaviour), the new fp32 test fails.
…isted

rglob silently skips a directory it cannot scan, so an unreadable tag
directory dropped that tag from retention. Walk both trees with os.walk and
an onerror that raises, and keep all blobs on any listing error.

[skip ci]
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Python 3.14's Path.is_dir returns False on EIO, which read an unreadable
manifests-v2 as "no v2 store". The walk now treats only a missing root as
empty and every other error as incomplete (keep all blobs).

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…sification errors

os.walk skips directory symlinks without calling onerror and files a
directory whose is_dir() raised as a regular entry, so a retained tag could
go unseen. Walk with scandir, follow each directory once (realpath guard),
and let any listing or classification error reach the keep-all path.

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: cd58aea2aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
… of a 1e-6 atol (intermittent m-r failure) (#18153)

`studio/backend/tests/test_rocm_windows_wide_head_sdpa.py::test_guarded_wide_head_compiles_fullgraph[inductor]`
(added in #18122) fails intermittently in the Studio `m-r` shard on
unrelated PRs (seen on the staging run of #18075):

```
tests/test_rocm_windows_wide_head_sdpa.py:154: in test_guarded_wide_head_compiles_fullgraph
    assert torch.allclose(got, want, atol = 1e-6)
E   assert False
```

## Cause

The test compares the guarded SDPA call in eager (math backend) with the
same call compiled `fullgraph` by Inductor. Inductor lowers the math
SDPA to its own CPU kernel, so the two agree to fp32 rounding, not bit
for bit. On this host the gap on a 512-wide head is already up to 8.3e-7
(seeds 0 to 3), right at the fixed `atol = 1e-6`, and the inputs were
unseeded, so a draw on a different CPU (CI runners vary) can land just
over it. The guard is fine; the bound was too tight for two different
kernels.

## Fix

- Seeded inputs (`torch.Generator().manual_seed(0)`), so a failure is
reproducible.
- `torch.testing.assert_close(got, want)` with the fp32 defaults (atol
1e-5, rtol 1.3e-6) and a comment saying why it is not bitwise.

## Verification

- `tests/test_rocm_windows_wide_head_sdpa.py`: 11 passed, twice.
- Sabotage: comparing against a non-causal eager result makes both
`compiles_fullgraph` cases fail, so the check still catches a wrong
answer.
danielhanchen added a commit that referenced this pull request Nov 17, 2026
… extra red since #18143) (#18155)

The `Chat UI Tests (extra)` declared-polls gate
(`tests/studio/playwright_declared_polls.py`) fails on main since #18143
(seen on the staging run of #18075, an Ollama-only PR):

```
FAIL these paths are polled by the app but are not in the log budget:
  /api/chat/revision   8x within one dwell (~38.4/min)
```

## Cause

#18143 added cross-device chat sync: `remote-history-watch.ts` polls
`GET /api/chat/revision` every `REMOTE_HISTORY_POLL_MS` (4 s) while the
page is visible. Every polled path has to be declared in the log budget
and given a log class, otherwise each hit writes an access line (here
about 15 lines a minute per open tab, also mirrored into the desktop
log). The feature is right; the two declarations were missed.

## Fix

- `studio/backend/tests/log_budget/session.py`: `"/api/chat/revision":
(4.0, "declared")` in `IDLE_POLLS`, with the call site named.
- `studio/backend/loggers/handlers.py`: `/api/chat/revision` in
`_QUIET_SUCCESS_PATHS`. A 2xx read only carries a revision number; when
it changes, the thread fetch that follows still logs, and a failed read
(non-2xx) still logs.

## Verification

- `tests/test_log_budget.py` plus the access-log handler tests: 83
passed.
- The unit-side closure check holds both halves together: with the
handler class but without the `IDLE_POLLS` entry,
`TestClassificationClosure::test_every_classified_path_is_in_a_scenario`
fails.
- The Playwright gate reads `IDLE_POLLS` / `BUSY_POLLS` (`declared =
set(ALL_POLLS)`), so the path it reported is now declared.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 673913599d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Studio Bug] New Ollama models omitted when legacy manifest contains OCI manifest-reference layer

3 participants