Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix GGUF export cwd confusion: remove os.chdir, use absolute paths
Roland Tannous7adb69581e41
diff --git a/setup.sh b/setup.shindex 36165dac65c..0d8821d50a2 100755--- a/setup.sh+++ b/setup.sh@@ -206,10 +206,11 @@ elsefifi-# ── 8. Build llama-server for GGUF inference ──+# ── 8. Build llama.cpp binaries for GGUF inference + export ──# Builds in-tree at $REPO/llama.cpp/. This directory is shared with-# unsloth-zoo's GGUF export pipeline — if converter/quantize are missing,-# unsloth-zoo will rebuild them on first export. We only build llama-server here.+# unsloth-zoo's GGUF export pipeline. We build:+# - llama-server: for GGUF model inference+# - llama-quantize: for GGUF export quantization (symlinked to root for check_llama_cpp())LLAMA_SERVER_BIN="$SCRIPT_DIR/llama.cpp/build/bin/llama-server"if [ -f "$LLAMA_SERVER_BIN" ]; thenecho ""@@ -272,12 +273,25 @@ elserun_quiet "build llama-server" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=falsefi+ # Also build llama-quantize (needed by unsloth-zoo's GGUF export pipeline)+ if [ "$BUILD_OK" = true ]; then+ run_quiet "build llama-quantize" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-quantize -j"$NCPU" || true+ # Symlink to llama.cpp root — check_llama_cpp() looks for the binary there+ QUANTIZE_BIN="$LLAMA_CPP_DIR/build/bin/llama-quantize"+ if [ -f "$QUANTIZE_BIN" ]; then+ ln -sf build/bin/llama-quantize "$LLAMA_CPP_DIR/llama-quantize"+ fi+ fi+if [ "$BUILD_OK" = true ]; thenif [ -f "$LLAMA_SERVER_BIN" ]; thenecho "✅ llama-server built at $LLAMA_SERVER_BIN"elseecho "⚠️ llama-server binary not found after build — GGUF inference won't be available"fi+ if [ -f "$LLAMA_CPP_DIR/llama-quantize" ]; then+ echo "✅ llama-quantize available for GGUF export"+ fielseecho "⚠️ llama-server build failed — GGUF inference won't be available, but everything else works"fidiff --git a/studio/backend/core/export/export.py b/studio/backend/core/export/export.pyindex da5b11c60dd..865900cb65c 100644--- a/studio/backend/core/export/export.py+++ b/studio/backend/core/export/export.py@@ -378,53 +378,33 @@ class ExportBackend:# Save locally if requestedif save_directory:- logger.info(f"Saving GGUF model locally to: {save_directory}")+ # Resolve to absolute path so unsloth's relative-path internals+ # (check_llama_cpp, use_local_gguf, _download_convert_hf_to_gguf)+ # all resolve against the repo root cwd, NOT the export directory.+ abs_save_dir = os.path.abspath(save_directory)+ logger.info(f"Saving GGUF model locally to: {abs_save_dir}")# Create the directory if it doesn't exist- os.makedirs(save_directory, exist_ok=True)-- # Get the base filename for the GGUF file- import shutil- original_dir = os.getcwd()-- try:- # Change to target directory- os.chdir(save_directory)- logger.info(f"Changed directory to: {save_directory}")-- # On WSL, patch out sudo check before llama.cpp build- _apply_wsl_sudo_patch()-- # Now save (will save in current directory)- self.current_model.save_pretrained_gguf(- "model", # Base filename- self.current_tokenizer,- quantization_method=quant_method- )-- logger.info(f"GGUF model saved successfully in {save_directory}")-- # Check if llama.cpp directory was created here- llama_cpp_in_target = os.path.join(save_directory, "llama.cpp")- llama_cpp_in_original = os.path.join(original_dir, "llama.cpp")+ os.makedirs(abs_save_dir, exist_ok=True)- if os.path.exists(llama_cpp_in_target):- logger.info(f"Found llama.cpp directory in {save_directory}")+ # On WSL, patch out sudo check before llama.cpp build+ _apply_wsl_sudo_patch()- # Remove llama.cpp from original directory if it exists- if os.path.exists(llama_cpp_in_original):- logger.info(f"Removing existing llama.cpp in {original_dir}")- shutil.rmtree(llama_cpp_in_original)+ # Enable verbose logging so subprocess errors are printed+ os.environ["UNSLOTH_ENABLE_LOGGING"] = "1"- # Move llama.cpp back to original directory- logger.info(f"Moving llama.cpp to {original_dir}")- shutil.move(llama_cpp_in_target, llama_cpp_in_original)- logger.info(f"Successfully moved llama.cpp back to original directory")+ # Pass absolute path — no os.chdir needed.+ # unsloth saves model files into this directory, while+ # check_llama_cpp("llama.cpp") resolves against cwd (repo root)+ # where setup.sh already built llama.cpp with quantizer.+ model_save_path = os.path.join(abs_save_dir, "model")+ self.current_model.save_pretrained_gguf(+ model_save_path,+ self.current_tokenizer,+ quantization_method=quant_method+ )- finally:- # Always change back to original directory- os.chdir(original_dir)- logger.info(f"Changed back to original directory: {original_dir}")+ logger.info(f"GGUF model saved successfully in {abs_save_dir}")# Push to hub if requestedif push_to_hub: