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: keep the zoo num_proc anchor tests meaningful once the zoo adopts the edit (#13269)

Daniel Hanb0544148ee9f
diff --git a/tests/utils/test_dataset_num_proc.py b/tests/utils/test_dataset_num_proc.py
index 0e1dcd6f1ad..d0e29f45115 100644
--- a/tests/utils/test_dataset_num_proc.py
+++ b/tests/utils/test_dataset_num_proc.py
@@ -605,6 +605,23 @@ def _anchor_and_count(where):
return ast.literal_eval(node.args[1]), count
+def _num_proc_replacement():
+ return ast.literal_eval(_anchor_calls(NUM_PROC_WHERE)[0].args[2])
+
+
+def _zoo_adopted_the_num_proc_edit(source):
+ return _num_proc_replacement() in source
+
+
+def _zoo_source_as_anchored():
+ """Installed Zoo source with an adopted num_proc block reverted to the anchor, so drift tests still bite on a newer Zoo."""
+ source = _zoo_dataset_utils_source()
+ if _zoo_adopted_the_num_proc_edit(source):
+ anchor, _ = _anchor_and_count(NUM_PROC_WHERE)
+ source = source.replace(_num_proc_replacement(), anchor, 1)
+ return source
+
+
def _keyword(where, name):
node = _anchor_calls(where)[0]
value = next(k.value for k in node.keywords if k.arg == name)
@@ -654,6 +671,9 @@ def test_zoo_sft_prepare_dataset_anchor_has_not_drifted():
"sft_prepare_dataset tokenizing map() calls",
):
anchor, count = _anchor_and_count(where)
+ if where == NUM_PROC_WHERE and _zoo_adopted_the_num_proc_edit(source):
+ # The Zoo ships the replacement itself; test_a_zoo_that_adopted_the_num_proc_edit_is_left_alone covers it.
+ continue
assert source.count(anchor) == count, (
f"unsloth_zoo.dataset_utils has {source.count(anchor)} occurrences of "
f"the {where!r} anchor, expected {count}; update rl_replacements.py"
@@ -668,7 +688,7 @@ def test_the_narrow_num_proc_anchor_still_matches_the_installed_zoo():
that line too, both anchors are gone and nothing rewrites the worker count --
so pin it here, in CI, rather than discovering it from a user's Pool(1).
"""
- source = _zoo_dataset_utils_source()
+ source = _zoo_source_as_anchored()
pattern = _narrow_num_proc_pattern()
matches = pattern.findall(source)
@@ -742,8 +762,22 @@ def _apply_num_proc_edit(source):
return result, warnings
-def test_the_block_anchor_is_used_when_the_zoo_has_not_moved():
+def test_a_zoo_that_adopted_the_num_proc_edit_is_left_alone():
+ """No rewrite and no warning; a narrow-anchor rewrite of its first line would leave continuation lines dangling."""
source = _zoo_dataset_utils_source()
+ adopted = source
+ if not _zoo_adopted_the_num_proc_edit(adopted):
+ anchor, _ = _anchor_and_count(NUM_PROC_WHERE)
+ adopted = source.replace(anchor, _num_proc_replacement(), 1)
+ assert adopted != source
+ result, warnings = _apply_num_proc_edit(adopted)
+ assert result == adopted
+ assert warnings == [], f"an adopted block must not warn: {warnings}"
+ ast.parse(result)
+
+
+def test_the_block_anchor_is_used_when_the_zoo_has_not_moved():
+ source = _zoo_source_as_anchored()
result, warnings = _apply_num_proc_edit(source)
assert "_unsloth_get_dataset_num_proc" in result
assert 'map_kwargs["num_proc"] = dataset_num_proc' not in result
@@ -762,7 +796,7 @@ def test_the_narrow_anchor_takes_over_when_the_block_drifts():
reads the config `1` the config layer writes for "serial", and datasets >= 4.1
turns that into a Pool(1) on the host that asked for no workers.
"""
- source = _zoo_dataset_utils_source()
+ source = _zoo_source_as_anchored()
# Drift the block without touching the line the fallback keys on.
drifted = source.replace(
" import multiprocessing as _mp\n",
@@ -788,7 +822,7 @@ def test_neither_anchor_matching_only_warns():
which is a far bigger blast radius than the one worker at stake.
"""
source = (
- _zoo_dataset_utils_source()
+ _zoo_source_as_anchored()
.replace(
' map_kwargs["num_proc"] = dataset_num_proc\n',
' map_kwargs.update({"num_proc": dataset_num_proc})\n',