Skip to content

Instantly share code, notes, and snippets.

@svngoku
Created May 29, 2026 21:53
Show Gist options
  • Select an option

  • Save svngoku/79f27589f76751d165c520d0a55c264f to your computer and use it in GitHub Desktop.

Select an option

Save svngoku/79f27589f76751d165c520d0a55c264f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
# Unsloth Studio GPU launcher
# Based on the attached Colab notebook:
# 1) clone unsloth
# 2) run studio/setup.sh --local
# 3) start Unsloth Studio on a GPU host
HOST="${HOST:-0.0.0.0}"
PORT="${PORT:-8888}"
REPO_DIR="${REPO_DIR:-$HOME/unsloth}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
START_MODE="${START_MODE:-cli}"
log() {
printf '\n[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
}
need_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "ERROR: required command '$1' not found" >&2
exit 1
}
}
log "Checking required tools"
need_cmd git
need_cmd "$PYTHON_BIN"
if ! command -v nvidia-smi >/dev/null 2>&1; then
echo "ERROR: nvidia-smi not found. This machine does not look GPU-ready." >&2
exit 1
fi
log "GPU status"
nvidia-smi || {
echo "ERROR: NVIDIA GPU is not accessible" >&2
exit 1
}
log "Python version"
"$PYTHON_BIN" --version
if [ ! -d "$REPO_DIR/.git" ]; then
log "Cloning unsloth repository"
git clone --depth 1 --branch main https://github.com/unslothai/unsloth.git "$REPO_DIR"
else
log "Updating existing unsloth repository"
git -C "$REPO_DIR" pull --ff-only
fi
cd "$REPO_DIR"
log "Running studio setup"
chmod +x studio/setup.sh
./studio/setup.sh --local
if [ "$START_MODE" = "colab" ]; then
log "Starting Studio with the Colab backend entrypoint"
export PYTHONPATH="$REPO_DIR/studio/backend:${PYTHONPATH:-}"
exec "$PYTHON_BIN" -c 'from colab import start; start()'
else
log "Starting Studio with the official CLI on ${HOST}:${PORT}"
if command -v unsloth >/dev/null 2>&1; then
exec unsloth studio -H "$HOST" -p "$PORT"
fi
if [ -x "$HOME/.unsloth/bin/unsloth" ]; then
exec "$HOME/.unsloth/bin/unsloth" studio -H "$HOST" -p "$PORT"
fi
if [ -x "$HOME/.local/bin/unsloth" ]; then
exec "$HOME/.local/bin/unsloth" studio -H "$HOST" -p "$PORT"
fi
echo "ERROR: could not find the 'unsloth' CLI after setup." >&2
echo "Try opening a new shell, or locate it with: find \$HOME -type f -name unsloth 2>/dev/null | head" >&2
exit 1
fi
@svngoku

svngoku commented May 29, 2026

Copy link
Copy Markdown
Author

chmod +x launch_unsloth_studio_gpu.sh
./launch_unsloth_studio_gpu.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment