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.

Treat Docker on WSL2 as WSL when deciding embedding offload (#13259)

Daniel Han3e9076d6c64b
diff --git a/tests/test_offload_tied_autodisable.py b/tests/test_offload_tied_autodisable.py
index ff0ec28d73d..e247b5c7cf7 100644
--- a/tests/test_offload_tied_autodisable.py
+++ b/tests/test_offload_tied_autodisable.py
@@ -76,10 +76,18 @@ _WSL_VARS = ("WSL_DISTRO_NAME", "WSL_INTEROP")
@contextmanager
-def _as_platform(os_name, wsl = False):
+def _as_platform(
+ os_name,
+ wsl = False,
+ release = "6.8.0-1021-generic",
+):
"""Drive the platform inputs directly instead of trusting the host's."""
saved_env = {v: os.environ.get(v) for v in _WSL_VARS}
saved_name = os.name
+ saved_uname = getattr(os, "uname", None)
+ if saved_uname is not None:
+ u = saved_uname()
+ os.uname = lambda: os.uname_result((u.sysname, u.nodename, release, u.version, u.machine))
for v in _WSL_VARS:
os.environ.pop(v, None)
if wsl:
@@ -90,6 +98,8 @@ def _as_platform(os_name, wsl = False):
yield
finally:
os.name = saved_name
+ if saved_uname is not None:
+ os.uname = saved_uname
for v, old in saved_env.items():
if old is None:
os.environ.pop(v, None)
@@ -174,6 +184,19 @@ def test_wsl_and_windows_disable_offload():
assert unsupported_platform() is None
[email protected](not hasattr(os, "uname"), reason = "os.uname is POSIX only")
+def test_docker_on_wsl2_disables_offload():
+ # A container on WSL2 sets no WSL_* variables; only the shared kernel says WSL (unslothai/unsloth#3511).
+ for release in ("6.6.87.2-microsoft-standard-WSL2", "5.15.153.1-microsoft-standard-WSL2"):
+ with _as_platform("posix", release = release):
+ assert unsupported_platform() == "WSL"
+ assert resolve(_untied_model(), True) is False
+
+ for release in ("6.8.0-1021-azure", "6.10.14-linuxkit"):
+ with _as_platform("posix", release = release):
+ assert unsupported_platform() is None
+
+
def test_platform_gate_lives_in_one_place():
# The offload block used to re-test os.name itself; the copies drifted apart and only Windows noticed.
# _resolve_offload_embedding owns it now.
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py
index 5301ac5d444..a6ef9680182 100644
--- a/unsloth/models/vision.py
+++ b/unsloth/models/vision.py
@@ -891,6 +891,12 @@ def _offload_embedding_unsupported_platform():
return "WSL"
if os.name == "nt":
return "Windows"
+ # Docker on WSL2 has no WSL_* variables but shares the *-microsoft-standard-WSL2 kernel (unslothai/unsloth#3511).
+ try:
+ if "microsoft" in os.uname().release.lower():
+ return "WSL"
+ except Exception:
+ pass
return None