Compare commits
4 commits
main
...
feature/do
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91e90a256c | ||
|
|
40c5b86005 | ||
|
|
9e8b87a0fe | ||
|
|
f81fdba8dc |
10 changed files with 190 additions and 151 deletions
|
|
@ -12,7 +12,18 @@ import typer
|
||||||
|
|
||||||
studio_app = typer.Typer(help = "Unsloth Studio commands.")
|
studio_app = typer.Typer(help = "Unsloth Studio commands.")
|
||||||
|
|
||||||
STUDIO_HOME = Path.home() / ".unsloth" / "studio"
|
|
||||||
|
def _studio_home() -> Path:
|
||||||
|
"""Studio root: env var > config file > default."""
|
||||||
|
custom = os.environ.get("UNSLOTH_STUDIO_HOME")
|
||||||
|
if custom:
|
||||||
|
return Path(custom).expanduser().resolve()
|
||||||
|
conf = Path.home() / ".unsloth" / "studio_home"
|
||||||
|
if conf.is_file():
|
||||||
|
saved = conf.read_text().strip()
|
||||||
|
if saved:
|
||||||
|
return Path(saved).expanduser().resolve()
|
||||||
|
return Path.home() / ".unsloth" / "studio"
|
||||||
|
|
||||||
# __file__ is cli/commands/studio.py — two parents up is the package root
|
# __file__ is cli/commands/studio.py — two parents up is the package root
|
||||||
# (either site-packages or the repo root for editable installs).
|
# (either site-packages or the repo root for editable installs).
|
||||||
|
|
@ -22,9 +33,9 @@ _PACKAGE_ROOT = Path(__file__).resolve().parent.parent.parent
|
||||||
def _studio_venv_python() -> Optional[Path]:
|
def _studio_venv_python() -> Optional[Path]:
|
||||||
"""Return the studio venv Python binary, or None if not set up."""
|
"""Return the studio venv Python binary, or None if not set up."""
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
p = STUDIO_HOME / ".venv" / "Scripts" / "python.exe"
|
p = _studio_home() / ".venv" / "Scripts" / "python.exe"
|
||||||
else:
|
else:
|
||||||
p = STUDIO_HOME / ".venv" / "bin" / "python"
|
p = _studio_home() / ".venv" / "bin" / "python"
|
||||||
return p if p.is_file() else None
|
return p if p.is_file() else None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,7 +55,7 @@ def _find_run_py() -> Optional[Path]:
|
||||||
"lib/python*/site-packages/studio/backend/run.py",
|
"lib/python*/site-packages/studio/backend/run.py",
|
||||||
"Lib/site-packages/studio/backend/run.py",
|
"Lib/site-packages/studio/backend/run.py",
|
||||||
):
|
):
|
||||||
for match in (STUDIO_HOME / ".venv").glob(pattern):
|
for match in (_studio_home() / ".venv").glob(pattern):
|
||||||
return match
|
return match
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -64,7 +75,7 @@ def _find_setup_script() -> Optional[Path]:
|
||||||
f"lib/python*/site-packages/studio/{name}",
|
f"lib/python*/site-packages/studio/{name}",
|
||||||
f"Lib/site-packages/studio/{name}",
|
f"Lib/site-packages/studio/{name}",
|
||||||
):
|
):
|
||||||
for match in (STUDIO_HOME / ".venv").glob(pattern):
|
for match in (_studio_home() / ".venv").glob(pattern):
|
||||||
return match
|
return match
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -85,7 +96,7 @@ def studio_default(
|
||||||
return
|
return
|
||||||
|
|
||||||
# Always use the studio venv if it exists and we're not already in it
|
# Always use the studio venv if it exists and we're not already in it
|
||||||
studio_venv_dir = STUDIO_HOME / ".venv"
|
studio_venv_dir = _studio_home() / ".venv"
|
||||||
in_studio_venv = sys.prefix.startswith(str(studio_venv_dir))
|
in_studio_venv = sys.prefix.startswith(str(studio_venv_dir))
|
||||||
|
|
||||||
if not in_studio_venv:
|
if not in_studio_venv:
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,8 @@ def _activate_transformers_version(model_name: str) -> None:
|
||||||
|
|
||||||
resolved = _resolve_base_model(model_name)
|
resolved = _resolve_base_model(model_name)
|
||||||
if needs_transformers_5(resolved):
|
if needs_transformers_5(resolved):
|
||||||
venv_t5 = os.path.join(
|
from utils.paths.storage_roots import venv_t5_root
|
||||||
os.path.expanduser("~"), ".unsloth", "studio", ".venv_t5"
|
venv_t5 = str(venv_t5_root())
|
||||||
)
|
|
||||||
if os.path.isdir(venv_t5):
|
if os.path.isdir(venv_t5):
|
||||||
sys.path.insert(0, venv_t5)
|
sys.path.insert(0, venv_t5)
|
||||||
logger.info("Activated transformers 5.x from %s", venv_t5)
|
logger.info("Activated transformers 5.x from %s", venv_t5)
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,8 @@ def _activate_transformers_version(model_name: str) -> None:
|
||||||
|
|
||||||
resolved = _resolve_base_model(model_name)
|
resolved = _resolve_base_model(model_name)
|
||||||
if needs_transformers_5(resolved):
|
if needs_transformers_5(resolved):
|
||||||
venv_t5 = os.path.join(
|
from utils.paths.storage_roots import venv_t5_root
|
||||||
os.path.expanduser("~"), ".unsloth", "studio", ".venv_t5"
|
venv_t5 = str(venv_t5_root())
|
||||||
)
|
|
||||||
if os.path.isdir(venv_t5):
|
if os.path.isdir(venv_t5):
|
||||||
sys.path.insert(0, venv_t5)
|
sys.path.insert(0, venv_t5)
|
||||||
logger.info("Activated transformers 5.x from %s", venv_t5)
|
logger.info("Activated transformers 5.x from %s", venv_t5)
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,8 @@ def _activate_transformers_version(model_name: str) -> None:
|
||||||
|
|
||||||
resolved = _resolve_base_model(model_name)
|
resolved = _resolve_base_model(model_name)
|
||||||
if needs_transformers_5(resolved):
|
if needs_transformers_5(resolved):
|
||||||
venv_t5 = os.path.join(
|
from utils.paths.storage_roots import venv_t5_root
|
||||||
os.path.expanduser("~"), ".unsloth", "studio", ".venv_t5"
|
venv_t5 = str(venv_t5_root())
|
||||||
)
|
|
||||||
if os.path.isdir(venv_t5):
|
if os.path.isdir(venv_t5):
|
||||||
sys.path.insert(0, venv_t5)
|
sys.path.insert(0, venv_t5)
|
||||||
logger.info("Activated transformers 5.x from %s", venv_t5)
|
logger.info("Activated transformers 5.x from %s", venv_t5)
|
||||||
|
|
|
||||||
|
|
@ -427,7 +427,8 @@ _VLM_MODEL_TYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Pre-computed .venv_t5 path and backend dir for subprocess version switching.
|
# Pre-computed .venv_t5 path and backend dir for subprocess version switching.
|
||||||
_VENV_T5_DIR = str(Path.home() / ".unsloth" / "studio" / ".venv_t5")
|
from utils.paths.storage_roots import venv_t5_root
|
||||||
|
_VENV_T5_DIR = str(venv_t5_root())
|
||||||
_BACKEND_DIR = str(Path(__file__).resolve().parent.parent.parent)
|
_BACKEND_DIR = str(Path(__file__).resolve().parent.parent.parent)
|
||||||
|
|
||||||
# Inline script executed in a subprocess with transformers 5.x activated.
|
# Inline script executed in a subprocess with transformers 5.x activated.
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ Path utilities for model and dataset handling
|
||||||
from .path_utils import normalize_path, is_local_path, is_model_cached, get_cache_path
|
from .path_utils import normalize_path, is_local_path, is_model_cached, get_cache_path
|
||||||
from .storage_roots import (
|
from .storage_roots import (
|
||||||
studio_root,
|
studio_root,
|
||||||
|
venv_t5_root,
|
||||||
assets_root,
|
assets_root,
|
||||||
datasets_root,
|
datasets_root,
|
||||||
dataset_uploads_root,
|
dataset_uploads_root,
|
||||||
|
|
@ -36,6 +37,7 @@ __all__ = [
|
||||||
"is_model_cached",
|
"is_model_cached",
|
||||||
"get_cache_path",
|
"get_cache_path",
|
||||||
"studio_root",
|
"studio_root",
|
||||||
|
"venv_t5_root",
|
||||||
"assets_root",
|
"assets_root",
|
||||||
"datasets_root",
|
"datasets_root",
|
||||||
"dataset_uploads_root",
|
"dataset_uploads_root",
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,26 @@ import tempfile
|
||||||
|
|
||||||
|
|
||||||
def studio_root() -> Path:
|
def studio_root() -> Path:
|
||||||
|
"""Studio root: env var > config file > default."""
|
||||||
|
custom = os.environ.get("UNSLOTH_STUDIO_HOME")
|
||||||
|
if custom:
|
||||||
|
return Path(custom).expanduser().resolve()
|
||||||
|
conf = Path.home() / ".unsloth" / "studio_home"
|
||||||
|
if conf.is_file():
|
||||||
|
saved = conf.read_text().strip()
|
||||||
|
if saved:
|
||||||
|
return Path(saved).expanduser().resolve()
|
||||||
return Path.home() / ".unsloth" / "studio"
|
return Path.home() / ".unsloth" / "studio"
|
||||||
|
|
||||||
|
|
||||||
|
def venv_t5_root() -> Path:
|
||||||
|
"""Pre-installed transformers 5.x directory, respects UNSLOTH_STUDIO_HOME."""
|
||||||
|
return studio_root() / ".venv_t5"
|
||||||
|
|
||||||
|
|
||||||
def cache_root() -> Path:
|
def cache_root() -> Path:
|
||||||
"""Central cache directory for all studio downloads (models, datasets, etc.)."""
|
"""Central cache directory for all studio downloads (models, datasets, etc.)."""
|
||||||
return Path.home() / ".unsloth" / "studio" / "cache"
|
return studio_root() / "cache"
|
||||||
|
|
||||||
|
|
||||||
def assets_root() -> Path:
|
def assets_root() -> Path:
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,8 @@ TRANSFORMERS_5_VERSION = "5.3.0"
|
||||||
TRANSFORMERS_DEFAULT_VERSION = "4.57.1"
|
TRANSFORMERS_DEFAULT_VERSION = "4.57.1"
|
||||||
|
|
||||||
# Pre-installed directory for transformers 5.x — created by setup.sh / setup.ps1
|
# Pre-installed directory for transformers 5.x — created by setup.sh / setup.ps1
|
||||||
_VENV_T5_DIR = str(Path.home() / ".unsloth" / "studio" / ".venv_t5")
|
from utils.paths.storage_roots import venv_t5_root
|
||||||
|
_VENV_T5_DIR = str(venv_t5_root())
|
||||||
|
|
||||||
|
|
||||||
def _resolve_base_model(model_name: str) -> str:
|
def _resolve_base_model(model_name: str) -> str:
|
||||||
|
|
|
||||||
|
|
@ -826,9 +826,14 @@ if (-not $PythonCmd) {
|
||||||
|
|
||||||
Write-Host "[OK] Using $PythonCmd ($(& $PythonCmd --version 2>&1))" -ForegroundColor Green
|
Write-Host "[OK] Using $PythonCmd ($(& $PythonCmd --version 2>&1))" -ForegroundColor Green
|
||||||
|
|
||||||
# Always create a .venv for isolation -- even for pip installs.
|
# ── Studio home (configurable via UNSLOTH_STUDIO_HOME) ──
|
||||||
# Created in the repo root (parent of studio/).
|
$StudioHome = if ($env:UNSLOTH_STUDIO_HOME) { $env:UNSLOTH_STUDIO_HOME } else { Join-Path $env:USERPROFILE ".unsloth\studio" }
|
||||||
$VenvDir = Join-Path $env:USERPROFILE ".unsloth\studio\.venv"
|
# Persist for future `unsloth studio` runs (survives shell restarts)
|
||||||
|
$UnslothDir = Join-Path $env:USERPROFILE ".unsloth"
|
||||||
|
if (-not (Test-Path $UnslothDir)) { New-Item -ItemType Directory -Path $UnslothDir -Force | Out-Null }
|
||||||
|
Set-Content -Path (Join-Path $UnslothDir "studio_home") -Value $StudioHome -NoNewline
|
||||||
|
|
||||||
|
$VenvDir = Join-Path $StudioHome ".venv"
|
||||||
if (-not (Test-Path $VenvDir)) {
|
if (-not (Test-Path $VenvDir)) {
|
||||||
Write-Host " Creating virtual environment at $VenvDir..." -ForegroundColor Cyan
|
Write-Host " Creating virtual environment at $VenvDir..." -ForegroundColor Cyan
|
||||||
& $PythonCmd -m venv $VenvDir
|
& $PythonCmd -m venv $VenvDir
|
||||||
|
|
@ -901,7 +906,7 @@ $ErrorActionPreference = $prevEAP
|
||||||
# The training subprocess just prepends .venv_t5/ to sys.path — instant switch.
|
# The training subprocess just prepends .venv_t5/ to sys.path — instant switch.
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " Pre-installing transformers 5.x for newer model support..." -ForegroundColor Cyan
|
Write-Host " Pre-installing transformers 5.x for newer model support..." -ForegroundColor Cyan
|
||||||
$VenvT5Dir = Join-Path $env:USERPROFILE ".unsloth\studio\.venv_t5"
|
$VenvT5Dir = Join-Path $StudioHome ".venv_t5"
|
||||||
if (Test-Path $VenvT5Dir) { Remove-Item -Recurse -Force $VenvT5Dir }
|
if (Test-Path $VenvT5Dir) { Remove-Item -Recurse -Force $VenvT5Dir }
|
||||||
New-Item -ItemType Directory -Path $VenvT5Dir -Force | Out-Null
|
New-Item -ItemType Directory -Path $VenvT5Dir -Force | Out-Null
|
||||||
$prevEAP_t5 = $ErrorActionPreference
|
$prevEAP_t5 = $ErrorActionPreference
|
||||||
|
|
|
||||||
266
studio/setup.sh
266
studio/setup.sh
|
|
@ -227,8 +227,13 @@ if [ "$IS_COLAB" = true ]; then
|
||||||
# Colab: install packages directly without venv
|
# Colab: install packages directly without venv
|
||||||
install_python_stack
|
install_python_stack
|
||||||
else
|
else
|
||||||
# Local: create venv under ~/.unsloth/studio/ (shared location, not in repo)
|
# Local: create venv under studio home (shared location, not in repo)
|
||||||
STUDIO_HOME="$HOME/.unsloth/studio"
|
# Configurable via UNSLOTH_STUDIO_HOME; defaults to ~/.unsloth/studio
|
||||||
|
STUDIO_HOME="${UNSLOTH_STUDIO_HOME:-$HOME/.unsloth/studio}"
|
||||||
|
echo " Studio home: $STUDIO_HOME"
|
||||||
|
# Persist for future `unsloth studio` runs (survives shell restarts)
|
||||||
|
mkdir -p "$HOME/.unsloth"
|
||||||
|
echo "$STUDIO_HOME" > "$HOME/.unsloth/studio_home"
|
||||||
VENV_DIR="$STUDIO_HOME/.venv"
|
VENV_DIR="$STUDIO_HOME/.venv"
|
||||||
VENV_T5_DIR="$STUDIO_HOME/.venv_t5"
|
VENV_T5_DIR="$STUDIO_HOME/.venv_t5"
|
||||||
mkdir -p "$STUDIO_HOME"
|
mkdir -p "$STUDIO_HOME"
|
||||||
|
|
@ -270,133 +275,136 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── 8. Build llama.cpp binaries for GGUF inference + export ──
|
# ── 8. Build llama.cpp binaries for GGUF inference + export ──
|
||||||
# Builds at ~/.unsloth/llama.cpp — a single shared location under the user's
|
# Disabled: llama.cpp build is commented out for now.
|
||||||
# home directory. This is used by both the inference server and the GGUF
|
# UNCOMMENT the block below to re-enable.
|
||||||
# export pipeline (unsloth-zoo).
|
#
|
||||||
# - llama-server: for GGUF model inference
|
# # Builds at ~/.unsloth/llama.cpp — a single shared location under the user's
|
||||||
# - llama-quantize: for GGUF export quantization (symlinked to root for check_llama_cpp())
|
# # home directory. This is used by both the inference server and the GGUF
|
||||||
UNSLOTH_HOME="$HOME/.unsloth"
|
# # export pipeline (unsloth-zoo).
|
||||||
mkdir -p "$UNSLOTH_HOME"
|
# # - llama-server: for GGUF model inference
|
||||||
LLAMA_CPP_DIR="$UNSLOTH_HOME/llama.cpp"
|
# # - llama-quantize: for GGUF export quantization (symlinked to root for check_llama_cpp())
|
||||||
LLAMA_SERVER_BIN="$LLAMA_CPP_DIR/build/bin/llama-server"
|
# UNSLOTH_HOME="$HOME/.unsloth"
|
||||||
rm -rf "$LLAMA_CPP_DIR"
|
# mkdir -p "$UNSLOTH_HOME"
|
||||||
{
|
# LLAMA_CPP_DIR="$UNSLOTH_HOME/llama.cpp"
|
||||||
# Check prerequisites
|
# LLAMA_SERVER_BIN="$LLAMA_CPP_DIR/build/bin/llama-server"
|
||||||
if ! command -v cmake &>/dev/null; then
|
# rm -rf "$LLAMA_CPP_DIR"
|
||||||
echo ""
|
# {
|
||||||
echo "⚠️ cmake not found — skipping llama-server build (GGUF inference won't be available)"
|
# # Check prerequisites
|
||||||
echo " Install cmake and re-run setup.sh to enable GGUF inference."
|
# if ! command -v cmake &>/dev/null; then
|
||||||
elif ! command -v git &>/dev/null; then
|
# echo ""
|
||||||
echo ""
|
# echo "⚠️ cmake not found — skipping llama-server build (GGUF inference won't be available)"
|
||||||
echo "⚠️ git not found — skipping llama-server build (GGUF inference won't be available)"
|
# echo " Install cmake and re-run setup.sh to enable GGUF inference."
|
||||||
else
|
# elif ! command -v git &>/dev/null; then
|
||||||
echo ""
|
# echo ""
|
||||||
echo "Building llama-server for GGUF inference..."
|
# echo "⚠️ git not found — skipping llama-server build (GGUF inference won't be available)"
|
||||||
|
# else
|
||||||
BUILD_OK=true
|
# echo ""
|
||||||
run_quiet "clone llama.cpp" git clone --depth 1 https://github.com/ggml-org/llama.cpp.git "$LLAMA_CPP_DIR" || BUILD_OK=false
|
# echo "Building llama-server for GGUF inference..."
|
||||||
|
#
|
||||||
if [ "$BUILD_OK" = true ]; then
|
# BUILD_OK=true
|
||||||
# Skip tests/examples we don't need (faster build)
|
# run_quiet "clone llama.cpp" git clone --depth 1 https://github.com/ggml-org/llama.cpp.git "$LLAMA_CPP_DIR" || BUILD_OK=false
|
||||||
CMAKE_ARGS="-DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_NATIVE=ON"
|
#
|
||||||
|
# if [ "$BUILD_OK" = true ]; then
|
||||||
# Use ccache if available (dramatically faster rebuilds)
|
# # Skip tests/examples we don't need (faster build)
|
||||||
if command -v ccache &>/dev/null; then
|
# CMAKE_ARGS="-DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_NATIVE=ON"
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache"
|
#
|
||||||
echo " Using ccache for faster compilation"
|
# # Use ccache if available (dramatically faster rebuilds)
|
||||||
fi
|
# if command -v ccache &>/dev/null; then
|
||||||
|
# CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache"
|
||||||
# Detect CUDA: check nvcc on PATH, then common install locations
|
# echo " Using ccache for faster compilation"
|
||||||
NVCC_PATH=""
|
# fi
|
||||||
if command -v nvcc &>/dev/null; then
|
#
|
||||||
NVCC_PATH="$(command -v nvcc)"
|
# # Detect CUDA: check nvcc on PATH, then common install locations
|
||||||
elif [ -x /usr/local/cuda/bin/nvcc ]; then
|
# NVCC_PATH=""
|
||||||
NVCC_PATH="/usr/local/cuda/bin/nvcc"
|
# if command -v nvcc &>/dev/null; then
|
||||||
export PATH="/usr/local/cuda/bin:$PATH"
|
# NVCC_PATH="$(command -v nvcc)"
|
||||||
elif ls /usr/local/cuda-*/bin/nvcc &>/dev/null 2>&1; then
|
# elif [ -x /usr/local/cuda/bin/nvcc ]; then
|
||||||
# Pick the newest cuda-XX.X directory
|
# NVCC_PATH="/usr/local/cuda/bin/nvcc"
|
||||||
NVCC_PATH="$(ls -d /usr/local/cuda-*/bin/nvcc 2>/dev/null | sort -V | tail -1)"
|
# export PATH="/usr/local/cuda/bin:$PATH"
|
||||||
export PATH="$(dirname "$NVCC_PATH"):$PATH"
|
# elif ls /usr/local/cuda-*/bin/nvcc &>/dev/null 2>&1; then
|
||||||
fi
|
# # Pick the newest cuda-XX.X directory
|
||||||
|
# NVCC_PATH="$(ls -d /usr/local/cuda-*/bin/nvcc 2>/dev/null | sort -V | tail -1)"
|
||||||
if [ -n "$NVCC_PATH" ]; then
|
# export PATH="$(dirname "$NVCC_PATH"):$PATH"
|
||||||
echo " Building with CUDA support (nvcc: $NVCC_PATH)..."
|
# fi
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DGGML_CUDA=ON"
|
#
|
||||||
|
# if [ -n "$NVCC_PATH" ]; then
|
||||||
# Detect GPU compute capability and limit CUDA architectures
|
# echo " Building with CUDA support (nvcc: $NVCC_PATH)..."
|
||||||
# Without this, cmake builds for ALL default archs (very slow)
|
# CMAKE_ARGS="$CMAKE_ARGS -DGGML_CUDA=ON"
|
||||||
CUDA_ARCHS=""
|
#
|
||||||
if command -v nvidia-smi &>/dev/null; then
|
# # Detect GPU compute capability and limit CUDA architectures
|
||||||
# Read all GPUs, deduplicate (handles mixed-GPU hosts)
|
# # Without this, cmake builds for ALL default archs (very slow)
|
||||||
_raw_caps=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null || true)
|
# CUDA_ARCHS=""
|
||||||
while IFS= read -r _cap; do
|
# if command -v nvidia-smi &>/dev/null; then
|
||||||
_cap=$(echo "$_cap" | tr -d '[:space:]')
|
# # Read all GPUs, deduplicate (handles mixed-GPU hosts)
|
||||||
if [[ "$_cap" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
|
# _raw_caps=$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null || true)
|
||||||
_arch="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
|
# while IFS= read -r _cap; do
|
||||||
# Append if not already present
|
# _cap=$(echo "$_cap" | tr -d '[:space:]')
|
||||||
case ";$CUDA_ARCHS;" in
|
# if [[ "$_cap" =~ ^([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
*";$_arch;"*) ;;
|
# _arch="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
|
||||||
*) CUDA_ARCHS="${CUDA_ARCHS:+$CUDA_ARCHS;}$_arch" ;;
|
# # Append if not already present
|
||||||
esac
|
# case ";$CUDA_ARCHS;" in
|
||||||
fi
|
# *";$_arch;"*) ;;
|
||||||
done <<< "$_raw_caps"
|
# *) CUDA_ARCHS="${CUDA_ARCHS:+$CUDA_ARCHS;}$_arch" ;;
|
||||||
fi
|
# esac
|
||||||
|
# fi
|
||||||
if [ -n "$CUDA_ARCHS" ]; then
|
# done <<< "$_raw_caps"
|
||||||
echo " GPU compute capabilities: ${CUDA_ARCHS//;/, } -- limiting build to detected archs"
|
# fi
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHS}"
|
#
|
||||||
else
|
# if [ -n "$CUDA_ARCHS" ]; then
|
||||||
echo " Could not detect GPU arch -- building for all default CUDA architectures (slower)"
|
# echo " GPU compute capabilities: ${CUDA_ARCHS//;/, } -- limiting build to detected archs"
|
||||||
fi
|
# CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHS}"
|
||||||
|
# else
|
||||||
# Multi-threaded nvcc compilation (uses all CPU cores per .cu file)
|
# echo " Could not detect GPU arch -- building for all default CUDA architectures (slower)"
|
||||||
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CUDA_FLAGS=--threads=0"
|
# fi
|
||||||
elif [ -d /usr/local/cuda ] || nvidia-smi &>/dev/null; then
|
#
|
||||||
echo " CUDA driver detected but nvcc not found — building CPU-only"
|
# # Multi-threaded nvcc compilation (uses all CPU cores per .cu file)
|
||||||
echo " To enable GPU: install cuda-toolkit or add nvcc to PATH"
|
# CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CUDA_FLAGS=--threads=0"
|
||||||
else
|
# elif [ -d /usr/local/cuda ] || nvidia-smi &>/dev/null; then
|
||||||
echo " Building CPU-only (no CUDA detected)..."
|
# echo " CUDA driver detected but nvcc not found — building CPU-only"
|
||||||
fi
|
# echo " To enable GPU: install cuda-toolkit or add nvcc to PATH"
|
||||||
|
# else
|
||||||
NCPU=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
# echo " Building CPU-only (no CUDA detected)..."
|
||||||
|
# fi
|
||||||
# Use Ninja if available (faster parallel builds than Make)
|
#
|
||||||
CMAKE_GENERATOR_ARGS=""
|
# NCPU=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
||||||
if command -v ninja &>/dev/null; then
|
#
|
||||||
CMAKE_GENERATOR_ARGS="-G Ninja"
|
# # Use Ninja if available (faster parallel builds than Make)
|
||||||
fi
|
# CMAKE_GENERATOR_ARGS=""
|
||||||
|
# if command -v ninja &>/dev/null; then
|
||||||
run_quiet "cmake llama.cpp" cmake $CMAKE_GENERATOR_ARGS -S "$LLAMA_CPP_DIR" -B "$LLAMA_CPP_DIR/build" $CMAKE_ARGS || BUILD_OK=false
|
# CMAKE_GENERATOR_ARGS="-G Ninja"
|
||||||
fi
|
# fi
|
||||||
|
#
|
||||||
if [ "$BUILD_OK" = true ]; then
|
# run_quiet "cmake llama.cpp" cmake $CMAKE_GENERATOR_ARGS -S "$LLAMA_CPP_DIR" -B "$LLAMA_CPP_DIR/build" $CMAKE_ARGS || BUILD_OK=false
|
||||||
run_quiet "build llama-server" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=false
|
# fi
|
||||||
fi
|
#
|
||||||
|
# if [ "$BUILD_OK" = true ]; then
|
||||||
# Also build llama-quantize (needed by unsloth-zoo's GGUF export pipeline)
|
# run_quiet "build llama-server" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-server -j"$NCPU" || BUILD_OK=false
|
||||||
if [ "$BUILD_OK" = true ]; then
|
# fi
|
||||||
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
|
# # Also build llama-quantize (needed by unsloth-zoo's GGUF export pipeline)
|
||||||
QUANTIZE_BIN="$LLAMA_CPP_DIR/build/bin/llama-quantize"
|
# if [ "$BUILD_OK" = true ]; then
|
||||||
if [ -f "$QUANTIZE_BIN" ]; then
|
# run_quiet "build llama-quantize" cmake --build "$LLAMA_CPP_DIR/build" --config Release --target llama-quantize -j"$NCPU" || true
|
||||||
ln -sf build/bin/llama-quantize "$LLAMA_CPP_DIR/llama-quantize"
|
# # Symlink to llama.cpp root — check_llama_cpp() looks for the binary there
|
||||||
fi
|
# QUANTIZE_BIN="$LLAMA_CPP_DIR/build/bin/llama-quantize"
|
||||||
fi
|
# if [ -f "$QUANTIZE_BIN" ]; then
|
||||||
|
# ln -sf build/bin/llama-quantize "$LLAMA_CPP_DIR/llama-quantize"
|
||||||
if [ "$BUILD_OK" = true ]; then
|
# fi
|
||||||
if [ -f "$LLAMA_SERVER_BIN" ]; then
|
# fi
|
||||||
echo "✅ llama-server built at $LLAMA_SERVER_BIN"
|
#
|
||||||
else
|
# if [ "$BUILD_OK" = true ]; then
|
||||||
echo "⚠️ llama-server binary not found after build — GGUF inference won't be available"
|
# if [ -f "$LLAMA_SERVER_BIN" ]; then
|
||||||
fi
|
# echo "✅ llama-server built at $LLAMA_SERVER_BIN"
|
||||||
if [ -f "$LLAMA_CPP_DIR/llama-quantize" ]; then
|
# else
|
||||||
echo "✅ llama-quantize available for GGUF export"
|
# echo "⚠️ llama-server binary not found after build — GGUF inference won't be available"
|
||||||
fi
|
# fi
|
||||||
else
|
# if [ -f "$LLAMA_CPP_DIR/llama-quantize" ]; then
|
||||||
echo "⚠️ llama-server build failed — GGUF inference won't be available, but everything else works"
|
# echo "✅ llama-quantize available for GGUF export"
|
||||||
fi
|
# fi
|
||||||
fi
|
# else
|
||||||
}
|
# echo "⚠️ llama-server build failed — GGUF inference won't be available, but everything else works"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
# }
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
if [ "$IS_COLAB" = true ]; then
|
if [ "$IS_COLAB" = true ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue