From c7fd2cf925b915e2a825c9c09826277b47d69b56 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 3 Jun 2026 21:06:43 -0700 Subject: [PATCH] provision_llama_cuda: default to ~half cores (thermal headroom) A full -j(nproc) CUDA build trips power/thermal shutdowns on thermally constrained NVIDIA-ARM laptops (observed on the N1X "RTX Spark": a full-core build, especially alongside other load, shuts the machine down). nice lowers CPU *scheduling* priority but not heat -- power/heat scale with the number of active compile jobs -- so default to ~half the cores instead: still ~2.5x faster than a tiny -j4, but leaves real headroom. Still mem-capped (~1.5 GB per nvcc job) and overridable via UNSLOTH_LLAMA_BUILD_JOBS (raise on a well-cooled box, lower if it still trips). Tiny boxes (<=4 cores) use all. Co-Authored-By: Claude Opus 4.8 --- studio/scripts/provision_llama_cuda.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/studio/scripts/provision_llama_cuda.sh b/studio/scripts/provision_llama_cuda.sh index fea0583fcc..3b11f8749f 100644 --- a/studio/scripts/provision_llama_cuda.sh +++ b/studio/scripts/provision_llama_cuda.sh @@ -130,17 +130,21 @@ if ! _cmake_configure; then fi # Build the full target set unsloth-zoo's GGUF exporter also needs (llama-mtmd-cli, # llama-gguf-split) so one build serves both Studio inference and save_pretrained_gguf. -# Parallelism: all cores by default (-j(nproc) is far faster than a conservative cap), -# but cap at mem/1.5GB when RAM is tight (nvcc uses ~1.5 GB/job) to avoid OOM-kill. -# Override with UNSLOTH_LLAMA_BUILD_JOBS=N. Incremental: a re-run resumes. +# Parallelism default = ~half the cores: much faster than a tiny -j4, but leaves +# thermal/power headroom -- a full -j(nproc) CUDA build trips shutdowns on +# thermally constrained NVIDIA-ARM laptops (e.g. N1X "RTX Spark"). Also cap by RAM +# (~1.5 GB per nvcc job) to avoid OOM. Tune with UNSLOTH_LLAMA_BUILD_JOBS=N (raise +# on a well-cooled box, lower if it still trips). Incremental: a re-run resumes. _ncpu="$(nproc 2>/dev/null || echo 4)" if [ -n "${UNSLOTH_LLAMA_BUILD_JOBS:-}" ]; then JOBS="$UNSLOTH_LLAMA_BUILD_JOBS" else + _half=$(( (_ncpu + 1) / 2 )) # ~half the cores for thermal headroom + if [ "$_ncpu" -le 4 ]; then _half="$_ncpu"; fi # tiny boxes: use all cores _memkb="$(awk '/MemTotal/{print $2}' /proc/meminfo 2>/dev/null || echo 0)" - _memjobs=$(( _memkb / 1572864 )) # 1.5 GB per nvcc job + _memjobs=$(( _memkb / 1572864 )) # 1.5 GB per nvcc job if [ "$_memjobs" -lt 1 ]; then _memjobs=1; fi - JOBS="$_ncpu" + JOBS="$_half" if [ "$_memjobs" -lt "$JOBS" ]; then JOBS="$_memjobs"; fi fi log "building with -j${JOBS} (cores=${_ncpu})"