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.

Tests: real-accelerator skip guards and utf-8 read in the gpt-oss and gc-skip tests (#14504)

Daniel Hanc08dfbbe641d
diff --git a/tests/test_gc_skip_auto.py b/tests/test_gc_skip_auto.py
index 4f042a1b900..8d2fae3ba76 100644
--- a/tests/test_gc_skip_auto.py
+++ b/tests/test_gc_skip_auto.py
@@ -6,6 +6,7 @@
import ast, logging, os
import pytest
import torch
+from real_accelerator import has_real_cuda # tests/_shared, on sys.path via tests/conftest.py
transformers = pytest.importorskip("transformers")
from transformers import Qwen3Config, Qwen3ForCausalLM
@@ -103,7 +104,7 @@ def _step(model, ids):
}
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_plans_after_first_step_and_keeps_gradients():
ns, found = _load()
assert "_AutoCheckpointSkip" in found, 'checkpoint_skip_layers = "auto" is not implemented'
@@ -132,7 +133,7 @@ def test_auto_plans_after_first_step_and_keeps_gradients():
torch.testing.assert_close(grads[name], ref_grads[name], rtol = 0, atol = 0, msg = name)
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_keeps_everything_checkpointed_without_headroom(monkeypatch):
ns, found = _load()
ids = torch.randint(0, 128, (2, 64), generator = torch.Generator().manual_seed(1)).cuda()
@@ -148,7 +149,7 @@ def test_auto_keeps_everything_checkpointed_without_headroom(monkeypatch):
assert _checkpointed(model) == [True] * 6
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_backs_off_without_reentrant_checkpointing():
ns, found = _load()
ids = torch.randint(0, 128, (2, 64), generator = torch.Generator().manual_seed(1)).cuda()
@@ -173,7 +174,7 @@ def test_auto_without_cuda_says_so_once(monkeypatch, capsys):
assert not hasattr(model, "_unsloth_auto_skip")
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_ignores_allocation_spike_before_first_step():
ns, found = _load()
ids = torch.randint(0, 128, (2, 64), generator = torch.Generator().manual_seed(1)).cuda()
@@ -207,7 +208,7 @@ def _big_model():
return model
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
@pytest.mark.parametrize("optimizer_stepped", [True, False])
def test_auto_reserves_optimizer_state_only_when_not_allocated(optimizer_stepped):
ns, found = _load()
@@ -253,7 +254,7 @@ def test_auto_with_model_off_cuda_on_a_cuda_host_installs_nothing(monkeypatch, c
assert dict(getattr(torch_optimizer, "_global_optimizer_pre_hooks", {})) == global_hooks
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_reserves_state_for_params_the_optimizer_has_not_seen():
ns, found = _load()
ids = torch.randint(0, 32000, (2, 64), generator = torch.Generator().manual_seed(1)).cuda()
@@ -278,7 +279,7 @@ def test_auto_reserves_state_for_params_the_optimizer_has_not_seen():
torch.cuda.empty_cache()
[email protected](not torch.cuda.is_available(), reason = "the auto planner sizes CUDA memory")
[email protected](not has_real_cuda(), reason = "the auto planner sizes CUDA memory")
def test_auto_does_not_scale_persistent_grads_by_sequence_length():
ns, found = _load()
model = _big_model()
diff --git a/tests/test_gpt_oss_bf16_load_in_4bit.py b/tests/test_gpt_oss_bf16_load_in_4bit.py
index 0b2e5e7b4d6..8780e065b70 100644
--- a/tests/test_gpt_oss_bf16_load_in_4bit.py
+++ b/tests/test_gpt_oss_bf16_load_in_4bit.py
@@ -22,6 +22,8 @@ from types import SimpleNamespace
import pytest
import torch
+from real_accelerator import has_real_cuda # tests/_shared, on sys.path via tests/conftest.py
+
import unsloth # noqa: F401 (patches before transformers)
from unsloth.models import loader_utils
@@ -96,7 +98,7 @@ def test_sync_ignores_other_models(monkeypatch):
assert os.environ["UNSLOTH_MODEL_NAME"] == "llama,_load_in_4bit_"
[email protected](not torch.cuda.is_available(), reason = "needs a CUDA GPU for bitsandbytes")
[email protected](not has_real_cuda(), reason = "needs a CUDA GPU for bitsandbytes")
def test_bf16_checkpoint_loads_real_weights_in_4bit(tmp_path):
pytest.importorskip("bitsandbytes")
from safetensors.torch import load_file
@@ -157,7 +159,7 @@ def test_bf16_checkpoint_loads_real_weights_in_4bit(tmp_path):
assert expert_grads and any(float(g.abs().sum()) > 0 for g in expert_grads)
[email protected](not torch.cuda.is_available(), reason = "needs a CUDA GPU for bitsandbytes")
[email protected](not has_real_cuda(), reason = "needs a CUDA GPU for bitsandbytes")
def test_bf16_checkpoint_4bit_generate_matches_prefill(tmp_path):
"""One-token decode on the fused Params4bit experts gives the prefill (module forward) logits."""
pytest.importorskip("bitsandbytes")
diff --git a/tests/test_gpt_oss_bnb_checkpoint_layout.py b/tests/test_gpt_oss_bnb_checkpoint_layout.py
index 9b052af00f9..cf50f0400db 100644
--- a/tests/test_gpt_oss_bnb_checkpoint_layout.py
+++ b/tests/test_gpt_oss_bnb_checkpoint_layout.py
@@ -26,6 +26,8 @@ import pytest
import torch
from safetensors.torch import save_file
+from real_accelerator import has_real_cuda # tests/_shared, on sys.path via tests/conftest.py
+
import unsloth # noqa: F401 (patches before transformers)
from unsloth.models import loader_utils
@@ -188,7 +190,7 @@ def _expert_weight(experts, name):
return w.detach().float().cpu()
[email protected](not torch.cuda.is_available(), reason = "needs a CUDA GPU for bitsandbytes")
[email protected](not has_real_cuda(), reason = "needs a CUDA GPU for bitsandbytes")
def test_reload_of_saved_fused_4bit_checkpoints(tmp_path):
pytest.importorskip("bitsandbytes")
from safetensors.torch import load_file
@@ -359,7 +361,7 @@ def _hub(
calls.append(filename)
if filename in files:
p = os.path.join(os.environ["TMPDIR"], "w17_hub_" + filename)
- with open(p, "w") as f:
+ with open(p, "w", encoding = "utf-8") as f:
json.dump({"weight_map": files[filename]}, f)
return p
if not filename.endswith(".json") and not kwargs.get("local_files_only"):