Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.
Python cliconsumer-gpudpofine-tuningggufhuggingfacellmllmopslocal-ailocal-llmloralow-vrammachine-learningollamapeftpythonpytorchqlorasfttransformers
test: stop 76 tests across 10 files downloading from the Hub (#1544)
Siddhardha Nandafa60adfdfc0c
diff --git a/changelog.d/0.75.1/1544.fixed.md b/changelog.d/0.75.1/1544.fixed.mdnew file mode 100644index 00000000..7c4a8e2a--- /dev/null+++ b/changelog.d/0.75.1/1544.fixed.md@@ -0,0 +1,12 @@+- **76 tests across 10 files downloaded tiny models/tokenizers from the+ Hugging Face Hub on every run, none marked `smoke` and none guarded against+ the network being unavailable (#1356 by @SID-6921 in #1544).** A real sweep+ (`HF_HUB_OFFLINE=1`, empty `HF_HOME`, `pytest tests/ -m "not smoke"`) found+ a much larger landscape than a preliminary grep-based pass had estimated.+ Every site now builds its tiny model and tokenizer locally instead --+ a `ByteLevelBPETokenizer` trained from a few lines of in-file text feeding+ a real, randomly-initialised `LlamaConfig`/`GPT2Config` model, matching the+ existing `_write_tiny_qwen2` convention -- since none of the fixed tests+ needed real pretrained weights or vocabulary, only a working tokenizer and+ a save/reload round-trip. A full-suite offline re-sweep afterward confirms+ zero remaining Hub-dependent failures.diff --git a/tests/_tiny_hf_models.py b/tests/_tiny_hf_models.pynew file mode 100644index 00000000..2965590d--- /dev/null+++ b/tests/_tiny_hf_models.py@@ -0,0 +1,96 @@+"""Shared tiny-model builders for tests that need a real transformers model+and tokenizer, not a mock, but not one pulled from the Hub either.++#1356 found 76 tests across 10 files downloading+``hf-internal-testing/tiny-random-LlamaForCausalLM``,+``hf-internal-testing/tiny-random-gpt2``, ``sshleifer/tiny-gpt2`` or+``HuggingFaceTB/SmolLM2-135M-Instruct`` on every run for nothing any of them+checked depends on real pretrained weights or vocabulary -- only a working+tokenizer and a save/reload round-trip. The first fix defined the same+builder in seven files and an inline version in three more; this module is+the one place that builds them now, mirroring ``tests/_windows_ci.py`` as+the existing precedent for a shared test helper pulled out after a predicate+had been copied instead (#372, #392, #424).++``tiny_model_dir(arch)`` is cached per architecture and per process, and the+directory is removed at interpreter exit rather than left in the system temp+directory the way ten separate ``tempfile.mkdtemp()`` calls were.+``build_tokenizer`` / ``build_gpt2`` / ``build_llama`` are exposed+separately for the two tests that want the in-memory objects directly+(``test_rewind_hf.py``, ``test_v05311.py``) rather than a saved directory.+"""++from __future__ import annotations++import atexit+import functools+import shutil+import tempfile+from typing import TYPE_CHECKING++if TYPE_CHECKING: # pragma: no cover+ from transformers import GPT2LMHeadModel, LlamaForCausalLM, PreTrainedTokenizerFast++_TEXTS = (+ "hi there friend",+ "hello world",+ "the quick brown fox jumps",+ "message 0 is ham",+ "message 1 is spam",+)+++def build_tokenizer(+ texts: tuple[str, ...] | None = None, *, eos: str = "<eos>"+) -> "PreTrainedTokenizerFast":+ """A byte-level BPE tokenizer trained locally (no download)."""+ from tokenizers import ByteLevelBPETokenizer+ from transformers import PreTrainedTokenizerFast++ bpe = ByteLevelBPETokenizer()+ bpe.train_from_iterator(+ list(texts or _TEXTS), vocab_size=300, min_frequency=1, special_tokens=[eos]+ )+ return PreTrainedTokenizerFast(+ tokenizer_object=bpe, eos_token=eos, bos_token=eos, pad_token=eos+ )+++def build_gpt2(tok: "PreTrainedTokenizerFast") -> "GPT2LMHeadModel":+ """A tiny, randomly-initialised GPT-2 sized to ``tok``'s vocabulary."""+ from transformers import GPT2Config, GPT2LMHeadModel++ config = GPT2Config(vocab_size=len(tok), n_positions=128, n_embd=32, n_layer=2, n_head=4)+ return GPT2LMHeadModel(config)+++def build_llama(tok: "PreTrainedTokenizerFast") -> "LlamaForCausalLM":+ """A tiny, randomly-initialised Llama sized to ``tok``'s vocabulary."""+ from transformers import LlamaConfig, LlamaForCausalLM++ config = LlamaConfig(+ hidden_size=32,+ intermediate_size=64,+ num_hidden_layers=2,+ num_attention_heads=4,+ num_key_value_heads=2,+ vocab_size=len(tok),+ max_position_embeddings=128,+ )+ return LlamaForCausalLM(config)+++_BUILDERS = {"gpt2": build_gpt2, "llama": build_llama}++[email protected]_cache(maxsize=None)+def tiny_model_dir(arch: str) -> str:+ """Build (once per process) and return a directory holding a tiny+ ``arch`` model + tokenizer, cleaned up at interpreter exit."""+ tok = build_tokenizer()+ model = _BUILDERS[arch](tok)+ out_dir = tempfile.mkdtemp(prefix=f"soup-test-tiny-{arch}-")+ atexit.register(shutil.rmtree, out_dir, ignore_errors=True)+ model.save_pretrained(out_dir)+ tok.save_pretrained(out_dir)+ return out_dirdiff --git a/tests/test_dpo_variants.py b/tests/test_dpo_variants.pyindex 6da9b61a..b3e19c60 100644--- a/tests/test_dpo_variants.py+++ b/tests/test_dpo_variants.py@@ -22,6 +22,17 @@ from pydantic import ValidationErrorfrom soup_cli.config.schema import SoupConfig++def _local_base_model_dir() -> str:+ """A tiny GPT-2 + tokenizer built locally (no download), standing in for+ sshleifer/tiny-gpt2 -- #1356 found these real-trainer tests pulling it+ from the Hub for nothing they check depends on real pretrained weights.+ Shared and cached across every file that needs one (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("gpt2")++# ─── Schema bounds ──────────────────────────────────────────────────────────@@ -611,8 +622,9 @@ class TestRealTrainerBetaSchedule:for i in range(4)]out_dir = (tmp_path / f"out_dpo_{sched}").as_posix()+ base_dir = Path(_local_base_model_dir()).as_posix()cfg = load_config_from_string(f"""-base: sshleifer/tiny-gpt2+base: {base_dir}task: dpodata:train: x.jsonl@@ -648,7 +660,7 @@ def _run_schedule(tmp_path, task, training):{"prompt": f"Q{i}?", "chosen": f"A{i} good.", "rejected": f"A{i} bad."} for i in range(4)]cfg = load_config_from_string(- "base: sshleifer/tiny-gpt2\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\n"f"task: {task}\n""data:\n train: x.jsonl\n max_length: 64\n""training:\n epochs: 2\n batch_size: 2\n quantization: none\n lr: 1e-4\n"diff --git a/tests/test_issue1217_tool_calling_nested.py b/tests/test_issue1217_tool_calling_nested.pyindex 860295ef..cf453504 100644--- a/tests/test_issue1217_tool_calling_nested.py+++ b/tests/test_issue1217_tool_calling_nested.py@@ -38,7 +38,18 @@ from soup_cli.utils.agent_forge import ()from tests.conftest import strip_ansi-_BASE = "hf-internal-testing/tiny-random-LlamaForCausalLM"++def _local_base_model_dir() -> str:+ """A tiny Llama causal LM + tokenizer built locally (no download),+ standing in for hf-internal-testing/tiny-random-LlamaForCausalLM -- #1356+ found this pulling it from the Hub for a dry-run plan and a tokenizer+ whose chat_template gets overwritten immediately after load. Shared and+ cached across every file that needs one (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("llama")++_WEATHER_TOOL = {"type": "function","function": {@@ -127,11 +138,12 @@ def test_the_printed_recipe_dry_runs_with_the_synthesised_rows(tmp_path, monkeypencoding="utf-8",)runner = CliRunner()- planned = runner.invoke(app, ["agent", "train", "--spec", "openapi.yaml", "--base", _BASE])+ base = Path(_local_base_model_dir()).as_posix()+ planned = runner.invoke(app, ["agent", "train", "--spec", "openapi.yaml", "--base", base])assert planned.exit_code == 0, planned.outputassert "format: tool-calling" in planned.outputPath("agent_train.yaml").write_text(- f"base: {_BASE}\ntask: sft\ndata:\n train: agent_dataset.jsonl\n"+ f"base: {base}\ntask: sft\ndata:\n train: agent_dataset.jsonl\n"" format: tool-calling\n val_split: 0.0\n""training:\n epochs: 3\n lr: 2.0e-5\n batch_size: auto\n""output: ./agent_train_output\n",@@ -458,7 +470,7 @@ def test_the_trajectory_renders_in_source_order_through_arrow():from soup_cli.data.sft_format import build_format_row- tokenizer = AutoTokenizer.from_pretrained(_BASE)+ tokenizer = AutoTokenizer.from_pretrained(_local_base_model_dir())tokenizer.chat_template = _LLAMA_STYLE_TEMPLATEdata_cfg = SimpleNamespace(chat_template=None,diff --git a/tests/test_issue1219_classifier_data_loader.py b/tests/test_issue1219_classifier_data_loader.pyindex a742c6b5..d4e61497 100644--- a/tests/test_issue1219_classifier_data_loader.py+++ b/tests/test_issue1219_classifier_data_loader.py@@ -47,6 +47,18 @@ def _strip_ansi(text: str) -> str:return " ".join(plain.split())+def _local_base_model_dir() -> str:+ """A tiny Llama causal LM + tokenizer built locally (no download),+ standing in for hf-internal-testing/tiny-random-LlamaForCausalLM -- #1356+ found these tests pulling it from the Hub just to initialise a+ classification head on top, which a randomly-initialised base serves+ identically. Shared and cached across every file that needs one+ (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("llama")++class TestTaskPreservesSourceColumns:"""One helper decides which tasks keep source columns; train and sweep must agree."""@@ -400,7 +412,7 @@ class TestDatasetVariantsLoading:data_file.write_text("\n".join(json.dumps(r) for r in rows) + "\n")cfg_obj = {- "base": "hf-internal-testing/tiny-random-LlamaForCausalLM",+ "base": _local_base_model_dir(),"task": task,"data": {"train": data_file.as_posix(),@@ -451,7 +463,7 @@ class TestDocumentedExampleTraining:cfg_file = tmp_path / "cls.yaml"cfg_file.write_text(f"""- base: hf-internal-testing/tiny-random-LlamaForCausalLM+ base: {Path(_local_base_model_dir()).as_posix()}task: classifierdata:train: {data_path.as_posix()}diff --git a/tests/test_issue1220_resume_prm_moe.py b/tests/test_issue1220_resume_prm_moe.pyindex 4ab5ba8f..fae96d6d 100644--- a/tests/test_issue1220_resume_prm_moe.py+++ b/tests/test_issue1220_resume_prm_moe.py@@ -25,7 +25,16 @@ from soup_cli.cli import appfrom soup_cli.commands.train import UNSUPPORTED_RESUME_TASKSfrom tests._windows_ci import skip_on_windows_ci-TINY_MODEL = "hf-internal-testing/tiny-random-LlamaForCausalLM"++def _local_base_model_dir() -> str:+ """A tiny Llama causal LM + tokenizer built locally (no download),+ standing in for hf-internal-testing/tiny-random-LlamaForCausalLM -- #1356+ found these resume/checkpoint tests pulling it from the Hub for nothing+ they check depends on real pretrained weights. Shared and cached across+ every file that needs one (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("llama")def _strip_ansi(text: str) -> str:@@ -172,7 +181,7 @@ class TestResumeRefusalForUnsupportedTasks:train_data.write_text(json.dumps({"prompt": "forget me", "response": "done"}) + "\n")config_path.write_text(- f"base: {TINY_MODEL}\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\n""task: unlearn\n"f"data: {{train: {train_data.as_posix()}, forget_set: {train_data.as_posix()},"" format: chatml, val_split: 0.0}\n"@@ -194,7 +203,7 @@ class TestResumeRefusalForUnsupportedTasks:train_data.write_text(json.dumps({"prompt": "forget me", "response": "done"}) + "\n")config_path.write_text(- f"base: {TINY_MODEL}\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\n""task: unlearn\n"f"data: {{train: {train_data.as_posix()}, forget_set: {train_data.as_posix()},"" format: chatml, val_split: 0.0}\n"@@ -242,7 +251,7 @@ class TestPRMResume:out_dir = tmp_path / "out_prm"cfg_path = tmp_path / "prm.yaml"cfg_path.write_text(- f"base: {TINY_MODEL}\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\n""task: prm\n"f"data: {{train: {prm_data.as_posix()}, format: prm, val_split: 0.0, max_length: 64}}\n""training: {\n"@@ -330,7 +339,7 @@ class TestMoleRoutingResume:monkeypatch.setattr(mole_routing, "_save_mole_gate", recording_save_gate)# Create two tiny task LoRA adapters- base_model = AutoModelForCausalLM.from_pretrained(TINY_MODEL)+ base_model = AutoModelForCausalLM.from_pretrained(_local_base_model_dir())lora_cfg = LoraConfig(r=4, lora_alpha=8, target_modules=["q_proj", "v_proj"])peft_m = get_peft_model(base_model, lora_cfg)adapter_a = tmp_path / "adapter_a"@@ -355,7 +364,7 @@ class TestMoleRoutingResume:cfg_path = tmp_path / "mole.yaml"c_posix = chat_data.as_posix()cfg_data = (- f"base: {TINY_MODEL}\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\n""task: moe_lora_routing\n"f"data: {{train: {c_posix}, format: chatml, val_split: 0.0, max_length: 64}}\n""training: {\n"diff --git a/tests/test_issue1225_online_dpo_unranked_pairs.py b/tests/test_issue1225_online_dpo_unranked_pairs.pyindex bbe5d90c..c7195eab 100644--- a/tests/test_issue1225_online_dpo_unranked_pairs.py+++ b/tests/test_issue1225_online_dpo_unranked_pairs.py@@ -8,17 +8,19 @@ drop a ``-1``: it builds ``mask = rank == 0``, so every such pair trained asthe judge server down, a whole run learned arbitrary labels and finishednormally.-These tests run the REAL wrapper and the REAL trl trainer on-``hf-internal-testing/tiny-random-gpt2`` on CPU. The generated tokens are-captured once and replayed, so two steps that differ only in the judge's ranks-see identical completions, and the LoRA ``B`` matrices are moved off zero so-the policy differs from the reference and every pair has its own loss.+These tests run the REAL wrapper and the REAL trl trainer on a tiny,+randomly-initialised GPT-2 built locally (``tests/_tiny_hf_models.py``, #1356+-- no download) on CPU. The generated tokens are captured once and replayed,+so two steps that differ only in the judge's ranks see identical+completions, and the LoRA ``B`` matrices are moved off zero so the policy+differs from the reference and every pair has its own loss."""from __future__ import annotationsimport loggingimport math+import pathlibimport reimport pytest@@ -133,10 +135,12 @@ def _build(path, monkeypatch, evaluator, *, batch_size=4, n_prompts=4, extra="")"""The real wrapper, set up on the tiny model, writing under ``path / "out"``."""import soup_cli.trainer.online_dpo as odfrom soup_cli.config.loader import load_config_from_string+ from tests._tiny_hf_models import tiny_model_dirmonkeypatch.setattr(od, "_ONLINE_DPO_JUDGE_OVERRIDE", evaluator)+ base_dir = pathlib.Path(tiny_model_dir("gpt2")).as_posix()cfg = load_config_from_string(- "base: hf-internal-testing/tiny-random-gpt2\n"+ f"base: {base_dir}\n""task: online_dpo\n""data:\n train: x.jsonl\n max_length: 64\n""training:\n"diff --git a/tests/test_issue491_frozen_base_load_dtype.py b/tests/test_issue491_frozen_base_load_dtype.pyindex 146d3845..8ac5a804 100644--- a/tests/test_issue491_frozen_base_load_dtype.py+++ b/tests/test_issue491_frozen_base_load_dtype.py@@ -24,6 +24,17 @@ import pytestfrom soup_cli.config.schema import SoupConfig+def _local_base_model_dir() -> str:+ """A tiny GPT-2 + tokenizer built locally (no download), standing in for+ hf-internal-testing/tiny-random-gpt2 -- #1356 found this real-model test+ pulling it from the Hub for nothing it checks depends on real pretrained+ weights. Shared and cached across every file that needs one+ (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("gpt2")++class _FakeCuda:"""Stands in for ``torch.cuda`` (mirrors tests/test_issue385_stream_dtype.py'sfixture of the same shape)."""@@ -193,7 +204,7 @@ class TestRewardModelHeadUpcastToFp32:from soup_cli.trainer.reward_model import RewardModelTrainerWrappercfg = SoupConfig(- base="hf-internal-testing/tiny-random-gpt2",+ base=_local_base_model_dir(),task="reward_model",data={"train": "./data.jsonl"},training={"quantization": "none"},diff --git a/tests/test_rewind_hf.py b/tests/test_rewind_hf.pyindex 5f31638b..fcbe9a3c 100644--- a/tests/test_rewind_hf.py+++ b/tests/test_rewind_hf.py@@ -1,8 +1,9 @@"""HF/TRL flight-recorder tests: row identity, per-row loss, and the eval guard.-Every test runs a real (tiny-random, CPU) TRL ``SFTTrainer`` -- the whole point of-the module is that it hooks HF internals correctly, and a mocked trainer would-assert nothing about ``_get_train_sampler`` / ``compute_loss`` call order.+Every test runs a real (tiny, randomly-initialised, CPU) TRL ``SFTTrainer`` --+the whole point of the module is that it hooks HF internals correctly, and a+mocked trainer would assert nothing about ``_get_train_sampler`` /+``compute_loss`` call order."""from __future__ import annotations@@ -13,8 +14,6 @@ pytest.importorskip("trl")from soup_cli.trainer import rewind_hf # noqa: E402-MODEL_ID = "hf-internal-testing/tiny-random-LlamaForCausalLM"-class FakeSink:"""List-collecting stand-in for ``monitoring.rewind_log.RewindLog``."""@@ -53,12 +52,14 @@ def _uniform_dataset(n: int = 8):def _model_and_tokenizer():- from transformers import AutoModelForCausalLM, AutoTokenizer-- tok = AutoTokenizer.from_pretrained(MODEL_ID)- if tok.pad_token is None:- tok.pad_token = tok.eos_token- model = AutoModelForCausalLM.from_pretrained(MODEL_ID)+ """A real, randomly-initialised tiny Llama + a locally-trained tokenizer+ (no download) -- #1356 found this pulling both from the Hub every run for+ nothing these tests check depends on real weights or vocabulary. Shared+ builders live in tests/_tiny_hf_models.py."""+ from tests._tiny_hf_models import build_llama, build_tokenizer++ tok = build_tokenizer()+ model = build_llama(tok)return model, tokdiff --git a/tests/test_v05311.py b/tests/test_v05311.pyindex 47f7e31a..65a9cfff 100644--- a/tests/test_v05311.py+++ b/tests/test_v05311.py@@ -758,23 +758,30 @@ class TestGRPOVariantRuntimeContract:def test_real_trl_grpotrainer_end_to_end_step(self, tmp_path, aten_half_matmuls):"""End-to-end single step with real trl.GRPOTrainer and tiny model."""from datasets import Dataset- from transformers import AutoTokenizer, GPT2Config, GPT2LMHeadModel+ from transformers import GPT2Config, GPT2LMHeadModelfrom trl import GRPOConfig, GRPOTrainerfrom soup_cli.trainer.grpo import make_grpo_trainer_variant-+ from tests._tiny_hf_models import build_tokenizer++ # #1356: a tokenizer built locally (no download) stands in for the+ # real "gpt2" tokenizer -- vocab_size matches it rather than a+ # hardcoded 50257, since nothing here depends on real BPE merges.+ # Dropout 0 and a 1-layer/1-head shape are specific to this test+ # (deterministic, minimal), so the model stays file-local.+ tokenizer = build_tokenizer(+ ("Hello", "World", "hello world"), eos="<|endoftext|>"+ )config = GPT2Config(n_layer=1,n_head=1,n_embd=32,- vocab_size=50257,+ vocab_size=len(tokenizer),attn_pdrop=0.0,resid_pdrop=0.0,embd_pdrop=0.0,)model = GPT2LMHeadModel(config)- tokenizer = AutoTokenizer.from_pretrained("gpt2")- tokenizer.pad_token = tokenizer.eos_tokendataset = Dataset.from_dict({"prompt": ["Hello", "World"]})training_args = GRPOConfig(diff --git a/tests/test_v07129.py b/tests/test_v07129.pyindex d0d72508..9d75a3bb 100644--- a/tests/test_v07129.py+++ b/tests/test_v07129.py@@ -145,6 +145,18 @@ def _tiny_llama(layers: int = 6, vocab_size: int = 128):return LlamaForCausalLM(cfg)+def _tiny_tokenizer():+ """A byte-level BPE tokenizer trained locally (no download), standing in+ for the SmolLM2 tokenizer that #1356 found these tests pulling from the+ Hub just for len(tok) and a save/reload round-trip -- not its English+ vocabulary. ``_tiny_llama`` here takes a variable ``layers`` per test+ (shrink prunes a specific layer count), so only the tokenizer is shared+ (tests/_tiny_hf_models.py); the model stays file-local."""+ from tests._tiny_hf_models import build_tokenizer++ return build_tokenizer()++class TestPrune:def test_arch_detected(self):from soup_cli.utils.shrink import shrink_arch_of@@ -440,9 +452,7 @@ class TestImportance:# ---------------------------------------------------------------------------def _write_tiny_model(dir_path, layers: int = 6):"""Save a tiny CPU Llama + tokenizer to ``dir_path`` for CLI smoke."""- from transformers import AutoTokenizer-- tok = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")+ tok = _tiny_tokenizer()m = _tiny_llama(layers, vocab_size=len(tok))m.save_pretrained(str(dir_path))tok.save_pretrained(str(dir_path))@@ -563,13 +573,13 @@ class TestShrinkCli:def test_reject_unsupported_arch(self, tmp_path, monkeypatch):"""A GPT-NeoX-family tiny model is a friendly reject (arch allowlist)."""- from transformers import AutoTokenizer, GPTNeoXConfig, GPTNeoXForCausalLM+ from transformers import GPTNeoXConfig, GPTNeoXForCausalLMfrom typer.testing import CliRunnerfrom soup_cli.cli import appmonkeypatch.chdir(tmp_path)- tok = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")+ tok = _tiny_tokenizer()cfg = GPTNeoXConfig(hidden_size=32, intermediate_size=64, num_hidden_layers=6,num_attention_heads=4, vocab_size=len(tok), max_position_embeddings=512,@@ -804,13 +814,13 @@ class TestReviewFixes:"""_fuse_adapter merges a LoRA adapter back into the base (atomic swap),so the shipped dir is a single dense model (no adapter_config.json)."""from peft import LoraConfig, TaskType, get_peft_model- from transformers import AutoModelForCausalLM, AutoTokenizer+ from transformers import AutoModelForCausalLMfrom soup_cli.commands.shrink import _fuse_adaptermonkeypatch.chdir(tmp_path) # base_dir must stay under cwd (containment)base_dir = tmp_path / "base"- tok = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct")+ tok = _tiny_tokenizer()_tiny_llama(4, vocab_size=len(tok)).save_pretrained(str(base_dir))tok.save_pretrained(str(base_dir))diff --git a/tests/test_v07131.py b/tests/test_v07131.pyindex bb2dfe1d..102f4d9b 100644--- a/tests/test_v07131.py+++ b/tests/test_v07131.py@@ -19,6 +19,19 @@ def _plain(text: str) -> str:"""Return ANSI-stripped, whitespace-collapsed CLI output."""return " ".join(_ANSI_RE.sub("", text).split())++def _local_base_model_dir() -> str:+ """A tiny GPT-2 + tokenizer built locally (no download), standing in for+ hf-internal-testing/tiny-random-gpt2 -- #1356 found the one test here+ that actually calls wrapper.setup() (building a real trainer) pulling it+ from the Hub for nothing that test checks depends on real pretrained+ weights. Shared and cached across every file that needs one+ (tests/_tiny_hf_models.py)."""+ from tests._tiny_hf_models import tiny_model_dir++ return tiny_model_dir("gpt2")++# ---------------------------------------------------------------------------# Shared test doubles# ---------------------------------------------------------------------------@@ -598,12 +611,14 @@ class TestOnlineDpoWrapper:# Parametrized over trl version by the wrapper itself: the seam evaluator# is adapted to judge= (trl 0.19.x) or reward_funcs= (trl 1.x). Builds a# real trainer on either.+ from pathlib import Path+import soup_cli.trainer.online_dpo as odfrom soup_cli.config.loader import load_config_from_stringfrom soup_cli.trainer.online_dpo import OnlineDPOTrainerWrappercfg = load_config_from_string(- "base: hf-internal-testing/tiny-random-gpt2\ntask: online_dpo\n"+ f"base: {Path(_local_base_model_dir()).as_posix()}\ntask: online_dpo\n""data:\n train: x.jsonl\n max_length: 64\n""training:\n online_dpo_judge: \"ollama://m\"\n"" epochs: 1\n batch_size: 2\n online_dpo_max_new_tokens: 8\n"