Fix unit tests (#11503)
This commit is contained in:
@@ -10,7 +10,7 @@ cd sglang/test/srt
|
||||
python3 test_srt_endpoint.py
|
||||
|
||||
# Run a single test
|
||||
python3 -m unittest test_srt_endpoint.TestSRTEndpoint.test_simple_decode
|
||||
python3 test_srt_endpoint.py TestSRTEndpoint.test_simple_decode
|
||||
|
||||
# Run a suite with multiple files
|
||||
python3 run_suite.py --suite per-commit
|
||||
@@ -21,21 +21,23 @@ python3 run_suite.py --suite per-commit
|
||||
cd sglang/test/lang
|
||||
|
||||
# Run a single file
|
||||
python3 test_srt_backend.py
|
||||
python3 test_choices.py
|
||||
```
|
||||
|
||||
## Adding or Updating Tests in CI
|
||||
|
||||
- Create new test files under `test/srt` or `test/lang` depending on the type of test.
|
||||
- Ensure they are referenced in the respective `run_suite.py` (e.g., `test/srt/run_suite.py`) so they’re picked up in CI. For most small test cases, they can be added to the `per-commit` suite. Sort the test cases alphabetically.
|
||||
- The CI will run the `per-commit` and `nightly` automatically. If you need special setup or custom test groups, you may modify the workflows in [`.github/workflows/`](https://github.com/sgl-project/sglang/tree/main/.github/workflows).
|
||||
|
||||
- Ensure they are referenced in the respective `run_suite.py` (e.g., `test/srt/run_suite.py`) so they are picked up in CI. For most small test cases, they can be added to the `per-commit-1-gpu` suite. Sort the test cases alphabetically by name.
|
||||
- Ensure you added `unittest.main()` for unittest and `pytest.main([__file__])` for pytest in the scripts. The CI run them via `python3 test_file.py`.
|
||||
- The CI will run some suites such as `per-commit-1-gpu`, `per-commit-2-gpu`, and `nightly-1-gpu` automatically. If you need special setup or custom test groups, you may modify the workflows in [`.github/workflows/`](https://github.com/sgl-project/sglang/tree/main/.github/workflows).
|
||||
|
||||
## Writing Elegant Test Cases
|
||||
|
||||
- Examine existing tests in [sglang/test](https://github.com/sgl-project/sglang/tree/main/test) for practical examples.
|
||||
- Learn from existing examples in [sglang/test/srt](https://github.com/sgl-project/sglang/tree/main/test/srt).
|
||||
- Reduce the test time by using smaller models and reusing the server for multiple test cases. Launching a server takes a lot of time.
|
||||
- Use as few GPUs as possible. Do not run long tests with 8-gpu runners.
|
||||
- If the test cases take too long, considering adding them to nightly tests instead of per-commit tests.
|
||||
- Keep each test function focused on a single scenario or piece of functionality.
|
||||
- Give tests descriptive names reflecting their purpose.
|
||||
- Use robust assertions (e.g., assert, unittest methods) to validate outcomes.
|
||||
- Clean up resources to avoid side effects and preserve test independence.
|
||||
- Reduce the test time by using smaller models and reusing the server for multiple test cases.
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestFile:
|
||||
|
||||
# NOTE: please sort the test cases alphabetically by the test file name
|
||||
suites = {
|
||||
"per-commit": [
|
||||
"per-commit-1-gpu": [
|
||||
TestFile("function_call/test_json_schema_constraint.py", 30),
|
||||
TestFile("hicache/test_hicache.py", 116),
|
||||
TestFile("hicache/test_hicache_eagle.py", 150),
|
||||
@@ -179,6 +179,9 @@ suites = {
|
||||
TestFile("test_vllm_dependency.py", 185),
|
||||
# TestFile("test_gguf.py", 96),
|
||||
],
|
||||
# If the test cases take too long, considering adding them to nightly tests instead of per-commit tests
|
||||
"nightly-1-gpu": [],
|
||||
"nightly-8-gpu": [],
|
||||
}
|
||||
|
||||
# Add AMD tests
|
||||
|
||||
@@ -72,7 +72,8 @@ class TestDeepseekV3MTPChannelInt8(CustomTestCase):
|
||||
"16",
|
||||
"--enable-torch-compile",
|
||||
"--torch-compile-max-bs",
|
||||
"2" "--speculative-algorithm",
|
||||
"2",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
"--speculative-draft-model-path",
|
||||
"sgl-project/sglang-ci-dsv3-channel-int8-test-NextN",
|
||||
@@ -177,7 +178,8 @@ class TestDeepseekV3MTPBlockInt8(CustomTestCase):
|
||||
"16",
|
||||
"--enable-torch-compile",
|
||||
"--torch-compile-max-bs",
|
||||
"2" "--speculative-algorithm",
|
||||
"2",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
"--speculative-num-steps",
|
||||
"2",
|
||||
|
||||
Reference in New Issue
Block a user