|
| 1 | +"""Check InferenceX generator subprocesses against selected checkout layouts.""" |
| 2 | + |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import sys |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +import pytest |
| 9 | +import yaml |
| 10 | + |
| 11 | +sys.path.insert(0, str(Path(__file__).resolve().parents[2])) |
| 12 | +from operatorx.scripts.inferencex_testlist.matrix import _run_inferencex_generator |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize("legacy", [False, True]) |
| 16 | +def test_generator_uses_requested_checkout_with_safe_path(tmp_path, monkeypatch, legacy): |
| 17 | + root = tmp_path / "selected checkout" |
| 18 | + root.mkdir() |
| 19 | + foreign = tmp_path / "other checkout" |
| 20 | + (foreign / "infx").mkdir(parents=True) |
| 21 | + (foreign / "infx/__init__.py").write_text("raise RuntimeError('wrong checkout')\n") |
| 22 | + monkeypatch.setenv("PYTHONPATH", str(foreign)) |
| 23 | + monkeypatch.setenv("PYTHONSAFEPATH", "1") |
| 24 | + monkeypatch.chdir(tmp_path) |
| 25 | + |
| 26 | + if legacy: |
| 27 | + # The old generator is an external executable. Its sibling dependency |
| 28 | + # distinguishes the selected revision from inherited import paths. |
| 29 | + script = root / "utils/matrix_logic/generate_sweep_configs.py" |
| 30 | + script.parent.mkdir(parents=True) |
| 31 | + script.write_text( |
| 32 | + "import json, sys\nfrom validation import model\n" |
| 33 | + "assert sys.argv[1:] == ['full-sweep', '--config-files', 'master.yaml', '--no-evals']\n" |
| 34 | + "print(json.dumps([{'model': model, 'conc': 2}]))\n" |
| 35 | + ) |
| 36 | + script.with_name("validation.py").write_text("model = 'legacy revision'\n") |
| 37 | + expected = "legacy revision" |
| 38 | + else: |
| 39 | + source = Path(__file__).resolve().parents[3] |
| 40 | + shutil.copytree(source / "infx", root / "infx", |
| 41 | + ignore=shutil.ignore_patterns("__pycache__", "tests")) |
| 42 | + (root / "configs").mkdir() |
| 43 | + (root / "configs/runners.yaml").write_text("labels: {fixture: [node-a]}\nhardware: {}\n") |
| 44 | + (root / "master.yaml").write_text(yaml.safe_dump({"fixture": { |
| 45 | + "image": "example/image:stable", "model": "selected revision", |
| 46 | + "model-prefix": "dsr1", "precision": "fp8", "framework": "sglang", |
| 47 | + "runner": "fixture", "multinode": False, |
| 48 | + "scenarios": {"fixed-seq-len": [{ |
| 49 | + "isl": 1024, "osl": 1024, |
| 50 | + "search-space": [{"tp": 1, "conc-list": [2]}], |
| 51 | + }]}, |
| 52 | + }})) |
| 53 | + expected = "selected revision" |
| 54 | + |
| 55 | + rows = _run_inferencex_generator(os.path.relpath(root), ["master.yaml"], ["--no-evals"]) |
| 56 | + assert [(row["model"], row["conc"]) for row in rows] == [(expected, 2)] |
0 commit comments