From 403a15c163b16836da7ca2ca07308159b626c2f6 Mon Sep 17 00:00:00 2001 From: Xiaoyu Zhang <1182563586@qq.com> Date: Wed, 2 Sep 2026 10:35:14 +0800 Subject: [PATCH] [CI] Batch CPU test workers (#37252) --- .github/workflows/_pr-test-stage-cpu.yml | 2 +- python/sglang/test/ci/fork_test_worker.py | 4 ++++ test/registered/unit/test_fork_test_worker.py | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/_pr-test-stage-cpu.yml b/.github/workflows/_pr-test-stage-cpu.yml index 651a0aa8d..10389ddac 100644 --- a/.github/workflows/_pr-test-stage-cpu.yml +++ b/.github/workflows/_pr-test-stage-cpu.yml @@ -158,7 +158,7 @@ jobs: SGLANG_SKIP_RUST_TESTS: ${{ fromJson(inputs.check_changes).rust_workspace == 'true' && 'false' || 'true' }} run: | cd test/ - python3 run_suite.py --hw cpu --suite ${{ inputs.self_name }} --auto-partition-id ${{ matrix.partition }} --auto-partition-size ${{ fromJson(inputs.partitions)[inputs.self_name].size }} --partition-model-file /tmp/partition-model.json $CONTINUE_ON_ERROR_FLAG + python3 run_suite.py --hw cpu --suite ${{ inputs.self_name }} --auto-partition-id ${{ matrix.partition }} --auto-partition-size ${{ fromJson(inputs.partitions)[inputs.self_name].size }} --partition-model-file /tmp/partition-model.json --fork-worker-batch-size 20 $CONTINUE_ON_ERROR_FLAG # PRs save only what the base lacks; the implicit if: success() keeps a # half-downloaded cache unpublished. diff --git a/python/sglang/test/ci/fork_test_worker.py b/python/sglang/test/ci/fork_test_worker.py index cccb52e79..b11486024 100644 --- a/python/sglang/test/ci/fork_test_worker.py +++ b/python/sglang/test/ci/fork_test_worker.py @@ -33,6 +33,10 @@ def _normalize_exit_code(code) -> int: def _run_file(filename: str) -> int: sys.argv = [filename, "-f"] + # Match ``python /path/to/test.py``: tests may import helper modules that + # live next to the executed file. runpy.run_path() does not update + # sys.path[0] for us, and this child exits after the file finishes. + sys.path[0] = os.path.dirname(os.path.abspath(filename)) try: runpy.run_path(filename, run_name="__main__") return 0 diff --git a/test/registered/unit/test_fork_test_worker.py b/test/registered/unit/test_fork_test_worker.py index 13ff61f6b..653aa6cd2 100644 --- a/test/registered/unit/test_fork_test_worker.py +++ b/test/registered/unit/test_fork_test_worker.py @@ -54,14 +54,28 @@ class TestForkTestWorker(CustomTestCase): assert "SGLANG_FORK_WORKER_TEST" not in os.environ raise SystemExit(3) """)) + helper = Path(tmpdir) / "sibling_helper.py" + helper.write_text("VALUE = 42\n") + sibling_import = Path(tmpdir) / "sibling_import.py" + sibling_import.write_text(textwrap.dedent(""" + import os + import sys + + from sibling_helper import VALUE + + assert sys.path[0] == os.path.dirname(__file__) + assert VALUE == 42 + """)) results = [] - for filename in (first, second): + for filename in (first, second, sibling_import): process.stdin.write(json.dumps({"filename": str(filename)}) + "\n") process.stdin.flush() results.append(json.loads(result_stream.readline())) - self.assertEqual([result["returncode"] for result in results], [0, 3]) + self.assertEqual( + [result["returncode"] for result in results], [0, 3, 0] + ) self.assertTrue(all(result["elapsed"] >= 0 for result in results)) process.stdin.write(json.dumps({"command": "stop"}) + "\n")