Skip to content

fix(studio): opt-in source-build GPU smoke validation - #7322

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:fix/5854-source-build-smoke-validation
Jul 24, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:fix/5854-source-build-smoke-validation

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Fixes #5854

Problem

#6481 already fixed gap 1: empty CUDA arch detection no longer silently produces a PTX-only source build. Gap 2 remained open: after a GPU source build, setup.sh accepted llama-server with no runtime smoke test, unlike the prebuilt path. A binary that links but cannot run on the host GPU/driver could still be installed.

The full GPU forward-pass smoke is intentionally off by default (_RUN_STAGED_PREBUILT_VALIDATION = False) because it JIT-compiles CUDA kernels and stalls installs for minutes on Blackwell. Daniel left #5854 open for wiring the source path into that same opt-in switch.

Fix

  • studio/install_llama_prebuilt.py: Add staged_validation_enabled() (UNSLOTH_LLAMA_STAGED_VALIDATION or the existing constant), use it in validate_prebuilt_choice, and add --validate-install / --install-kind to run the staged smoke against an existing build tree.
  • studio/setup.sh: After a successful GPU source build (before the install swap), if staged validation is enabled, run --validate-install; on failure, reuse the existing _gpu_fallback_label CPU retry path.
  • Tests + CI: Shell helper/contract tests; Python coverage for env gate and --validate-install; wire into tests/run_all.sh and studio-backend-ci.yml.

Verification

bash -n studio/setup.sh
bash tests/sh/test_staged_validation_enabled.sh
bash tests/sh/test_resolve_cuda_archs.sh
python -m pytest tests/studio/install/test_install_llama_prebuilt_logic.py -k 'staged_validation or validate_existing_install or validate_prebuilt_choice_approved' -q

25 shell assertions + 10 Python tests pass. Default remains off (no Blackwell stall).

Compatibility

Souravrajvi0 and others added 2 commits July 22, 2026 07:41
Gap 1 (empty CUDA arch -> CPU) already landed in unslothai#6481. Wire gap 2: after a
GPU source build, optionally run the same staged llama-server smoke test as
the prebuilt path, then CPU-fallback on failure. Gated by
UNSLOTH_LLAMA_STAGED_VALIDATION (default off) to avoid Blackwell JIT stalls.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@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: 67c99c65a1

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

Comment thread studio/setup.sh Outdated
Comment on lines +258 to +260
case "${UNSLOTH_LLAMA_STAGED_VALIDATION:-}" in
1|true|TRUE|yes|YES|on|ON) return 0 ;;
*) return 1 ;;

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 Normalize the source-smoke opt-in env value

When users opt in with a common environment spelling such as UNSLOTH_LLAMA_STAGED_VALIDATION=True or with surrounding whitespace, the Python helper enables staged validation because it strips and lowercases the value, but this shell gate rejects it and skips the new source-build smoke test. That makes the prebuilt and source-build paths disagree on the same documented opt-in and can still install an unvalidated GPU source build for those values.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 09efc49.

_staged_validation_enabled() now strips whitespace and lowercases UNSLOTH_LLAMA_STAGED_VALIDATION before the truthiness check, matching staged_validation_enabled() in install_llama_prebuilt.py. Values like True and yes now opt in on the source-build path too.

Tests: tests/sh/test_staged_validation_enabled.sh (17 passed, including True and whitespace cases).

…7322)

Strip and lowercase UNSLOTH_LLAMA_STAGED_VALIDATION before the shell
gate so values like True and surrounding whitespace match the Python
staged_validation_enabled() helper.

@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: 09efc490be

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

Comment thread studio/setup.sh
GPU_BACKEND=""
run_quiet_no_exit "build llama-server (cpu fallback)" cmake --build "$_BUILD_TMP/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=false
if [ "$BUILD_OK" = true ]; then
run_quiet_no_exit "build llama-quantize (cpu fallback)" cmake --build "$_BUILD_TMP/build" --config Release --target llama-quantize -j"$NCPU" || true

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 Rebuild visual server after smoke fallback

When UNSLOTH_LLAMA_STAGED_VALIDATION=1 and a CUDA/ROCm/Metal source build compiles but fails the smoke, this fallback deletes _BUILD_TMP/build after the normal best-effort visual-server target was built and then rebuilds only llama-server/llama-quantize. The install swap later links llama-diffusion-gemma-visual-server only if it exists, so DiffusionGemma auto-serving loses the bundled visual runner on this path even though the normal source-build path provides it; please mirror the best-effort visual-server build here as well.

Useful? React with 👍 / 👎.

…#5854)

Mirror the primary source-build path by best-effort building
llama-diffusion-gemma-visual-server after smoke-failure CPU fallback.
@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

Fixed in a06719e.

P2 — Rebuild visual server after smoke fallback: Valid. Staged-validation CPU fallback now best-effort builds llama-diffusion-gemma-visual-server alongside llama-server/llama-quantize, mirroring the primary source-build path.

@Souravrajvi0
Souravrajvi0 marked this pull request as draft July 23, 2026 07:34
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: a06719ed5a

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

@Souravrajvi0
Souravrajvi0 marked this pull request as ready for review July 23, 2026 10:22
@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

Ready for review — undrafted after @danielhanchen's commits on ``. Maintainer changes incorporated; awaiting CI + review.

@danielhanchen

Copy link
Copy Markdown
Member

Reviewed and verified. This adds an opt-in source build GPU smoke validation so a broken source build is caught before use, without forcing the check on users who do not want it. Confirmed the flag defaults off and the validation only runs when explicitly requested. Codex review has no open items. The remaining red CI is pre-existing upstream breakage (Core HF/TRL and Repo tests CPU) unrelated to this change. Good to merge.

@danielhanchen
danielhanchen merged commit 09b6bf6 into unslothai:main Jul 24, 2026
39 of 42 checks passed
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.

studio/setup.sh: validate source-built llama.cpp and guard empty CUDA arch detection

2 participants