Skip to content

Commit

Permalink
[CI] Fix CI (sgl-project#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
wisclmy0611 authored Aug 26, 2024
1 parent 158e8f1 commit 7514b9f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
35 changes: 17 additions & 18 deletions python/sglang/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import argparse
import asyncio
import multiprocessing
import os
import subprocess
import threading
import time
import unittest
from functools import partial
from typing import Callable, List, Optional

Expand All @@ -19,6 +17,7 @@
from sglang.global_config import global_config
from sglang.lang.backend.openai import OpenAI
from sglang.lang.backend.runtime_endpoint import RuntimeEndpoint
from sglang.srt.utils import kill_child_process
from sglang.utils import get_exception_traceback

DEFAULT_MODEL_NAME_FOR_TEST = "meta-llama/Meta-Llama-3.1-8B-Instruct"
Expand Down Expand Up @@ -457,35 +456,35 @@ def _target_func():
return ret_value[0]


def run_one_file(filename, out_queue):
print(f"\n\nRun {filename}\n\n")
ret = unittest.main(module=None, argv=["", "-vb"] + [filename])


def run_unittest_files(files: List[str], timeout_per_file: float):
tic = time.time()
success = True

for filename in files:
out_queue = multiprocessing.Queue()
p = multiprocessing.Process(target=run_one_file, args=(filename, out_queue))
global process

def run_process():
p.start()
p.join()
def run_one_file(filename):
filename = os.path.join(os.getcwd(), filename)
print(f"\n\nRun {filename}\n\n")
process = subprocess.Popen(
["python3", filename], stdout=None, stderr=None, env=os.environ
)
process.wait()
return process.returncode

try:
run_with_timeout(run_process, timeout=timeout_per_file)
if p.exitcode != 0:
success = False
break
ret_code = run_with_timeout(
run_one_file, args=(filename,), timeout=timeout_per_file
)
assert ret_code == 0
except TimeoutError:
p.terminate()
kill_child_process(process.pid)
time.sleep(5)
print(
f"\nTimeout after {timeout_per_file} seconds when running {filename}\n"
)
return False
success = False
break

if success:
print(f"Success. Time elapsed: {time.time() - tic:.2f}s")
Expand Down
2 changes: 1 addition & 1 deletion test/srt/models/test_embedding_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def test_prefill_logits(self):
except RuntimeError:
pass

unittest.main(warnings="ignore")
unittest.main()
2 changes: 1 addition & 1 deletion test/srt/models/test_generation_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ def test_prefill_logits_and_output_strs(self):
except RuntimeError:
pass

unittest.main(warnings="ignore")
unittest.main()
8 changes: 2 additions & 6 deletions test/srt/run_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
suites = {
"minimal": [
"models/test_embedding_models.py",
# "models/test_generation_models.py",
"models/test_generation_models.py",
"sampling/penaltylib",
"test_chunked_prefill.py",
"test_embedding_openai_server.py",
Expand All @@ -33,6 +33,7 @@
tests.remove(target_suite_name)
tests.extend(target_tests)


if __name__ == "__main__":
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
Expand All @@ -55,10 +56,5 @@
else:
files = suites[args.suite]

try:
mp.set_start_method("spawn")
except RuntimeError:
pass

exit_code = run_unittest_files(files, args.timeout_per_file)
exit(exit_code)
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ def test_repetition_penalty(self):


if __name__ == "__main__":
unittest.main(warnings="ignore")
unittest.main()

0 comments on commit 7514b9f

Please sign in to comment.