Skip to content

Fetch the llama.cpp validation model only when the smoke test reads it - #8248

Merged
danielhanchen merged 6 commits into
mainfrom
llama-prebuilt-lazy-probe
Aug 9, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
llama-prebuilt-lazy-probe

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

An approved prebuilt bundle proves its integrity by sha256 and so skips the staged
smoke test, which leaves the tiny GGUF probe unread on the default install path.
It was still downloaded up front, before the release loop, which made
huggingface.co a hard gate on every prebuilt install: a 429 there raised
PrebuiltFallback and forced a multi-minute source build over a file nothing
went on to open.

Seen on #8185, where virgin win container / overlay=true failed like this:

[llama-prebuilt] downloading tiny GGUF validation model
[llama-prebuilt] fetch failed (1/4) for .../stories260K.gguf: HTTP Error 429: Too Many Requests; retrying
[llama-prebuilt] prebuilt install path failed; falling back to source build
[llama-prebuilt] prebuilt fallback reason: validation model unavailable: HTTP Error 429

Change

lazy_validation_model() returns a memoised thunk, and validate_prebuilt_choice
resolves it inside the one branch that reads the probe, so both validate_quantize
and validate_server share a single fetch. The provider accepts a Path or a
callable, so every existing caller and test keeps working unchanged.

The retry path itself was already sound (429 is in RETRYABLE_HTTP_STATUS,
Retry-After is honoured, exponential backoff with jitter), so this removes the
dependency rather than widening the retry window. Hashless external prebuilts have
no sha256 gate and still validate, so they still fetch the probe, just at the point
of use.

Tests

  • approved bundle with the flag off: a probe provider that raises is never called
  • hashless build: probe fetched exactly once across both smoke steps
  • lazy_validation_model: no download on construction, one download across repeat calls
  • end to end over install_prebuilt: with download_validation_model raising 429, the
    flow reaches validate_prebuilt_attempts instead of exiting EXIT_FALLBACK. Verified
    this one fails against the pre-fix source.

test_install_prebuilt_does_not_skip_unhealthy_existing_install had been tripping on
the probe download as a proxy for reaching the normal install flow. That proxy no longer
exists on the default path, so it now trips on validate_prebuilt_attempts, which is the
behaviour its name describes.

Validation

Full tests/studio/install/ green locally (1711 passed), ruff clean. Ran the matrix on a
staging replica: Clean machine install, Mac Studio Install Matrix, MLX, Cross-platform
parity, Startup profile and every API/GGUF/Update/UI lane green. Backend CI is red there
and on unmodified main alike, on test_python39_compatibility (the newly vendored
truststore) and on test_diffusion_backend / test_saved_image_metadata_precision_contract;
all five reproduce on a clean checkout of main with none of these commits.

danielhanchen and others added 3 commits August 9, 2026 08:59
An approved bundle proves integrity by sha256 and skips the staged smoke test,
so the tiny GGUF probe goes unread on the default install path. It was still
downloaded up front, which made huggingface.co a hard gate on every prebuilt
install: a 429 there raised PrebuiltFallback and forced a multi-minute source
build over a file nothing opens.

Fetch it lazily instead, at the one branch that reads it, memoised so the two
smoke steps share a single download.

test_install_prebuilt_does_not_skip_unhealthy_existing_install tripped on the
probe download as a proxy for reaching the normal install flow. That proxy is
gone on the default path, so it now trips on validate_prebuilt_attempts, which
is the behaviour it actually names.
The unit tests pin validate_prebuilt_choice's behaviour, but the bug was that a
429 short-circuited the whole install before the release loop. Assert that over
install_prebuilt itself: with download_validation_model raising 429, the flow
must still reach validate_prebuilt_attempts rather than exit EXIT_FALLBACK.

Verified it fails against the pre-fix source.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b3d457a9d

ℹ️ 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".

# kept intact; flip the flag / env to restore it (#5854).
if choice.expected_sha256 is None or staged_validation_enabled():
# Only branch that reads the probe, so this is where a lazy one is fetched.
probe_path = resolve_validation_model(probe)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep probe-fetch failures outside candidate fallback

