Skip to content

MLX CI: find llama-cli where save_pretrained_gguf actually installs it - #6777

Merged
danielhanchen merged 3 commits into
mainfrom
fix-mlx-gguf-reload-llama-cli-path
Jul 1, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix-mlx-gguf-reload-llama-cli-path

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The MLX CI on Mac M1 workflow (.github/workflows/mlx-ci.yml) fails on every main commit at the MLX export round-trip - RELOAD GGUF via llama-cli step:

llama-cli not found; checked [PosixPath('llama.cpp/llama-cli'), PosixPath('llama.cpp/build/bin/llama-cli')]

_reload_gguf in tests/studio/run_real_mlx_smoke.py looks for llama-cli at two CWD-relative paths. But save_pretrained_gguf builds and installs llama.cpp under unsloth_zoo's LLAMA_CPP_DEFAULT_DIR, which is $UNSLOTH_LLAMA_CPP_PATH or, by default, ~/.unsloth/llama.cpp (the workflow does not override it). So the binary really lands at ~/.unsloth/llama.cpp/llama-cli, not ./llama.cpp/llama-cli, and the reload can never find it. The export itself succeeds (the quantizer runs from the same install dir), so gguf_supported is true and the step runs and then hard-fails.

Fix

Add _find_llama_cli(), which searches the directory where the binary is actually installed:

  1. $UNSLOTH_LLAMA_CPP_PATH if set,
  2. unsloth_zoo's LLAMA_CPP_DEFAULT_DIR (falls back to ~/.unsloth/llama.cpp if the import is unavailable),
  3. the previous CWD-relative ./llama.cpp,

checking llama-cli and build/bin/llama-cli inside each base directory, with a recursive **/llama-cli glob as a last resort. This is a strict superset of the old two paths, so any layout that already worked keeps working.

Verification

  • python -m py_compile and ruff check pass.
  • Unit-exercised _find_llama_cli against fixtures: binary at the install-dir root, at build/bin, only under the CWD ./llama.cpp (back-compat), and absent-everywhere returning None - all correct.
  • End-to-end validation requires the Mac M1 runner (I cannot build a Metal GGUF here); the change is scoped to the binary-location logic and cannot regress the prior search set.

The GGUF reload step hardcoded the CWD-relative paths llama.cpp/llama-cli and
llama.cpp/build/bin/llama-cli, but save_pretrained_gguf builds and installs llama.cpp
under unsloth_zoo's LLAMA_CPP_DEFAULT_DIR ($UNSLOTH_LLAMA_CPP_PATH, else
~/.unsloth/llama.cpp), so the reload could not find the binary and failed the Mac M1
job with "llama-cli not found". _find_llama_cli now searches that install directory
(and honors the env override) before falling back to the old CWD layout, with a
recursive glob as a last resort. The search is a strict superset of the previous
paths, so it cannot regress a layout that already worked.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function _find_llama_cli to robustly locate the llama-cli binary across multiple potential directories, including environment variables, default paths, and local fallbacks. The feedback suggests returning resolved absolute paths using cand.resolve() to prevent potential FileNotFoundError issues in subprocess.run when relative paths without directory separators are used.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tests/studio/run_real_mlx_smoke.py Outdated
Comment on lines +543 to +544
if cand.is_file() and os.access(cand, os.X_OK):
return cand

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Returning a resolved absolute path using cand.resolve() is safer and more robust. If UNSLOTH_LLAMA_CPP_PATH is set to a relative path (e.g., .), cand will be a relative path without a directory separator (e.g., llama-cli). Passing a relative path without a directory separator to subprocess.run on Unix/macOS causes the OS to search for it in the system PATH rather than the current directory, leading to a FileNotFoundError. Resolving the path to an absolute path avoids this issue entirely.

Suggested change
if cand.is_file() and os.access(cand, os.X_OK):
return cand
if cand.is_file() and os.access(cand, os.X_OK):
return cand.resolve()

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.

Good catch, applied. Both return sites now return cand.resolve() so a relative UNSLOTH_LLAMA_CPP_PATH (e.g. ".") cannot yield a separator-less name that subprocess resolves via PATH. Pushed in 1fce57e.

Comment thread tests/studio/run_real_mlx_smoke.py Outdated
Comment on lines +548 to +549
if cand.is_file() and os.access(cand, os.X_OK):
return cand

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Returning a resolved absolute path using cand.resolve() is safer and more robust. If UNSLOTH_LLAMA_CPP_PATH is set to a relative path (e.g., .), cand will be a relative path without a directory separator (e.g., llama-cli). Passing a relative path without a directory separator to subprocess.run on Unix/macOS causes the OS to search for it in the system PATH rather than the current directory, leading to a FileNotFoundError. Resolving the path to an absolute path avoids this issue entirely.

Suggested change
if cand.is_file() and os.access(cand, os.X_OK):
return cand
if cand.is_file() and os.access(cand, os.X_OK):
return cand.resolve()

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.

Good catch, applied. Both return sites now return cand.resolve() so a relative UNSLOTH_LLAMA_CPP_PATH (e.g. ".") cannot yield a separator-less name that subprocess resolves via PATH. Pushed in 1fce57e.

Resolve the located binary to an absolute path. If UNSLOTH_LLAMA_CPP_PATH is a
relative directory (e.g. "."), Path(".") / "llama-cli" normalizes to the bare name
"llama-cli", and subprocess.run treats a separator-less argument as a PATH lookup
rather than a file to execute, raising FileNotFoundError. resolve() makes the returned
path absolute so it always runs the intended binary.
With the binary now found, the GGUF reload actually invokes llama-cli and it timed
out after 300s generating 24 tokens on a 270m model, which is a stdin block rather
than slow generation: subprocess.run captured stdout/stderr but left stdin inherited,
so -no-cnv still left llama-cli waiting for interactive input. Pass
stdin=subprocess.DEVNULL so it receives an immediate EOF and runs the single prompt to
completion.
@danielhanchen
danielhanchen merged commit bc69dfa into main Jul 1, 2026
22 of 23 checks passed
@danielhanchen
danielhanchen deleted the fix-mlx-gguf-reload-llama-cli-path branch July 1, 2026 07:49
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.

2 participants