Merge pull request #142 from unslothai/feature/wsl-gguf-sudo-fix

fix: skip sudo check on WSL during GGUF export to prevent password pr…
This commit is contained in:
Roland Tannous 2026-02-18 00:46:15 +04:00 committed by GitHub
commit f88f0bc047
2 changed files with 54 additions and 1 deletions

View file

@ -152,8 +152,19 @@ echo " Installing studio dependencies..."
run_quiet "pip install studio" pip install -r "$SCRIPT_DIR/studio/backend/requirements/studio.txt"
echo "✅ Python dependencies installed"
# ── 7. WSL: pre-install GGUF build dependencies ──
# On WSL, sudo requires a password and can't be entered during GGUF export
# (runs in a non-interactive subprocess). Install build deps here instead.
if grep -qi microsoft /proc/version 2>/dev/null; then
echo ""
echo "⚠️ WSL detected — installing build dependencies for GGUF export..."
echo " You may be prompted for your password."
sudo apt-get update -y
sudo apt-get install -y build-essential cmake curl git libcurl4-openssl-dev
echo "✅ GGUF build dependencies installed"
fi
# ── 7. Add shell alias ──
# ── 8. Add shell alias ──
# Note: venv activation does NOT persist across terminal sessions.
# This alias hardcodes the venv python path so users don't need to activate.
echo ""

View file

@ -18,6 +18,45 @@ from core.inference import get_inference_backend
logger = logging.getLogger(__name__)
def _is_wsl():
"""Detect if running under Windows Subsystem for Linux."""
try:
return "microsoft" in open("/proc/version").read().lower()
except Exception:
return False
def _apply_wsl_sudo_patch():
"""On WSL, monkey-patch do_we_need_sudo() to return False.
WSL doesn't have passwordless sudo, and do_we_need_sudo() runs
`sudo apt-get update` which hangs waiting for a stdin password
inside a non-interactive subprocess. setup.sh pre-installs the
build dependencies on WSL, so sudo is not needed at runtime.
"""
if not _is_wsl():
return
try:
import unsloth_zoo.llama_cpp as llama_cpp_module
def _wsl_do_we_need_sudo(system_type="debian"):
logger.info(
"WSL detected — skipping sudo check "
"(build deps pre-installed by setup.sh)"
)
return False
llama_cpp_module.do_we_need_sudo = _wsl_do_we_need_sudo
logger.info(
"Applied WSL sudo patch to "
"unsloth_zoo.llama_cpp.do_we_need_sudo"
)
except Exception as e:
logger.warning(f"Could not apply WSL sudo patch: {e}")
# Model card template
MODEL_CARD = \
"""---
@ -353,6 +392,9 @@ class ExportBackend:
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