When validation is required and a plan has multiple attempts—for example, direct-upstream Windows GPU plus CPU assets—a PrebuiltFallback from the lazy model download now occurs here inside validate_prebuilt_attempts' per-candidate try. Its catch treats the network error as a failure of the preferred bundle and advances to a lower-priority candidate or older release; because the thunk does not memoize failures, every attempt may repeat the model retries after downloading and extracting another bundle, and a transient first failure followed by success can install CPU instead of the healthy GPU bundle. Materialize the probe once outside the per-candidate catch when the plan requires smoke validation, while retaining laziness for plans that skip it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct catch, and it is mine. Reproduced it against the code at head.

validate_prebuilt_attempts wraps each candidate in except Exception, so once the probe moved inside validate_prebuilt_choice a failed download landed in that handler, got rewritten as candidate attempt failed before activation, and fell through to the next attempt rather than aborting. On a plan with a GPU asset ahead of a CPU one that installs the CPU bundle off a transient 429. The thunk memoised success only, so each further attempt re-ran the download after extracting another bundle, exactly as described.

Fixed in fb18afd by resolving the probe once before the candidate loop whenever any attempt will validate:

if staged_validation_enabled() or any(a.expected_sha256 is None for a in attempt_list):
    probe = resolve_validation_model(probe)

Hashless attempts are the reachable case, since they have no sha256 gate and are always validated. A failure there now raises outside the per-candidate handler and reaches the source-build fallback, which is the pre-change behaviour. Plans that skip validation never call the thunk, so the laziness this PR is about is unaffected.

Regression test added: two hashless attempts and a probe that raises 429 must leave the second candidate untouched and fetch exactly once. It fails against the pre-fix source.

validate_prebuilt_attempts catches Exception per candidate, so a probe download
failing inside that try read as a failure of the bundle itself: a transient 429
demoted a healthy GPU pick to the CPU asset or an older release, and because the
thunk memoises success but not failure, each further attempt re-downloaded after
extracting another bundle.

Hashless attempts always validate, so resolve the probe once before the loop
whenever any attempt will need it. Plans that skip validation never call the
thunk and stay lazy.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64ce11b16a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

install_dir,
work_dir,
probe_path,
probe,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep probe failures out of release fallback

When UNSLOTH_LLAMA_STAGED_VALIDATION=1 (or a hashless direct-upstream plan) and latest resolves more than one release, a PrebuiltFallback from materializing this lazy probe is raised inside the per-release try; the except PrebuiltFallback below then treats a Hugging Face 429 as a bad release and continues to an older plan. Because the probe is independent of the release and failed thunks are retried, a transient first failure followed by success installs the older llama.cpp build instead of validating the selected release or falling back once. Resolve the probe once before entering the release loop when any plan will smoke-test, or otherwise keep probe failures out of the release fallback path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right again, and it is the same shape as the last one a level up. Confirmed against the code at head: the per-release handler in install_prebuilt is except PrebuiltFallback: ... continue, so a probe failure raised inside validate_prebuilt_attempts propagated out of the inner guard and demoted the selected release to an older plan. With the thunk memoising success but not failure, each plan re-ran the download.

Fixed in ab2ce98, same treatment as the inner loop, applied before the release loop:

if staged_validation_enabled() or any(
    attempt.expected_sha256 is None
    for release_plan in release_plans
    for attempt in release_plan.attempts
):
    probe = resolve_validation_model(probe)

The guard inside validate_prebuilt_attempts stays, so that function is still correct when called on its own; with the outer resolve it just sees a Path and does nothing.

Regression test added: two hashless release plans with a probe that fails must exit EXIT_FALLBACK without validating either plan, so the run reaches the source build once instead of silently installing the older release. It fails against the pre-fix source.

The per-release handler in install_prebuilt swallows PrebuiltFallback and moves
to an older plan, the same shape as the per-candidate handler one level down. A
probe failure raised inside it installed an older llama.cpp build over a
transient 429, and since the thunk memoises success but not failure, each plan
retried the download.

The probe does not depend on which release was picked, so resolve it once before
the loop whenever any plan will smoke-test.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ab2ce981b3

ℹ️ 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
danielhanchen merged commit 82bf2e6 into main Aug 9, 2026
65 of 69 checks passed
@danielhanchen
danielhanchen deleted the llama-prebuilt-lazy-probe branch August 9, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant