Skip to content

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.

Installers (ROCm on WSL): no empty LD_LIBRARY_PATH entry in the profile drop-in (#14433)

Daniel Han8f3d1c01e6c5
diff --git a/install.sh b/install.sh
index af5488b8c39..b5b3d244a09 100755
--- a/install.sh
+++ b/install.sh
@@ -6671,6 +6671,14 @@ _radeon_torch_compiles_for_pytag() {
# ── ROCm-on-WSL bootstrap for AMD Strix Halo (gfx1151) ───────────────────────
# Idempotent, no-op without librocdxg, best-effort; sudo-tee when not root.
+_rocm_wsl_dropin_stale() {
+ grep -qF 'lib:${LD_LIBRARY_PATH:-}' /etc/profile.d/unsloth-rocm-wsl.sh 2>/dev/null
+}
+# The helper pinned by _ROCM_WSL_HELPER_REF can predate the fix and leave the old line in ~/.bashrc.
+_repair_rocm_wsl_bashrc() {
+ [ -n "${HOME:-}" ] && grep -qF 'lib:${LD_LIBRARY_PATH:-}' "${HOME}/.bashrc" 2>/dev/null || return 0
+ sed --follow-symlinks -i '/^# >>> Unsloth ROCm-on-WSL/,/^# <<< Unsloth ROCm-on-WSL/ s#lib:\${LD_LIBRARY_PATH:-}#lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}#' "${HOME}/.bashrc" 2>/dev/null || true
+}
_persist_rocm_wsl_dropin() {
[ -e /opt/rocm/lib/librocdxg.so ] || [ -e /opt/rocm/lib64/librocdxg.so ] || return 0
_rw_rocm=/opt/rocm
@@ -6679,13 +6687,23 @@ _persist_rocm_wsl_dropin() {
*":${_rw_rocm}/bin:"*) ;;
*) export PATH="${_rw_rocm}/bin:${PATH}" ;;
esac
- export LD_LIBRARY_PATH="${_rw_rocm}/lib:${LD_LIBRARY_PATH:-}"
- [ -r /etc/profile.d/unsloth-rocm-wsl.sh ] && return 0
+ export LD_LIBRARY_PATH="${_rw_rocm}/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
+ if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ]; then
+ _rocm_wsl_dropin_stale || return 0
+ # An older drop-in left a trailing ':' (the cwd) on an empty LD_LIBRARY_PATH: fix that line, keep the rest.
+ _rw_fix='s#lib:\${LD_LIBRARY_PATH:-}#lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}#'
+ if [ "$(id -u)" = "0" ]; then
+ sed --follow-symlinks -i "$_rw_fix" /etc/profile.d/unsloth-rocm-wsl.sh 2>/dev/null || true
+ elif command -v sudo >/dev/null 2>&1; then
+ sudo sed --follow-symlinks -i "$_rw_fix" /etc/profile.d/unsloth-rocm-wsl.sh >/dev/null 2>&1 || true
+ fi
+ return 0
+ fi
_rw_dropin="$(
printf '# >>> Unsloth ROCm-on-WSL (gfx1151) >>>\n'
printf 'export HSA_ENABLE_DXG_DETECTION=1\n'
printf 'export PATH="%s/bin:${PATH}"\n' "${_rw_rocm}"
- printf 'export LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\n' "${_rw_rocm}"
+ printf 'export LD_LIBRARY_PATH="%s/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"\n' "${_rw_rocm}"
printf '# <<< Unsloth ROCm-on-WSL (gfx1151) <<<\n'
)"
if [ "$(id -u)" = "0" ]; then
@@ -6705,6 +6723,7 @@ _maybe_bootstrap_rocm_wsl() {
if command -v rocminfo >/dev/null 2>&1 && \
rocminfo 2>/dev/null | awk '/Name:[[:space:]]*gfx[1-9]/ && !/generic/{found=1} END{exit !found}'; then
_persist_rocm_wsl_dropin
+ _repair_rocm_wsl_bashrc
return 0
fi
# WSL GPU passthrough device must exist (present on any WSL2 GPU host).
@@ -6717,13 +6736,14 @@ _maybe_bootstrap_rocm_wsl() {
command -v bash >/dev/null 2>&1 || return 0
if [ -e /opt/rocm/lib/librocdxg.so ] || [ -e /opt/rocm/lib64/librocdxg.so ]; then
- if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ]; then
+ if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ] && ! _rocm_wsl_dropin_stale; then
# shellcheck disable=SC1091
. /etc/profile.d/unsloth-rocm-wsl.sh || true
else
- # librocdxg present but the env drop-in is gone (uninstall dropped it).
+ # librocdxg present but the env drop-in is gone (uninstall dropped it) or stale.
_persist_rocm_wsl_dropin
fi
+ _repair_rocm_wsl_bashrc
return 0
fi
@@ -6784,10 +6804,14 @@ _maybe_bootstrap_rocm_wsl() {
UNSLOTH_LIBROCDXG_REF="$_rw_dxg_ref" UNSLOTH_LIBROCDXG_SHA="$_rw_dxg_sha" \
bash "$_rw_helper"; then
# Pull the helper's persisted env into THIS shell so detection (rocminfo) now enumerates the GPU and routes to gfx1151.
- if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ]; then
+ if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ] && ! _rocm_wsl_dropin_stale; then
# shellcheck disable=SC1091
. /etc/profile.d/unsloth-rocm-wsl.sh || true
+ else
+ # The pinned helper may write the old drop-in: rewrite it (and export) here.
+ _persist_rocm_wsl_dropin
fi
+ _repair_rocm_wsl_bashrc
substep "ROCm-on-WSL ready; continuing with GPU install." "$C_OK"
else
substep "ROCm-on-WSL setup did not complete; falling back to CPU-only." "$C_WARN"
diff --git a/scripts/install_rocm_wsl_strixhalo.sh b/scripts/install_rocm_wsl_strixhalo.sh
index b860b7d570c..4f4fea2d9c5 100644
--- a/scripts/install_rocm_wsl_strixhalo.sh
+++ b/scripts/install_rocm_wsl_strixhalo.sh
@@ -258,17 +258,22 @@ $SUDO tee "$_envfile" >/dev/null <<EOF
# >>> Unsloth ROCm-on-WSL >>>
export HSA_ENABLE_DXG_DETECTION=1
export PATH="${ROCM_DIR}/bin:\${PATH}"
-export LD_LIBRARY_PATH="${ROCM_DIR}/lib:\${LD_LIBRARY_PATH:-}"
+export LD_LIBRARY_PATH="${ROCM_DIR}/lib\${LD_LIBRARY_PATH:+:\${LD_LIBRARY_PATH}}"
# <<< Unsloth ROCm-on-WSL <<<
EOF
-# also drop into ~/.bashrc for interactive shells
+# also drop into ~/.bashrc for interactive shells; an older block left a trailing ':' (the cwd) on an empty LD_LIBRARY_PATH, so replace it
+if [ -n "${HOME:-}" ] && grep -qF 'lib:${LD_LIBRARY_PATH:-}' "${HOME}/.bashrc" 2>/dev/null; then
+ # --follow-symlinks: a dotfile-managed ~/.bashrc stays a link and its target gets the edit.
+ sed --follow-symlinks -i '/^# >>> Unsloth ROCm-on-WSL >>>$/,/^# <<< Unsloth ROCm-on-WSL <<<$/d' "${HOME}/.bashrc" \
+ || say "Could not update the ROCm block in ~/.bashrc; /etc/profile.d has the fixed one"
+fi
if [ -n "${HOME:-}" ] && ! grep -q "Unsloth ROCm-on-WSL" "${HOME}/.bashrc" 2>/dev/null; then
cat "$_envfile" >> "${HOME}/.bashrc"
fi
# export into the current process so verification below works immediately
export HSA_ENABLE_DXG_DETECTION=1
export PATH="${ROCM_DIR}/bin:${PATH}"
-export LD_LIBRARY_PATH="${ROCM_DIR}/lib:${LD_LIBRARY_PATH:-}"
+export LD_LIBRARY_PATH="${ROCM_DIR}/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
# ── Step 5: verify the runtime enumerates the GPU ────────────────────────────
say "Verifying rocminfo enumerates the GPU over DXG"
diff --git a/tests/sh/test_rocm_wsl_ld_library_path.sh b/tests/sh/test_rocm_wsl_ld_library_path.sh
new file mode 100755
index 00000000000..a0f664b3440
--- /dev/null
+++ b/tests/sh/test_rocm_wsl_ld_library_path.sh
@@ -0,0 +1,128 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# The ROCm-on-WSL env drop-in must not add an empty LD_LIBRARY_PATH element (the cwd) when the
+# variable starts unset, a re-run must repair an older drop-in, and a second run changes nothing.
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+. "$SCRIPT_DIR/_harness.sh"
+INSTALL_SH="$SCRIPT_DIR/../../install.sh"
+HELPER_SH="$SCRIPT_DIR/../../scripts/install_rocm_wsl_strixhalo.sh"
+
+_tmp="$(mktemp -d)"
+trap 'rm -rf "$_tmp"' EXIT
+mkdir -p "$_tmp/rocm/lib" "$_tmp/profile.d" "$_tmp/home"
+: > "$_tmp/rocm/lib/librocdxg.so"
+_dropin="$_tmp/profile.d/unsloth-rocm-wsl.sh"
+
+# Every function the writer needs, with the system paths pointed into the sandbox.
+_fns="$(sed -n '/^_rocm_wsl_dropin_stale() {$/,/^}$/p; /^_repair_rocm_wsl_bashrc() {$/,/^}$/p; /^_persist_rocm_wsl_dropin() {$/,/^}$/p' "$INSTALL_SH" \
+ | sed "s|/etc/profile.d/unsloth-rocm-wsl.sh|$_dropin|g; s|/opt/rocm|$_tmp/rocm|g")"
+case "$_fns" in
+ *"_persist_rocm_wsl_dropin()"*) ;;
+ *) bad "could not extract _persist_rocm_wsl_dropin"; summary ;;
+esac
+
+_run_writer() {
+ env -i PATH="$PATH" bash -c 'id() { echo 0; }; eval "$1"; _persist_rocm_wsl_dropin' _ "$_fns"
+}
+
+_ld_after_source() {
+ # A login shell with LD_LIBRARY_PATH unset, as /etc/profile.d sees it.
+ env -i PATH=/usr/bin:/bin sh -c '. "$1"; printf "%s" "$LD_LIBRARY_PATH"' _ "$1"
+}
+
+_no_empty_element() {
+ case ":$1:" in
+ *::*) return 1 ;;
+ esac
+ return 0
+}
+
+echo "=== install.sh drop-in ==="
+_run_writer
+[ -r "$_dropin" ] || bad "drop-in not written"
+_ld="$(_ld_after_source "$_dropin")"
+assert_eq "drop-in with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+if _no_empty_element "$_ld"; then ok "no empty LD_LIBRARY_PATH element"; else bad "empty element in '$_ld'"; fi
+_ld="$(env -i PATH=/usr/bin:/bin LD_LIBRARY_PATH=/x sh -c '. "$1"; printf "%s" "$LD_LIBRARY_PATH"' _ "$_dropin")"
+assert_eq "drop-in keeps an existing LD_LIBRARY_PATH after ROCm" "$_tmp/rocm/lib:/x" "$_ld"
+
+cp "$_dropin" "$_tmp/first"
+_run_writer
+if cmp -s "$_tmp/first" "$_dropin"; then ok "second run is byte-identical"; else bad "second run changed the drop-in"; fi
+
+# An older install left the trailing-colon form: a re-run must fix that line and keep the rest.
+printf '# >>> Unsloth ROCm-on-WSL (gfx1151) >>>\nexport LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\nexport HSA_CUSTOM=1\n# <<< Unsloth ROCm-on-WSL (gfx1151) <<<\n' "$_tmp/rocm" > "$_dropin"
+_run_writer
+assert_not_contains "stale drop-in line fixed on re-run" "$(cat "$_dropin")" 'lib:${LD_LIBRARY_PATH:-}'
+assert_contains "other drop-in lines kept" "$(cat "$_dropin")" "export HSA_CUSTOM=1"
+_ld="$(_ld_after_source "$_dropin")"
+assert_eq "fixed drop-in with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+cp "$_dropin" "$_tmp/fixed_first"
+_run_writer
+if cmp -s "$_tmp/fixed_first" "$_dropin"; then ok "fixed drop-in unchanged by another run"; else bad "another run changed the fixed drop-in"; fi
+
+# A drop-in an operator edited (no stale form) is left alone.
+printf 'export LD_LIBRARY_PATH=/custom\n' > "$_dropin"
+_run_writer
+assert_eq "current drop-in not overwritten" "export LD_LIBRARY_PATH=/custom" "$(cat "$_dropin")"
+
+echo "=== install.sh repairs an old helper's ~/.bashrc block ==="
+mkdir -p "$_tmp/dotfiles" "$_tmp/home2"
+printf '# user line\n# >>> Unsloth ROCm-on-WSL >>>\nexport LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\n# <<< Unsloth ROCm-on-WSL <<<\n' "$_tmp/rocm" > "$_tmp/dotfiles/bashrc"
+ln -s "$_tmp/dotfiles/bashrc" "$_tmp/home2/.bashrc"
+env -i PATH="$PATH" HOME="$_tmp/home2" bash -c 'eval "$1"; _repair_rocm_wsl_bashrc' _ "$_fns"
+if [ -L "$_tmp/home2/.bashrc" ]; then ok "symlinked ~/.bashrc stays a link"; else bad "~/.bashrc link replaced by a file"; fi
+assert_not_contains "old block line repaired" "$(cat "$_tmp/dotfiles/bashrc")" 'lib:${LD_LIBRARY_PATH:-}'
+_ld="$(_ld_after_source "$_tmp/home2/.bashrc")"
+assert_eq "repaired block with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+cp "$_tmp/dotfiles/bashrc" "$_tmp/repaired_first"
+env -i PATH="$PATH" HOME="$_tmp/home2" bash -c 'eval "$1"; _repair_rocm_wsl_bashrc' _ "$_fns"
+if cmp -s "$_tmp/repaired_first" "$_tmp/dotfiles/bashrc"; then ok "repair is idempotent"; else bad "second repair changed ~/.bashrc"; fi
+
+echo "=== helper env block ==="
+_step4="$(sed -n '/^# ── Step 4: persist environment/,/^# ── Step 5:/p' "$HELPER_SH" \
+ | sed "s|/etc/profile.d/unsloth-rocm-wsl.sh|$_tmp/helper_env.sh|g")"
+[ -n "$_step4" ] || bad "could not extract the helper's Step 4"
+_run_helper_step4() {
+ env -i PATH="$PATH" HOME="$_tmp/home" ROCM_DIR="$_tmp/rocm" SUDO="" \
+ bash -c 'say() { :; }; eval "$1"; printf "%s" "$LD_LIBRARY_PATH"' _ "$_step4"
+}
+printf '# user line\n' > "$_tmp/home/.bashrc"
+_proc_ld="$(_run_helper_step4)"
+assert_eq "helper's own process LD_LIBRARY_PATH" "$_tmp/rocm/lib" "$_proc_ld"
+_ld="$(_ld_after_source "$_tmp/helper_env.sh")"
+assert_eq "helper drop-in with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+_ld="$(_ld_after_source "$_tmp/home/.bashrc")"
+assert_eq "helper ~/.bashrc block with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+cp "$_tmp/home/.bashrc" "$_tmp/bashrc_first"
+_run_helper_step4 >/dev/null
+if cmp -s "$_tmp/bashrc_first" "$_tmp/home/.bashrc"; then ok "helper second run leaves ~/.bashrc byte-identical"; else bad "helper second run changed ~/.bashrc"; fi
+
+# An older helper's ~/.bashrc block is replaced through a symlink, the user's own lines kept.
+printf '# user line\n# >>> Unsloth ROCm-on-WSL >>>\nexport LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\n# <<< Unsloth ROCm-on-WSL <<<\n# after\n' "$_tmp/rocm" > "$_tmp/dotfiles/helper_bashrc"
+rm -f "$_tmp/home/.bashrc"; ln -s "$_tmp/dotfiles/helper_bashrc" "$_tmp/home/.bashrc"
+_run_helper_step4 >/dev/null
+if [ -L "$_tmp/home/.bashrc" ]; then ok "helper keeps a symlinked ~/.bashrc a link"; else bad "helper replaced the ~/.bashrc link"; fi
+assert_not_contains "stale ~/.bashrc block removed" "$(cat "$_tmp/home/.bashrc")" 'lib:${LD_LIBRARY_PATH:-}'
+assert_contains "user lines kept" "$(cat "$_tmp/home/.bashrc")" "# after"
+_ld="$(_ld_after_source "$_tmp/home/.bashrc")"
+assert_eq "repaired ~/.bashrc with LD_LIBRARY_PATH unset" "$_tmp/rocm/lib" "$_ld"
+
+# A ~/.bashrc it cannot edit must not abort the helper after ROCm is installed.
+if [ "$(id -u)" != "0" ]; then
+ mkdir -p "$_tmp/ro"
+ printf '# >>> Unsloth ROCm-on-WSL >>>\nexport LD_LIBRARY_PATH="%s/lib:${LD_LIBRARY_PATH:-}"\n# <<< Unsloth ROCm-on-WSL <<<\n' "$_tmp/rocm" > "$_tmp/ro/.bashrc"
+ chmod a-w "$_tmp/ro" "$_tmp/ro/.bashrc"
+ if env -i PATH="$PATH" HOME="$_tmp/ro" ROCM_DIR="$_tmp/rocm" SUDO="" \
+ bash -euo pipefail -c 'say() { :; }; eval "$1"' _ "$_step4" >/dev/null 2>&1; then
+ ok "read-only ~/.bashrc does not abort the helper"
+ else
+ bad "read-only ~/.bashrc aborted the helper"
+ fi
+ chmod u+w "$_tmp/ro" "$_tmp/ro/.bashrc"
+fi
+
+summary