Repository navigation
MLX CI: find llama-cli where save_pretrained_gguf actually installs it - #6777
Conversation
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.
There was a problem hiding this comment.
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.
| if cand.is_file() and os.access(cand, os.X_OK): | ||
| return cand |
There was a problem hiding this comment.
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.
| 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() |
There was a problem hiding this comment.
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.
| if cand.is_file() and os.access(cand, os.X_OK): | ||
| return cand |
There was a problem hiding this comment.
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.
| 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() |
There was a problem hiding this comment.
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.
Problem
The
MLX CI on Mac M1workflow (.github/workflows/mlx-ci.yml) fails on every main commit at theMLX export round-trip - RELOAD GGUF via llama-clistep:_reload_ggufintests/studio/run_real_mlx_smoke.pylooks forllama-cliat two CWD-relative paths. Butsave_pretrained_ggufbuilds and installs llama.cpp under unsloth_zoo'sLLAMA_CPP_DEFAULT_DIR, which is$UNSLOTH_LLAMA_CPP_PATHor, 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), sogguf_supportedis true and the step runs and then hard-fails.Fix
Add
_find_llama_cli(), which searches the directory where the binary is actually installed:$UNSLOTH_LLAMA_CPP_PATHif set,LLAMA_CPP_DEFAULT_DIR(falls back to~/.unsloth/llama.cppif the import is unavailable),./llama.cpp,checking
llama-cliandbuild/bin/llama-cliinside each base directory, with a recursive**/llama-cliglob 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_compileandruff checkpass._find_llama_cliagainst fixtures: binary at the install-dir root, atbuild/bin, only under the CWD./llama.cpp(back-compat), and absent-everywhere returningNone- all correct.